What's the best way to generate arbitrary JSON files that reference sources and deps?
- Dominant language
- Rust
- Stars
- 4.4k
- Forks
- 394
- PR merge metrics
- No merged PRs in 30d
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:
```python
{
"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?
Contributor guide
Research direction
Start with the mentioned ctx.actions.write_json API and rule attrs handling, then look for Buck2 documentation or entry points covering structured inputs with source and dependency references. Done means establishing a supported approach for schema-flexible JSON generation or documenting that the capability is unavailable.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100