-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Allow multiple matching select branches if they resolve to the same value #14874
Allow multiple matching select branches if they resolve to the same value #14874
Conversation
2f19014
to
436e9a7
Compare
Interesting proposal. What use cases inspired it? I'm reluctant to loosen the current strict matching requirements without a good, thorough discussion (happy to have it here). My main conceptual worry is there's also meaningful signal knowing - decisively and unambiguously - which branch matches. For example, for I appreciate that strict interpretation results in awkward workarounds a you describe. And we already have one instance of multiple matches when one match is a clear specialization of the other. Although even in that case a single branch is clearly selected by design, and without having to consider the values. |
FWIW I have hit this many times in complex select statements with envoy where you may want to do specific flags for a platform, and for a compilation mode. In general we have worked around them at this point but here are some complex examples https://github.com/envoyproxy/envoy/blob/4a03e625960267032577f6792eef41d715b87b40/bazel/envoy_binary.bzl#L56-L117 |
@gregestren the main rationale is complexity. As Keith mentioned, conditions can easily get quite complex, especially when combining multiple together. |
@AlessandroPatti can you trace your your example a bit more explicitly? Apologies for not parsing it more quickly. I want to make sure I fully understand the relationship you're describing between flag values, @keith would select.with_or or config_setting_group be insufficient for your cases? |
I wish I had a better example off the top of my head, since we had to work around most of them already. In general the situation has been we've had a bunch of feature flags in the envoy build, some of which support specific platforms only, so when selects have both platform specifics, and feature flag specifics, we ended up with this conflict. Maybe this case could be refactored now though? https://github.com/envoyproxy/envoy/blob/b8c4d4bae0c48c2a97126e486651987ceab7b493/bazel/BUILD#L219-L282 The other thing I worry about is the combinatorial explosion of config_setting_groups if we need use that for disambiguation. |
@gregestren sorry I wasn't clear before, I'll try to expand on that here. I was suggesting a case with a VALUES = ["v"+ str(i) for i in range(9)]
string_list_flag(
name = "setting",
build_setting_default = VALUES,
)
[
config_setting(
name = v,
flag_values = {
"//:setting": v,
}
)
for v in VALUES
] which can be set on the command like like my_rule(
...
target_compatible_with = select({
"//:v1-or-v5-or-v6": [],
"//conditions:defaults": ["@platforms//:incompatible"],
}),
) The complexity araises when creating the targets like load("//:utils.bzl", "powerset")
[
selects.config_setting_group(
# Sort values to a deterministic name. Note that this mean that `v1-or-v3` is valid but `v3-or-v1` is not
name = "-or-".join(sorted(group)),
match_any = ["//:{}".format(v) for v in group],
)
for group in powerset(VALUES)
# exclude empty group and unary groups which are already defined as `config_settings` above
if len(group) > 1
] The above requires implementing select({
"//:{}".format(v): [],
for v in ["v1", "v5", "v6"],
}) |
@gregestren any update on this? |
I discussed this with other devs last week. Let me follow up soon to your last comments - I'll aim for tomorrow or the day after. I appreciate your patience. |
Caught up.
|
Hello @AlessandroPatti , Can you please take a look on above comments and reply. Thanks! |
@sgowroji @gregestren Sorry, I lost track of this.
Yes, multiple value could be set in the scenario I was describing, and indeed defining and using
Yes, this is what I did in practice, but I found this to still be more complex than creating a simple select with the individual values (i.e. AFAIK, this is just a matter of convenience, using |
@aiuto revived this request to me. I see I was the last one to drop the ball - apologies. I'm open to this if people still want it. My main followup comments would be updating documentation. And one pedantic technical nitpick about which condition is chosen in the code and if it matters? |
436e9a7
to
676028e
Compare
Done, I think. Please let me know if I missed any other place that needs update.
I think this is already deterministic: the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one small nit (for a wrinkle you're not responsible for).
Otherwise LGTM, and thanks for persevering through this.
src/main/java/com/google/devtools/build/lib/packages/ConfiguredAttributeMapper.java
Outdated
Show resolved
Hide resolved
676028e
to
1f3e259
Compare
@bazel-io flag |
@bazel-io fork 6.2.0 |
…alue Select branches that map to the same value can unambiguosly be resolved even when multiple are true. This is currently not allowed and requires the use of constructs like `bazel-skylib`'s `selects.config_setting_group`. With this change, assuming A and B are true, the following is allowed: ``` select({ "//:A": "Value", "//:B": "Value", }) ``` Closes bazelbuild#14874. PiperOrigin-RevId: 523597091 Change-Id: I751809b1b9e11d20a86ae2af4bbdb0228fd3c670
…alue (#18066) Select branches that map to the same value can unambiguosly be resolved even when multiple are true. This is currently not allowed and requires the use of constructs like `bazel-skylib`'s `selects.config_setting_group`. With this change, assuming A and B are true, the following is allowed: ``` select({ "//:A": "Value", "//:B": "Value", }) ``` Closes #14874. PiperOrigin-RevId: 523597091 Change-Id: I751809b1b9e11d20a86ae2af4bbdb0228fd3c670 Co-authored-by: Alessandro Patti <[email protected]>
…alue Select branches that map to the same value can unambiguosly be resolved even when multiple are true. This is currently not allowed and requires the use of constructs like `bazel-skylib`'s `selects.config_setting_group`. With this change, assuming A and B are true, the following is allowed: ``` select({ "//:A": "Value", "//:B": "Value", }) ``` Closes bazelbuild#14874. PiperOrigin-RevId: 523597091 Change-Id: I751809b1b9e11d20a86ae2af4bbdb0228fd3c670
Select branches that map to the same value can unambiguosly be resolved even when multiple are true. This is currently not allowed and requires the use of constructs like
bazel-skylib
'sselects.config_setting_group
. With this change, assuming A and B are true, the following is allowed: