Search code examples
bazel

Keep build output for post-build inspection in Bazel genrule


I am using a Bazel genrule to run a script that takes some input files and produces some output files. Some outputs are dependencies for subsequent genrules of the same form, and a dependency graph is formed.

In addition to the generated outputs I am coding in as dependencies, there are logs and reports associated with the job. Some of these are deterministic and could be hard coded as output files, however others contain timestamps and other meta information like CPU usage which legitimately varies between runs, and therefore can not be coded as outputs as it would invalidate the cache.

Our users need to inspect these output files after the build, and I am wondering how I can collect such files for post-build consumption. I've considered using rsync or similar, but it seems kind of hackish and I feel like this would be a "normal" enough use case that Bazel would support it directly, however my google-fu has failed me on it.

I've tried using https://docs.aspect.build/rules/aspect_bazel_lib/docs/run_binary but there is a limitation around nesting output directories between rules which is tricky to overcome, based on how the tool works. So I'm looking for other suggestions for how to solve this.


Solution

  • If you include them as outputs from the action, but no other action uses them as inputs, it won't affect caching of any downstream actions. Cache entries are based on files, not actions.

    Action outputs are the only thing that comes out of the sandbox, so there isn't really any other option.