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

[6.1.0]Allow map_each to return None in TemplateDict#add_joined #17288

Merged
merged 1 commit into from
Jan 21, 2023
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 @@ -121,12 +121,12 @@ public String getValue() throws EvalException {
/*kwargs=*/ ImmutableMap.of());
if (ret instanceof String) {
parts.add((String) ret);
continue;
} else if (ret != Starlark.NONE) {
throw Starlark.errorf(
"Function provided to map_each must return a String or None, but returned type "
+ "%s for key '%s' and value: %s",
Starlark.type(ret), getKey(), Starlark.repr(val));
}
throw Starlark.errorf(
"Function provided to map_each must return a String, but returned type %s for key:"
+ " %s",
Starlark.type(ret), getKey());
} catch (InterruptedException e) {
// Report the error to the user, but the stack trace is not of use to them
throw Starlark.errorf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public interface TemplateDictApi extends StarlarkValue {
named = true,
positional = false,
doc =
"A Starlark function accepting a single argument and returning a String. This"
+ " function is applied to each item of the depset specified in the"
+ " <code>values</code> parameter"),
"A Starlark function accepting a single argument and returning either a String or "
+ "<code>None</code>. This function is applied to each item of the depset "
+ "specified in the <code>values</code> parameter"),
@Param(
name = "uniquify",
named = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3626,7 +3626,7 @@ public void testTemplateExpansionComputedSubstitution() throws Exception {
scratch.file(
"test/rules.bzl",
"def _artifact_to_basename(file):",
" return file.basename",
" return file.basename if file.basename != 'ignored.txt' else None",
"",
"def _undertest_impl(ctx):",
" template_dict = ctx.actions.template_dict()",
Expand Down Expand Up @@ -3656,7 +3656,7 @@ public void testTemplateExpansionComputedSubstitution() throws Exception {
"undertest_rule(",
" name = 'undertest',",
" template = ':template.txt',",
" srcs = ['foo.txt', 'bar.txt', 'baz.txt'],",
" srcs = ['foo.txt', 'bar.txt', 'baz.txt', 'ignored.txt'],",
")",
"testing_rule(",
" name = 'testing',",
Expand Down Expand Up @@ -3912,8 +3912,8 @@ public void testTemplateExpansionComputedSubstitutionMapEachBadReturnType() thro
assertThat(evalException)
.hasMessageThat()
.isEqualTo(
"Function provided to map_each must return a String, but returned type Label for key:"
+ " %files%");
"Function provided to map_each must return a String or None, but returned "
+ "type Label for key '%files%' and value: <source file test/template.txt>");
}

@Test
Expand Down