Closed cbarrete closed 2 weeks ago
Did you try this?
builder_parameters = {
"output_path": output.as_output(),
"some_dir": some_dir.as_output(),
}
I did, no difference.
I also tried to call builder_parameters.as_output()
, but it's just a dict
, no magic there!
The right thing to do in this scenario is pass with_inputs = True
.
https://buck2.build/docs/api/build/actions/#actionswrite_json
If you pass with_inputs = True, you'll get back a cmd_args that expands to the JSON file but carries all the underlying inputs as dependencies (so you don't have to use, for example, hidden for them to be added to an action that already receives the JSON file)
Indeed, I missed that, thanks Ben :)
Consider the following simplified but somewhat realistic rule implementation:
I am essentially calling some script that is responsible for producing my output. Because it needs a few parameters (in this case just a directory to do work within, but in practice also more structured data), I pass the parameters around via a JSON file, the path of which is passed as the unique command line argument to the builder.
My issue is that I need to add a call to
hidden
, and seemingly manually list the all dependencies (passingbuilder_parameters.values()
does not typecheck). Not only is it in theory redundant, it's also error prone and brittle: any changes that don't properly update thehidden
call would still pass on systems that already have the required dependencies already materialized (quite likely if those are e.g. commonly built targets), but the build would be incorrect and fail after abuck2 clean
.Ideally I'd like
actions.write_json
to propagate its contents as dependencies, which I believe makes sense, but any XY-problem style solutions to my problem would be welcome as well :)