Skip to content
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

[7.1.0] Accept labels of aliases in config_setting. #20649

Merged
merged 2 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,14 @@ static UserDefinedFlagMatch fromAttributeValueAndPrerequisites(
} else if (target.satisfies(BuildSettingProvider.REQUIRE_BUILD_SETTING_PROVIDER)) {
// build setting
BuildSettingProvider provider = target.getProvider(BuildSettingProvider.class);
Object configurationValue =
optionDetails.getOptionValue(specifiedLabel) != null
? optionDetails.getOptionValue(specifiedLabel)
: provider.getDefaultValue();

Object configurationValue;
if (optionDetails.getOptionValue(provider.getLabel()) != null) {
configurationValue = optionDetails.getOptionValue(provider.getLabel());
} else {
configurationValue = provider.getDefaultValue();
}

Object convertedSpecifiedValue;
try {
// We don't need to supply a base package or repo mapping for the conversion here,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,35 @@ public void testLabelFlag_set() throws Exception {
assertThat(b.get("value")).isEqualTo("command_line_value");
}

@Test
public void withSelectThroughAlias() throws Exception {
writeRulesBzl("flag");
scratch.file(
"test/BUILD",
"load('//test:rules.bzl', 'my_rule', 'simple_rule')",
"simple_rule(name = 'default', value = 'default_value')",
"simple_rule(name = 'command_line', value = 'command_line_value')",
"label_flag(name = 'my_label_flag', build_setting_default = ':default')",
"alias(name = 'my_label_flag_alias', actual = ':my_label_flag')",
"config_setting(",
" name = 'is_default_label',",
" flag_values = {':my_label_flag_alias': '//test:default'}",
")",
"simple_rule(name = 'selector', value = select({':is_default_label': 'valid'}))");

useConfiguration();
getConfiguredTarget("//test:selector");
assertNoEvents();

reporter.removeHandler(failFastHandler);
useConfiguration(
ImmutableMap.of(
"//test:my_label_flag", Label.parseCanonicalUnchecked("//test:command_line")));
getConfiguredTarget("//test:selector");
assertContainsEvent(
"configurable attribute \"value\" in //test:selector doesn't match this configuration");
}

@Test
public void withSelect() throws Exception {
writeRulesBzl("flag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2174,6 +2174,27 @@ public void ruleLicensesUsed() throws Exception {
assertThat(getLicenses("//test:match")).containsExactly(LicenseType.NONE);
}

@Test
public void aliasedStarlarkFlag() throws Exception {
scratch.file(
"test/flagdef.bzl",
"def _impl(ctx):",
" return []",
"my_flag = rule(",
" implementation = _impl,",
" build_setting = config.string(flag = True))");

scratch.file(
"test/BUILD",
"load('//test:flagdef.bzl', 'my_flag')",
"my_flag(name = 'flag', build_setting_default = 'default')",
"alias(name = 'alias', actual = ':flag')",
"config_setting(name = 'alias_setting', flag_values = {':alias': 'specified'})");

useConfiguration(ImmutableMap.of("//test:flag", "specified"));
assertThat(getConfigMatchingProviderResultAsBoolean("//test:alias_setting")).isTrue();
}

@Test
public void simpleStarlarkFlag() throws Exception {
scratch.file(
Expand Down
Loading