1

Inside a .bzl file,
I specify a program to generate some code. It looks something like this:

def generate_code():
    native.genrule(
        name = "foo",
        outs = ["file.hpp"],
        tools = ["//path/to:tool"],
        cmd = $(location path/to:tool) $(@D)
    )

This works fine,
however the problem is that the tool might generate more files than are specified in outs.
I'm trying to find a way to either have bazel stop the build if more files are generated than specified, or to have the outs automatically be everything generated.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
  • Did you try this and see that bazel doesn’t error out? – Ittai Jun 10 '18 at 16:47
  • yeah, if `$(location path/to:tool) $(@D)` generates `file1.hpp` and `file2.hpp`, but I only specify `file1.hpp` in my `outs` list, then only `file1.hpp` is transfered to `bazel-gen` and `file2.hpp` gets lost in translation. Obviously, I find out its missing if other rules need to use the file, but I was hoping bazel would know everything the tool generates and error/warn if something was generated into `$(@D)`, but unspecified as an out. – Trevor Hickey Jun 10 '18 at 21:23
  • Does this also happen in a "full fledged" rule? I think it doesn't but couldn't find the time to validate – Ittai Jun 12 '18 at 06:03

1 Answers1

0

I'm not aware of a generalized way to have bazel error out if additional, unexpected files were generated.

One thing I could recommend is wrapping your tool in another tool which verifies the output files in the target directory and only returns success if no unexpected files were generated.

As for a generalized solution that intentionally includes all files in an output directory, consider using actions.declare_directory and creating a skylark rule instead of using native.genrule.