diff --git a/src/main/java/com/google/devtools/build/lib/rules/Alias.java b/src/main/java/com/google/devtools/build/lib/rules/Alias.java index d50fa98e99caa6..b916124c8cf401 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/Alias.java +++ b/src/main/java/com/google/devtools/build/lib/rules/Alias.java @@ -89,10 +89,6 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi .allowedRuleClasses(ANY_RULE) .mandatory()) .canHaveAnyProvider() - // Aliases themselves do not need toolchains or an execution platform, so this is fine. - // The actual target will resolve platforms and toolchains with no issues regardless of - // this setting. - .useToolchainResolution(false) .build(); } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java index 4cd7ad34d9424d..070a7f9b5d4179 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java @@ -1266,6 +1266,45 @@ public void nonToolchainResolvingTargetsCantSelectDirectlyOnConstraints() throws assertContainsEvent("//conditions:apple is not a valid select() condition for //check:hello"); } + @Test + public void selectDirectlyOnConstraintsWithAlias() throws Exception { + // Tests select()ing directly on a constraint_value (with no intermediate config_setting). + scratch.file( + "conditions/BUILD", + "constraint_setting(name = 'fruit')", + "constraint_value(name = 'apple', constraint_setting = 'fruit')", + "constraint_value(name = 'banana', constraint_setting = 'fruit')", + "platform(", + " name = 'apple_platform',", + " constraint_values = [':apple'],", + ")", + "platform(", + " name = 'banana_platform',", + " constraint_values = [':banana'],", + ")"); + scratch.file( + "check/BUILD", + "filegroup(name = 'adep', srcs = ['afile'])", + "filegroup(name = 'bdep', srcs = ['bfile'])", + "alias(name = 'hello',", + " actual = select({", + " '//conditions:apple': ':adep',", + " '//conditions:banana': ':bdep',", + " }))"); + checkRule( + "//check:hello", + "srcs", + ImmutableList.of("--platforms=//conditions:apple_platform"), + /*expected:*/ ImmutableList.of("src check/afile"), + /*not expected:*/ ImmutableList.of("src check/bfile")); + checkRule( + "//check:hello", + "srcs", + ImmutableList.of("--platforms=//conditions:banana_platform"), + /*expected:*/ ImmutableList.of("src check/bfile"), + /*not expected:*/ ImmutableList.of("src check/afile")); + } + @Test public void multipleMatchErrorWhenAliasResolvesToSameSetting() throws Exception { scratch.file(