Skip to content

Commit

Permalink
Respect Starlark options with values in removeStarlarkOptions()
Browse files Browse the repository at this point in the history
Related: #11301
(Partially fixed in 2ec58f6)

Motivation:

`StarlarkOptionsParser.removeStarlarkOptions()` doesn't take the case
into account where the specified Starlark option has a value, e.g.
`--//my_rules/custom_flags:foo=bar`.

Modifications:

- Do not pass a Starlark flag value when validating the flag name.

Result:

`bazel info` does not fail anymore when `.bazelrc` contains a statement
like the following:

    build --//my_rules/custom_flags:foo=bar

Closes #12648.

PiperOrigin-RevId: 348676049
  • Loading branch information
trustin authored and copybara-github committed Dec 22, 2020
1 parent 4369cc9 commit 64157a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ public static Pair<ImmutableList<String>, ImmutableList<String>> removeStarlarkO
if (name.startsWith("no")) {
potentialStarlarkFlag = potentialStarlarkFlag.substring(2);
}
// Check if the string contains a value, trim off the value if so.
int equalsIdx = potentialStarlarkFlag.indexOf('=');
if (equalsIdx > 0) {
potentialStarlarkFlag = potentialStarlarkFlag.substring(0, equalsIdx);
}
// Check if we can properly parse the (potentially trimmed) string as a label. If so, count
// as starlark flag, else count as regular residue.
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,27 @@ public void testRemoveStarlarkOptionsWorks() throws Exception {
StarlarkOptionsParser.removeStarlarkOptions(
ImmutableList.of(
"--//local/starlark/option",
"--//local/starlark/option=with_value",
"--@some_repo//external/starlark/option",
"--@some_repo//external/starlark/option=with_value",
"--@//main/repo/option",
"--@//main/repo/option=with_value",
"some-random-residue",
"--mangled//external/starlark/option"));
"--mangled//external/starlark/option",
"--mangled//external/starlark/option=with_value"));
assertThat(residueAndStarlarkOptions.getFirst())
.containsExactly(
"--//local/starlark/option",
"--//local/starlark/option=with_value",
"--@some_repo//external/starlark/option",
"--@//main/repo/option");
"--@some_repo//external/starlark/option=with_value",
"--@//main/repo/option",
"--@//main/repo/option=with_value");
assertThat(residueAndStarlarkOptions.getSecond())
.containsExactly("some-random-residue", "--mangled//external/starlark/option");
.containsExactly(
"some-random-residue",
"--mangled//external/starlark/option",
"--mangled//external/starlark/option=with_value");
}

/**
Expand Down

0 comments on commit 64157a5

Please sign in to comment.