Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the best way to generate arbitrary JSON files that reference sources and deps? #831

Open
cbarrete opened this issue Jan 5, 2025 · 0 comments

Comments

@cbarrete
Copy link
Contributor

cbarrete commented Jan 5, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant