Skip to content

Commit

Permalink
Support --no@//:bool_flag on the command line.
Browse files Browse the repository at this point in the history
This applies label canonicalization to starlark flags having a `--no`
prefix.

Relates to #11128.

Closes #13418.

PiperOrigin-RevId: 372619463
  • Loading branch information
rbeasley authored and copybara-github committed May 7, 2021
1 parent 41a0c35 commit 32d5268
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ private void parseArg(
buildSettingTarget.getAssociatedRule().getRuleClassObject().getBuildSetting();
if (current.getType().equals(BOOLEAN)) {
// --boolean_flag or --noboolean_flag
unparsedOptions.put(name, new Pair<>(String.valueOf(booleanValue), buildSettingTarget));
// Ditto w/r/t canonical form.
unparsedOptions.put(
buildSettingTarget.getLabel().getCanonicalForm(),
new Pair<>(String.valueOf(booleanValue), buildSettingTarget));
} else {
if (!booleanValue) {
// --no(non_boolean_flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ public void testNoPrefixedBooleanFlag() throws Exception {
assertThat(result.getResidue()).isEmpty();
}

// test --no@main_workspace//:bool_flag
@Test
public void testNoPrefixedBooleanFlag_withWorkspace() throws Exception {
writeBasicBoolFlag();

OptionsParsingResult result = parseStarlarkOptions("--no@//test:my_bool_setting");

assertThat(result.getStarlarkOptions()).hasSize(1);
assertThat(result.getStarlarkOptions().get("//test:my_bool_setting")).isEqualTo(false);
assertThat(result.getResidue()).isEmpty();
}

// test --noint_flag
@Test
public void testNoPrefixedNonBooleanFlag() throws Exception {
Expand Down

0 comments on commit 32d5268

Please sign in to comment.