-
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
cquery with starlark output uses wrong label for alias targets #18421
Comments
I think if we were to go about this, ideally we should swap the meaning - I think most users when writing a starlark query would expect |
Work around bazelbuild/bazel#17749 and bazelbuild/bazel#18421
Work around bazelbuild/bazel#17749 and bazelbuild/bazel#18421
Description of the bug:
https://bazel.build/extending/platforms#cquery-incompatible-target-detection gives the following snippet as the canonical way of filtering incompatible targets:
Unfortunately,
target.label
returns the label ofactual
, not thealias
itself, foralias
targets:The repr of the target contains both pieces of information:
I would expect
target.label
to return the actual label of all targets, and for any alias lookup to require looking at a specific property or provider, rather than automatically passing through.AliasConfiguredTarget
explicitly overridesgetLabel
to have this behaviour,bazel/src/main/java/com/google/devtools/build/lib/rules/AliasConfiguredTarget.java
Lines 126 to 129 in 277d05f
AFAICT the quick way to fix this would be to use a custom
StarlarkSemantics
for cquery, and overrideObject getValue(StarlarkSemantics semantics, String name)
onAliasConfiguredTarget
so thatgetValue(CquerySemantics, "label")
returns the original label not the aliased one. I suspect actually changing any of the behaviours ofgetLabel
anywhere else would be a huge scary change...It's worth noting this isn't the first time this has come up - see
bazel/src/main/java/com/google/devtools/build/lib/query2/cquery/ConfiguredTargetQueryEnvironment.java
Lines 465 to 473 in 6c1487c
bazel/src/main/java/com/google/devtools/build/lib/query2/aquery/ActionGraphQueryEnvironment.java
Lines 181 to 186 in 6c1487c
/cc @lberki as the author of
AliasConfiguredTarget
, @gregestren and @fmeum as cquery --output=starlark folks.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
No response
Which operating system are you running Bazel on?
No response
What is the output of
bazel info release
?release 6.2.0
If
bazel info release
returnsdevelopment version
or(@non-git)
, tell us how you built Bazel.No response
What's the output of
git remote get-url origin; git rev-parse master; git rev-parse HEAD
?No response
Have you found anything relevant by searching the web?
No response
Any other information, logs, or outputs that you want to share?
No response
The text was updated successfully, but these errors were encountered: