-
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
Weird behavior with alias
and target_compatible_with
#17663
Comments
Assigned to self for triage. |
I can reproduce. I wonder if this is because the logic doesn't check source files for compatibility, although I'm not sure what makes the @philsc for reference. |
Maybe #14096 explains the different in Bazel 6.0? |
The difference in 6.0 is indeed caused by the refactor in #14096. I thought I got this working, but apparently it doesn't work for In particular, the bazel/src/main/java/com/google/devtools/build/lib/skyframe/PrerequisiteProducer.java Lines 334 to 335 in c8388e3
I haven't dug into why, but I'm guessing it has something to do with the fact that we want to be able to create aliases to platform constraints. In which case we don't want to evaluate toolchain information unless necessary. |
Okay, piggy backing on @gregestren 's #14310, this patch appears to fix the issue: diff --git a/src/main/java/com/google/devtools/build/lib/packages/Rule.java b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
index a931906337..d7a9fef42c 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Rule.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Rule.java
@@ -1225,8 +1225,10 @@ public class Rule implements Target, DependencyFilter.AttributeInfoProvider {
return true;
} else if (mode == ToolchainResolutionMode.HAS_SELECT) {
RawAttributeMapper attr = RawAttributeMapper.of(this);
- return (attr.has(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE)
- && !attr.get(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE, BuildType.LABEL_LIST).isEmpty());
+ return ((attr.has(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE)
+ && !attr.get(RuleClass.CONFIG_SETTING_DEPS_ATTRIBUTE, BuildType.LABEL_LIST).isEmpty()) ||
+ (attr.has(RuleClass.TARGET_COMPATIBLE_WITH_ATTR)
+ && !attr.get(RuleClass.TARGET_COMPATIBLE_WITH_ATTR, BuildType.LABEL_LIST).isEmpty()));
} else {
return false;
} @gregestren , WDYT about that? It seems fairly innocuous. At least compared to the existing logic. Happy to rename the |
@philsc that sounds good. Thanks for getting to the bottom of this. I don't know what the right updated name to |
Currently the `target_compatible_with` on `alias()` targets only works when a `select()` is involved. That's because `alias()` targets by default don't have a toolchains evaluated. This patch changes the behaviour by making it so all `alias()` targets with a `target_compatible_with` attribute are skipped appropriately. When `target_compatible_with` is present, then toolchains are evaluated for `alias()` targets. The implementation is basically an enhancement to @gregestren's 1c3a245 (bazelbuild#14310). In addition to resolving toolchains when a `select()` is present, Bazel will now also resolve toolchains when a `target_compatible_with` attribute is set. I also took this opportunity to rename `HAS_SELECT` to something more appropriate. The name may be too long now, but I feel that at least it's descriptive. Fixes bazelbuild#17663 Closes bazelbuild#17983. PiperOrigin-RevId: 522446438 Change-Id: I80bce3e840553b75960022545df7f27ad1d1d363
Description of the bug:
Setting
target_compatible_with
on alias does not work as expected. See repro below.What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Consider the following top-level BUILD.bazel file. (full repro bazel-alias-bug.zip)
foo
andfoo2
should behave the same. However, on an M1 Mac with Bazel 6.0.0, I haveWith Bazel 5.4.0, I have
Behavior of
foo2
is correct in both cases.foo
is both incorrect in 5.4.0 and 6.0.0.Which operating system are you running Bazel on?
macOS
What is the output of
bazel info release
?release 5.4.0 and release 6.0.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: