Skip to content

Commit 272b1bf

Browse files
committed
Support contraint_values in select()s for alias rules
Fixes bazelbuild#13047
1 parent 1bae172 commit 272b1bf

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/Alias.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,6 @@ public RuleClass build(RuleClass.Builder builder, RuleDefinitionEnvironment envi
8989
.allowedRuleClasses(ANY_RULE)
9090
.mandatory())
9191
.canHaveAnyProvider()
92-
// Aliases themselves do not need toolchains or an execution platform, so this is fine.
93-
// The actual target will resolve platforms and toolchains with no issues regardless of
94-
// this setting.
95-
.useToolchainResolution(false)
9692
.build();
9793
}
9894

src/test/java/com/google/devtools/build/lib/analysis/ConfigurableAttributesTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,45 @@ public void nonToolchainResolvingTargetsCantSelectDirectlyOnConstraints() throws
12661266
assertContainsEvent("//conditions:apple is not a valid select() condition for //check:hello");
12671267
}
12681268

1269+
@Test
1270+
public void selectDirectlyOnConstraintsWithAlias() throws Exception {
1271+
// Tests select()ing directly on a constraint_value (with no intermediate config_setting).
1272+
scratch.file(
1273+
"conditions/BUILD",
1274+
"constraint_setting(name = 'fruit')",
1275+
"constraint_value(name = 'apple', constraint_setting = 'fruit')",
1276+
"constraint_value(name = 'banana', constraint_setting = 'fruit')",
1277+
"platform(",
1278+
" name = 'apple_platform',",
1279+
" constraint_values = [':apple'],",
1280+
")",
1281+
"platform(",
1282+
" name = 'banana_platform',",
1283+
" constraint_values = [':banana'],",
1284+
")");
1285+
scratch.file(
1286+
"check/BUILD",
1287+
"filegroup(name = 'adep', srcs = ['afile'])",
1288+
"filegroup(name = 'bdep', srcs = ['bfile'])",
1289+
"alias(name = 'hello',",
1290+
" actual = select({",
1291+
" '//conditions:apple': ':adep',",
1292+
" '//conditions:banana': ':bdep',",
1293+
" }))");
1294+
checkRule(
1295+
"//check:hello",
1296+
"srcs",
1297+
ImmutableList.of("--platforms=//conditions:apple_platform"),
1298+
/*expected:*/ ImmutableList.of("src check/afile"),
1299+
/*not expected:*/ ImmutableList.of("src check/bfile"));
1300+
checkRule(
1301+
"//check:hello",
1302+
"srcs",
1303+
ImmutableList.of("--platforms=//conditions:banana_platform"),
1304+
/*expected:*/ ImmutableList.of("src check/bfile"),
1305+
/*not expected:*/ ImmutableList.of("src check/afile"));
1306+
}
1307+
12691308
@Test
12701309
public void multipleMatchErrorWhenAliasResolvesToSameSetting() throws Exception {
12711310
scratch.file(

0 commit comments

Comments
 (0)