Modifying a rule to accept a actions.declare_directory File

838 views
Skip to first unread message

Andrew Allen

unread,
Apr 26, 2018, 1:38:05 AM4/26/18
to bazel-discuss
Does anyone have any examples of using actions.declare_directory to create a File object that is then parsed by a rule? I've been playing with this all night, but I can't really find any examples.

It looks to me like the file it creates is a zip. Do I need to detect that case, unzip the file and then handle the files in there? The code generator I've been playing with is swagger-codegen and it makes a few additional files that aren't necessarily going to work as sources in a foo_library rule (.gitignore, README.md file, etc.). Is there a way to prune the list of files that should be passed down?

Thanks in advance!

/** ~Andrew Z Allen */

Marcel Hlopko

unread,
Apr 26, 2018, 1:49:41 AM4/26/18
to m...@andrewzallen.com, bazel-discuss

--
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/CAAVj6hx7L-mbnE2qfmOuWnUrmAJxO5UJ5a8DKJqd0tgzALsmqA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Andrew Allen

unread,
Apr 28, 2018, 12:54:10 AM4/28/18
to Marcel Hlopko, bazel-discuss
I just posted a pull request that exhibits my problem to the examples
directory. Hopefully we can work through this and improve the
documentation at the same time :-).

This example creates a new "sum" rule in the "directory_outputs"
directory that takes a file containing a single line, a number, and adds
it to the deps inputs. Additionally there is a rule "generate_sums" that
declares a directory of files that meet this criteria. My expectation
was that it would be possible to iterate over an attribute on the File
object returned from declare_directory, but there doesn't appear to be
any way to enumerate the files that were created and pass those
individually as files into my run_shell action.

Unfortunately this doesn't seem to be the case.

https://github.com/bazelbuild/examples/pull/58

Thanks so much for taking a look at things



/** ~Andrew Z Allen */

On Wed, Apr 25, 2018 at 11:49 PM, Marcel Hlopko <hlo...@google.com> wrote:
On Thu, Apr 26, 2018 at 7:38 AM Andrew Allen <m...@andrewzallen.com> wrote:
Does anyone have any examples of using actions.declare_directory to create a File object that is then parsed by a rule? I've been playing with this all night, but I can't really find any examples.

It looks to me like the file it creates is a zip. Do I need to detect that case, unzip the file and then handle the files in there? The code generator I've been playing with is swagger-codegen and it makes a few additional files that aren't necessarily going to work as sources in a foo_library rule (.gitignore, README.md file, etc.). Is there a way to prune the list of files that should be passed down?

Thanks in advance!

/** ~Andrew Z Allen */

--
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.

Marcel Hlopko

unread,
May 11, 2018, 5:11:46 AM5/11/18
to Andrew Allen, Jon Brandvein, bazel-discuss
Hi Andrew,
so you have a rule that creates a directory artifact, and you want to write a rule that consumes it and creates 1 action per file in the directory artifact, correct? The high level limitation is that directory artifacts are created in the execution phase, but rules are evaluated in the analysis phase. In general, analysis phase has no access to actual filesystem, it only describes a world of targets and actions. We solve the problem of creating 1 action per file in directory artifact using "action templates" in the native rules, but I don't think those are available to Skylark. CCing Jon as a randomly chosen victim from the Skylark team :)

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

Andrew Allen

unread,
May 16, 2018, 1:55:05 AM5/16/18
to Marcel Hlopko, bran...@google.com, bazel-discuss
Friendliest of pings


/** ~Andrew Z Allen */

Andrew Allen

unread,
May 20, 2018, 4:55:00 PM5/20/18
to Marcel Hlopko, Jon Brandvein, bazel-discuss
Reping. Thanks for looking at this


/** ~Andrew Z Allen */

Marcel Hlopko

unread,
May 23, 2018, 12:02:53 PM5/23/18
to Andrew Allen, Dmitry Lomov, Laurent Le Brun, Jon Brandvein, bazel-discuss

George Gensure

unread,
May 23, 2018, 12:14:52 PM5/23/18
to Marcel Hlopko, Andrew Allen, Dmitry Lomov, Laurent Le Brun, Jon Brandvein, bazel-discuss
This seems similar to an issue I've already filed: https://github.com/bazelbuild/bazel/issues/4668

I've been mostly unable to generate use cases for directory outputs in buildfarm as a result of this. My only tests are contrived.

-George

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891


--
Marcel Hlopko | Software Engineer | hlo...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Geschäftsführer: Paul Manicle, Halimah DeLaine Prado | Registergericht und -nummer: Hamburg, HRB 86891

--
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/CAFuL9GkEZWiOH33X-r1fe%3DmtoNq8OLhnacX3EiXgxCkgtSr8Qw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages