Untar files using bazel

3,024 views
Skip to first unread message

Zain Asgar

unread,
Apr 25, 2017, 8:25:07 PM4/25/17
to bazel-discuss
I am trying to create a rule (maybe one already exists?), to un-tar a file during a bazel build step. 

If I understand correctly all output files need to be known during the "Analysis Phase". To work around this I have a file lets call it manifest.txt which lists all the files in the tar file. However, I don't quite understand how I can read this file as a list outputs for my skylark rule? Is there an easy way to read a file and have each line be a generated output?

Thanks, 

- Zain

Brian Silverman

unread,
Apr 25, 2017, 10:14:53 PM4/25/17
to Zain Asgar, bazel-discuss
Zain,

If you reformat the manifest as something you can load, it's easy to work with it. That can't be quite one per line, but it can be close. I would do something like this (might not handle paths within the tar file too well without some more work):

manifest_foo.bzl:
contents = [
  'file1',
  'file2',
]

BUILD:
load(':manifest_foo.bzl', foo_contents = 'contents')

genrule(
  name = 'extract_foo',
  srcs = ['foo.tar'],
  outs = foo_contents,
  cmd = 'tar -C $(@D) -xf $(location foo.tar)',
)

If you're going to use this a lot, definitely write a macro around it.

Feel free to ask if you have any questions about that,
Brian

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/c043088e-53e2-4a2e-8e70-1c465e3ea5b3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages