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.4.0] Ignore Starlark options on commands with allowResidue = False #19417

Merged
merged 1 commit into from
Sep 6, 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 @@ -758,10 +758,8 @@ public ImmutableList<String> parseArgsAsExpansionOfOption(
private void addResidueFromResult(OptionsParserImplResult result) throws OptionsParsingException {
residue.addAll(result.getResidue());
postDoubleDashResidue.addAll(result.postDoubleDashResidue);
if (!allowResidue && (!getSkippedArgs().isEmpty() || !residue.isEmpty())) {
String errorMsg =
"Unrecognized arguments: "
+ Joiner.on(' ').join(Iterables.concat(getSkippedArgs(), residue));
if (!allowResidue && !residue.isEmpty()) {
String errorMsg = "Unrecognized arguments: " + Joiner.on(' ').join(residue);
throw new OptionsParsingException(errorMsg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,24 +437,6 @@ public void testParseOptions_residue() {
assertThat(optionHandler.getRcfileNotes()).isEmpty();
}

@Test
public void testParseOptions_disallowResidue_skippedArgsLeadToFailure() throws Exception {
ImmutableList<Class<? extends OptionsBase>> optionsClasses =
ImmutableList.of(TestOptions.class, CommonCommandOptions.class, ClientOptions.class);

BlazeOptionHandlerTestHelper helper =
new BlazeOptionHandlerTestHelper(
optionsClasses,
/* allowResidue= */ false,
/* aliasFlag= */ null,
/* skipStarlarkPrefixes= */ true);
OptionsParser parser = helper.getOptionsParser();

OptionsParsingException e =
assertThrows(OptionsParsingException.class, () -> parser.parse("--//f=1"));
assertThat(e).hasMessageThat().isEqualTo("Unrecognized arguments: --//f=1");
}

@Test
public void testParseOptions_explicitOption() {
optionHandler.parseOptions(
Expand Down
14 changes: 14 additions & 0 deletions src/test/py/bazel/options_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,20 @@ def testCommonPseudoCommand_unsupportedOptionValue(self):
stderr,
)

def testCommonPseudoCommand_allowResidueFalseCommandIgnoresStarlarkOptions(
self,
):
self.ScratchFile("WORKSPACE.bazel")
self.ScratchFile(
".bazelrc",
[
"common --@foo//bar:flag",
],
)

# Check that version doesn't fail.
self.RunBazel(["version"])


if __name__ == "__main__":
unittest.main()