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

Complete support for parametrize in overrides #14430

Open
stuhood opened this issue Feb 10, 2022 · 2 comments
Open

Complete support for parametrize in overrides #14430

stuhood opened this issue Feb 10, 2022 · 2 comments

Comments

@stuhood
Copy link
Member

stuhood commented Feb 10, 2022

Supporting parametrize in the overrides of a target generator (in #14408) required changing the shape of overrides, in order to allow some override "keys" to result in multiple targets. Since overrides are implemented separately by each GenerateTargetsRequest instance, fully supporting parametrize for all of them will require changes to each of them.

Un-ported implementations (those not yet supporting parametrize in overrides) use GenerateTargetsRequest.require_unparametrized_overrides to assert that parametrize has not been used in overrides. Porting them involves removing usage of that method, and consuming the overrides directly to potentially generate multiple targets for some override keys.

It's also possible that during the course of porting we'll be able to remove duplication from GenerateTargetsRequest in the area of overrides... perhaps by adjusting target generation into a @rule that returns the list of keys to generate for...?

stuhood added a commit that referenced this issue Feb 11, 2022
…copies of a target (#14408)

As introduced in #13882 and designed in https://docs.google.com/document/d/1mzZWnXiE6OkgMH_Dm7WeA3ck9veusQmr_c6GWPb_tsQ/edit#, this change adds the `parametrize` builtin.

Examples:
```python
# Create two copies of each generated target, with addresses qualified with `@resolve=a` and `@resolve=b`.
python_sources(
  ..,
  resolve=parametrize(“a”, “b”),
)

# ...alternatively, define an alias for some or all of the values:
python_sources(
  ..,
  resolve=parametrize(“a”, b="bread and butter"),
)

# Create four copies of each generated target, with addresses qualified with both parametrized fields.
scala_sources(
  ..,
  resolve=parametrize(“a”, “b”),
  jdk=parametrize("c", "d"),
)

# Apply parametrization to only some of the generated targets:
scala_sources(
  ..,
  overrides={
    "JdkDependent.scala": {"jdk": parametrize("c", "d")},
  },
)
```

----

`parametrize` may be used in any field (other than `name`) of non-generator targets, but is limited to `moved` fields of generator targets (i.e., those which will be moved from the generator to the generated target).

Using `parametrize` in the `overrides` of a target generator requires adjustments to the target generator's implementation (see #14430): this change only adjusts the implementation for target file generators (`TargetFileGenerator`).
@Eric-Arellano
Copy link
Contributor

Is this still relevant?

@stuhood
Copy link
Member Author

stuhood commented May 16, 2022

Yes. All usages of GenerateTargetsRequest.require_unparametrized_overrides are affected, and cannot parametrize their overrides. We could close this if we think that fixing that is a low enough priority though.

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

2 participants