What's the best way to generate arbitrary JSON files that reference sources and deps? #831
Description
I'd like to write a rule to generate arbitrary JSON files with sources and deps. The implementation of that rule is fairly simple using ctx.actions.write_json
, but the issue comes from the attrs
parameter to rule
.
Consider:
{
"name": "foo",
"components": [
{
"name": "a",
"binary": ":target_a",
"config": "path/to/source"
},
{
"name": "b",
"binary": ":target_b",
"config": "path/to/other/source"
}
],
"extra_artifacts": [":some_target", ":another_one"]
}
In real life the layout would be more complicated, and not something that I would like to replicate the structure of in the rule
's attrs
. Writing out the sum type for this would be quite painful, so I'd like to have to avoid this. It also adds the restriction that the JSON schema has to be known upfront.
Another option would be to write a rule that takes in an existing JSON file and search/replace specific tokens. The rule would then take key/value pairs of token -> source/dep replacement. But that's quite cumbersome for users.
Is there a better to do this?