Skip to content

Commit

Permalink
Allow absolute negative target patterns without a -- separator
Browse files Browse the repository at this point in the history
This commit makes `bazel build //foo/... -//bar/...` work, which
previously failed with an invalid option error and required using
`--` as a separator.
  • Loading branch information
fmeum committed Oct 26, 2022
1 parent 48a8d01 commit f50af3b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,14 @@ private OptionsParserImplResult parse(
continue; // not an option arg
}

if (arg.startsWith("-//") || arg.startsWith("-@")) {
// Do not fail on absolute negative target patterns that aren't separated by `--`.
// Relative negative target patterns (e.g. "-pkg:...") aren't readily distinguishable from
// options, so these still require a `--` separator.
unparsedArgs.add(arg);
continue;
}

arg = swapShorthandAlias(arg);

if (arg.equals("--")) { // "--" means all remaining args aren't options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2369,6 +2369,15 @@ public void setOptionValueAtSpecificPriorityWithoutExpansion_expandedFlag_setsVa
.containsExactly("--second=hello");
}

@Test
public void negativeTargetPatternsAddedToPostDoubleDashArgs() throws OptionsParsingException {
OptionsParser parser = OptionsParser.builder().optionsClasses(ExampleFoo.class).build();
parser.parse("//foo", "-//bar", "-@repo//bar", "-@@repo//bar", "--", "//bar", "-//baz");
assertThat(parser.getResidue()).containsExactly("//foo", "-//bar", "-@repo//bar",
"-@@repo//bar", "//bar", "-//baz").inOrder();
assertThat(parser.getPostDoubleDashResidue()).containsExactly("//bar", "-//baz").inOrder();
}

private static OptionInstanceOrigin createInvocationPolicyOrigin() {
return createInvocationPolicyOrigin(/*implicitDependent=*/ null, /*expandedFrom=*/ null);
}
Expand Down

0 comments on commit f50af3b

Please sign in to comment.