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

Throw exception if 'None' value given to List-type command line options in Bazel transitions #13286

Closed
wants to merge 2 commits into from
Closed
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 @@ -332,6 +332,8 @@ private static BuildOptions applyTransition(
.convert(
optionValueAsList.stream().map(Object::toString).collect(joining(",")));
}
} else if (def.getType() == List.class && optionValue == null) {
throw ValidationException.format("'None' value not allowed for List-type option '%s'. Please use '[]' instead if trying to set option to empty value.", optionName);
} else if (optionValue == null || def.getType().isInstance(optionValue)) {
convertedValue = optionValue;
} else if (def.getType().equals(boolean.class) && optionValue instanceof Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,38 @@ public void successfulTypeConversionOfNativeListOptionEmptyList() throws Excepti
assertThat(getConfiguration(ct).getOptions().get(CppOptions.class).fissionModes).isEmpty();
}

@Test
public void failedTypeConversionOfNativeListOptionNone() throws Exception {
writeAllowlistFile();
scratch.file(
"test/transitions.bzl",
"def _impl(settings, attr):",
" return {'//command_line_option:copt': None}",
"my_transition = transition(implementation = _impl, inputs = [],",
" outputs = ['//command_line_option:copt'])");
scratch.file(
"test/rules.bzl",
"load('//test:transitions.bzl', 'my_transition')",
"def _impl(ctx):",
" return []",
"my_rule = rule(",
" implementation = _impl,",
" cfg = my_transition,",
" attrs = {",
" '_allowlist_function_transition': attr.label(",
" default = '//tools/allowlists/function_transition_allowlist',",
" ),",
" })");
scratch.file(
"test/BUILD",
"load('//test:rules.bzl', 'my_rule')",
"my_rule(name = 'test')");

reporter.removeHandler(failFastHandler);
getConfiguredTarget("//test");
assertContainsEvent("'None' value not allowed for List-type option 'copt'. Please use '[]' instead if trying to set option to empty value.");
}

@Test
public void starlarkPatchTransitionRequiredFragments() throws Exception {
// All Starlark rule transitions are patch transitions, while all Starlark attribute transitions
Expand Down