examples icon indicating copy to clipboard operation
examples copied to clipboard

Add declare_directory example

Open achew22 opened this issue 7 years ago • 5 comments

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.

I attempted to write about this in a thread on Bazel-discus but I figure code will do a decent job of explaining my question.

Additionally reformat with mdformat.

achew22 avatar Apr 28 '18 04:04 achew22

@laurentlb Any progress on this review?

petroseskinder avatar Aug 23 '18 03:08 petroseskinder

ping @tomlu

laurentlb avatar Aug 23 '18 09:08 laurentlb

It isn't possible to iterate over directory contents, because (almost by definition) bazel can't know what's in the directory until execution time. If you did know, then you wouldn't need to use a directory.

tomlu avatar Aug 27 '18 16:08 tomlu

Removing myself as I don't have bandwidth atm.

brandjon avatar Aug 27 '18 18:08 brandjon

@achew22 Any chance to get this PR updated? Would be great to get a directory example merged into master.

Globegitter avatar Aug 27 '19 05:08 Globegitter

Doing some cleanup of the repo. It's almost four years since the last update here so I think it went stale. Please comment if that's wrong.

alexeagle avatar Sep 22 '23 21:09 alexeagle