Edit: The example below did actually work, I misinterpreted the output the compiler gave me. The answer may still be helpful to some.
Is there a way for an action in a rule to generate a file that is consumed by a later action in that same rule?
E.g.:
def _example_rule_impl(ctx):
thefile = ctx.actions.declare_file("required_file.json")
ctx.actions.write(
output = thefile,
content = "CONTENT",
)
args = ctx.actions.args()
args.add("--config", thefile)
ctx.actions.run(
inputs = ctx.files.srcs + ctx.files.deps + [thefile],
outputs = outs,
arguments = [args],
progress_message = "Compiling...",
executable = ctx.executable._compiler,
)
The main problem with this seems to be, that all action outputs seem to be written to bazel-out, but the run action requires the generated file to be written next to the srcs and deps files in the execroot for it to work. Is there a way to have an action write to the execroot or is this not the correct approach?