Way to "move" files to show up elsewhere in workspace?

1,752 views
Skip to first unread message

Kamal Marhubi

unread,
Dec 4, 2015, 4:24:36 PM12/4/15
to bazel-discuss
I've got a new_git_repository rule that brings in some files. I would like to refer to the files via a build rule under third_party for later inclusion in a docker_build. I tried a "proxy" filegroup at third_party, but the files end up under /external in the docker image. Is there a way to move files to refer to them as if they existed elsewhere?

-Kamal

svilen...@gmail.com

unread,
Dec 4, 2015, 4:32:41 PM12/4/15
to Kamal Marhubi, bazel-discuss
Not sure if that's the exact same use case, but I had to deal with something similar. My ugly solution was to just copy the files I needed inside a genrule with output_to_bindir=1 (https://github.com/s-kanev/XIOSim/blob/master/third_party/pin/BUILD.external#L59). Hope that helps.

On Fri, Dec 4, 2015 at 1:24 PM Kamal Marhubi <ka...@marhubi.com> wrote:
I've got a new_git_repository rule that brings in some files. I would like to refer to the files via a build rule under third_party for later inclusion in a docker_build. I tried a "proxy" filegroup at third_party, but the files end up under /external in the docker image. Is there a way to move files to refer to them as if they existed elsewhere?

-Kamal

--
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-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/CAK-ZPekoALLbN3hCPbkz6A_AcG-R-xDdO_9_nM7RHKmRvNgiNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Kamal Marhubi

unread,
Dec 4, 2015, 4:52:33 PM12/4/15
to svilen...@gmail.com, bazel-discuss
Oh nifty. That could work though I don't know how to specify an entry in outs for each entry in srcs. Maybe it works for a single file, but not for a tree?

I realised for my use case I can use a pkg_tar since I'm just adding stuff to the docker_build. I'd still be interested in knowing if there's a way to do this though!

-Kamal

Damien Martin-guillerez

unread,
Dec 4, 2015, 4:55:21 PM12/4/15
to Kamal Marhubi, svilen...@gmail.com, bazel-discuss
Use pkg_tar with strip_prefix seems like the good way to go for your use case.

Brian Silverman

unread,
Dec 4, 2015, 5:37:53 PM12/4/15
to Damien Martin-guillerez, Kamal Marhubi, svilen...@gmail.com, bazel-discuss
As far as a way to use a genrule to copy a bunch of files, glob + a list comprehension should work. Something along the lines of:
files = glob(['the_directory/**'])
genrule(
  name = 'copy_the_files',
  srcs = files,
  outs = [f.replace('the_directory', 'another_place/folder') for f in files],
  cmd = '\n'.join(['mkdir -p $$(dirname $(location %s)) && cp $(location %s) $(location :%s)' % (f, f, f.replace('the_directory', 'another_place/folder')) for f in files]),
)

Depending on exactly what you're doing, writing that (or at least the part that does the actual renaming) as a skylark macro and/or putting the output names in a separate list and using zip when generating the cmd to avoid duplicating that logic might make sense.

Reply all
Reply to author
Forward
0 new messages