Skip to content

Commit

Permalink
Allow Invocation Policy to set output-affecting flags in conjunction …
Browse files Browse the repository at this point in the history
…with PROJECT.scl files.

PiperOrigin-RevId: 689004819
Change-Id: Ide4749c79903af3f85774ab9a5666458f2fa9090
  • Loading branch information
susinmotion authored and copybara-github committed Oct 23, 2024
1 parent 8b9122e commit e608349
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ private GlobalRcUtils() {}
&& option.getOrigin().getSource().equals("client")) {
return true;
}
if (option.getOrigin().getSource() != null
&& option.getOrigin().getSource().equals("Invocation policy")) {
return true;
}
return false;
};
// LINT.ThenChange(//src/main/cpp/option_processor.cc)
// LINT.ThenChange(//src/main/cpp/option_processor.cc,
// src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
public final class InvocationPolicyEnforcer {
private static final GoogleLogger logger = GoogleLogger.forEnclosingClass();

// LINT.IfChange
private static final String INVOCATION_POLICY_SOURCE = "Invocation policy";
// LINT.ThenChange(//src/main/java/com/google/devtools/common/options/GlobalRcUtils.java,
// src/main/java/com/google/devtools/common/options/GlobalRcUtils.java
private final InvocationPolicy invocationPolicy;
private final Level loglevel;
@Nullable private final Object conversionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2641,6 +2641,22 @@ public void testOptionsParser_getUserOptions_excludesClientOptions() throws Exce
assertThat(parser.getUserOptions()).containsExactly("--foo");
}

@Test
public void testOptionsParser_getUserOptions_excludesInvocationPolicy() throws Exception {
OptionsParser parser =
OptionsParser.builder()
.optionsClasses(ExpandingOptions.class, ExpandingOptionsFallback.class)
.build();
parser.parseWithSourceFunction(
PriorityCategory.RC_FILE, o -> "Invocation policy", ImmutableList.of("--foo"), null);
assertThat(parser.getUserOptions()).isEmpty();

parser.parseWithSourceFunction(
PriorityCategory.RC_FILE, o -> ".bazelrc", ImmutableList.of("--foo"), null);

assertThat(parser.getUserOptions()).containsExactly("--foo");
}

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

0 comments on commit e608349

Please sign in to comment.