Turn string into file to include in inputs of ctx.action

175 views
Skip to first unread message

jenn...@xperiel.com

unread,
Dec 7, 2015, 4:52:12 PM12/7/15
to bazel-discuss
Hi,

I am trying to find out how to turn a parameter that I receive as a string (i.e. includes = [] in cc_library) into a file so I can pass it into the inputs = [] of ctx.action so my sandbox will include the files.

I haven't been able to find any documentation on if this is possible; is there way to do this?

Thanks,
Jennifer

Brian Silverman

unread,
Dec 7, 2015, 4:54:58 PM12/7/15
to jenn...@xperiel.com, bazel-discuss
Make it an attr.label_list(allow_files = True). ctx.files.inputs will then give you all the files.


--
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/a72f24f1-7c7b-4c4e-8e2e-c578c8a6e10c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jennifer Vannier

unread,
Dec 7, 2015, 5:13:43 PM12/7/15
to Brian Silverman, bazel-discuss
Hi Brian,

That doesn't work for my particular problem because my includes=[] has up-level references (i.e. '..') which I cannot remove for my project. Do you know of a way around this problem?

Thanks again,
Jennifer

Brian Silverman

unread,
Dec 7, 2015, 7:57:17 PM12/7/15
to Jennifer Vannier, bazel-discuss
Bazel doesn't allow packages to refer directly to source files in other packages. You'll have to define a filegroup or something in the higher-level package and pass that in through a label/label_list. Is there some reason the rule is in the sub-package instead of the parent one? In general, moving the rule(s) up works better.

Also, another tip: if you're doing something like includes which takes all files in a directory as inputs, you'll want to use glob to get an actual list of files. Wrapping the rule in a macro often helps clean up the API for that kind of thing.

Jennifer Vannier

unread,
Dec 30, 2015, 10:47:37 PM12/30/15
to Brian Silverman, bazel-discuss
Thank you for your help! I ended up re-working it so that the includes could still be a list of strings but including the files in a different section.

Thank you for your time,
Jennifer
Reply all
Reply to author
Forward
0 new messages