Hi, I recently came across a problem in Bazel wher...
# general
i
Hi, I recently came across a problem in Bazel where you have a rule that outputs a directory of randomly named files instead of a few known files. This means you can't add it to the build graph because that only deals in files, not directories. The currently recommended workaround is to zip/unzip the directory before/after running the rule. Not idea. I was wondering if Pants handles this any better?
b
Mmmm you'd have to be more specific on the problem at hand to get a complete answer. Pants certainly can handle various things at the directory (and file) level, but depending on the situation your ability to cache results of operations may diminish
i
Well in Bazel when you define a rule you'd like to say something like this:
Copy code
ctx.actions.run(
        ...
        outputs = [work_dir],
    )
Where
work_dir
is a directory that gets a load of randomly named files written to it. But it doesn't really work because the build graph operates on files with names that are all known at analysis time.
It doesn't have the concept of "this rule generates a directory of stuff, and this other rule needs access to that directory as input".
b
So Pants defintely supports directory-as-a-unit both at the BUILD-level (
experimental_shell_command
comes to mind) and at the Plugin level (using a
Digest
). Depending on where/how the directory is captured is the razor for caching. So in that regard YMMV
i
Ah ok cool that's good to know!