-
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
Allow string_list flags to be set via repeated flag uses #14911
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3024,6 +3024,65 @@ public void testBuildSettingValue_allowMultipleSetting() throws Exception { | |
.containsExactly("some-other-value", "some-other-other-value"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
@Test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all of these test cases are great. Thank you for adding them. Could we also add test case for this example
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great point, added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! |
||
public void testBuildSettingValue_isRepeatedSetting() throws Exception { | ||
scratch.file( | ||
"test/build_setting.bzl", | ||
"BuildSettingInfo = provider(fields = ['name', 'value'])", | ||
"def _impl(ctx):", | ||
" return [BuildSettingInfo(name = ctx.attr.name, value = ctx.build_setting_value)]", | ||
"", | ||
"string_list_flag = rule(", | ||
" implementation = _impl,", | ||
" build_setting = config.string_list(flag = True, repeatable = True),", | ||
")"); | ||
scratch.file( | ||
"test/BUILD", | ||
"load('//test:build_setting.bzl', 'string_list_flag')", | ||
"string_list_flag(name = 'string_list_flag', build_setting_default = ['some-value'])"); | ||
|
||
// from default | ||
ConfiguredTarget buildSetting = getConfiguredTarget("//test:string_list_flag"); | ||
Provider.Key key = | ||
new StarlarkProvider.Key( | ||
Label.create(buildSetting.getLabel().getPackageIdentifier(), "build_setting.bzl"), | ||
"BuildSettingInfo"); | ||
StructImpl buildSettingInfo = (StructImpl) buildSetting.get(key); | ||
|
||
assertThat(buildSettingInfo.getValue("value")).isInstanceOf(List.class); | ||
assertThat((List<String>) buildSettingInfo.getValue("value")).containsExactly("some-value"); | ||
|
||
// Set multiple times | ||
useConfiguration( | ||
ImmutableMap.of( | ||
"//test:string_list_flag", ImmutableList.of("some-other-value", "some-other-other-value"))); | ||
buildSetting = getConfiguredTarget("//test:string_list_flag"); | ||
key = | ||
new StarlarkProvider.Key( | ||
Label.create(buildSetting.getLabel().getPackageIdentifier(), "build_setting.bzl"), | ||
"BuildSettingInfo"); | ||
buildSettingInfo = (StructImpl) buildSetting.get(key); | ||
|
||
assertThat(buildSettingInfo.getValue("value")).isInstanceOf(List.class); | ||
assertThat((List<String>) buildSettingInfo.getValue("value")) | ||
.containsExactly("some-other-value", "some-other-other-value"); | ||
|
||
// No splitting on comma. | ||
useConfiguration( | ||
ImmutableMap.of("//test:string_list_flag", ImmutableList.of("a,b,c", "a", "b,c"))); | ||
buildSetting = getConfiguredTarget("//test:string_list_flag"); | ||
key = | ||
new StarlarkProvider.Key( | ||
Label.create(buildSetting.getLabel().getPackageIdentifier(), "build_setting.bzl"), | ||
"BuildSettingInfo"); | ||
buildSettingInfo = (StructImpl) buildSetting.get(key); | ||
|
||
assertThat(buildSettingInfo.getValue("value")).isInstanceOf(List.class); | ||
assertThat((List<String>) buildSettingInfo.getValue("value")) | ||
.containsExactly("a,b,c", "a", "b,c"); | ||
} | ||
|
||
@Test | ||
public void testBuildSettingValue_nonBuildSettingRule() throws Exception { | ||
scratch.file( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this actually do anything beside doc? I was thinking it would be nice to emit a WARNING from now on if allowMultiple is being used. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outside Google, such a warning probably wouldn't work that well: The ones seeing the warning (ruleset users on a new Bazel version) would not be the ones in a position to fix it (ruleset authors). In the past, I think that this has been handled via an
--incompatible_*
flag, which is flipped at some point with a full downstream pipeline running against the popular rulesets before the flip.