"path" attribute of filegroup

2,242 views
Skip to first unread message

Shimin Guo

unread,
Feb 4, 2016, 2:18:21 PM2/4/16
to bazel-discuss
I'm having a hard time understanding the "path" attribute of the filegroup rule.

Say I have

filegroup(
    name = "mygroup",
    srcs = [
        "//data:a_file.txt",
        "//data:some/subdirectory/another_file.txt",
    ],
    path = "mydata",
)

cc_binary(
    name = "prog",
    srcs = [ ... ],
    data = [":mygroup"],
)

What does the path attribute do here? It seems the runfiles directory generated for prog is the same where I specify the path or not.

Greg Estren

unread,
Feb 4, 2016, 4:58:55 PM2/4/16
to Shimin Guo, bazel-discuss
The "path" attribute is exposed through a FilegroupPathProvider, which isn't getting any practical use right now in Bazel (cc_binary doesn't exploit it).

Is there anything specific you need from this attribute or are you just curious?

--
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/9259d000-13f2-4f1e-9a22-ad2a4c025c6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shimin Guo

unread,
Feb 4, 2016, 6:17:35 PM2/4/16
to Greg Estren, bazel-discuss
I was trying to pull files from other packages have them appear in a particular directory layout. I guess that's not what the path attribute is for?

Brian Silverman

unread,
Feb 4, 2016, 6:22:07 PM2/4/16
to Shimin Guo, Greg Estren, bazel-discuss
No, it isn't. The way to do pull files in is using a genrule or a custom Skylark rule to copy them.

Something along the lines of this should work for the genrule approach:

files = ["//data:a_file.txt", "//data:some/subdirectory/another_file.txt"]
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.

Shimin Guo

unread,
Feb 4, 2016, 6:23:38 PM2/4/16
to Brian Silverman, Greg Estren, bazel-discuss
Got it. Thanks for the help.
Reply all
Reply to author
Forward
0 new messages