Skip to content

Commit

Permalink
Support contraint_values in select()s for alias rules
Browse files Browse the repository at this point in the history
  • Loading branch information
staalb committed Feb 25, 2021
1 parent 1bae172 commit 272b1bf
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/main/java/com/google/devtools/build/lib/rules/Alias.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 272b1bf

Please sign in to comment.