Skip to content

Commit

Permalink
Respect Starlark options with values in removeStarlarkOptions()
Browse files Browse the repository at this point in the history
Related: bazelbuild#11301
(Partially fixed in bazelbuild@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 bazelbuild#12648.

PiperOrigin-RevId: 348676049
  • Loading branch information
trustin authored and katre committed Jul 13, 2021
1 parent fa08b97 commit 0cd1666
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 @@ -241,6 +241,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 @@ -328,16 +328,26 @@ 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");
}
}

0 comments on commit 0cd1666

Please sign in to comment.