diff options
author | ccalvarin <ccalvarin@google.com> | 2018-04-17 07:48:38 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-04-17 07:50:36 -0700 |
commit | 9c8c77502ff52907a327e6bdc9ac282da0af6b44 (patch) | |
tree | 14b05cdc2eb7db3231a05c6a119d0c6aba876495 /src | |
parent | a4ca5e77ea1cd2ee86632af168f107ea7be9e980 (diff) |
Make attempting to change --config in invocation policy an error.
It will not work as expected, since config is already expanded by this point in options processing.
RELNOTES: None.
PiperOrigin-RevId: 193196664
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java | 9 | ||||
-rw-r--r-- | src/test/java/com/google/devtools/common/options/InvocationPolicySetValueTest.java | 27 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java b/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java index 88deb46c4c..3b42a29d85 100644 --- a/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java +++ b/src/main/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java @@ -248,6 +248,15 @@ public final class InvocationPolicyEnforcer { OptionPriority nextPriority = OptionPriority.lowestOptionPriorityAtCategory(PriorityCategory.INVOCATION_POLICY); for (FlagPolicy policy : invocationPolicy.getFlagPoliciesList()) { + // Explicitly disallow --config in invocation policy. + if (policy.getFlagName().equals("config")) { + throw new OptionsParsingException( + "Invocation policy is applied after --config expansion, changing config values now " + + "would have no effect and is disallowed to prevent confusion. Please remove the " + + "following policy : " + + policy); + } + // These policies are high-level, before expansion, and so are not the implicitDependents or // expansions of any other flag, other than in an obtuse sense from --invocation_policy. OptionPriority currentPriority = nextPriority; diff --git a/src/test/java/com/google/devtools/common/options/InvocationPolicySetValueTest.java b/src/test/java/com/google/devtools/common/options/InvocationPolicySetValueTest.java index c8d08cc110..22324196b2 100644 --- a/src/test/java/com/google/devtools/common/options/InvocationPolicySetValueTest.java +++ b/src/test/java/com/google/devtools/common/options/InvocationPolicySetValueTest.java @@ -481,4 +481,31 @@ public class InvocationPolicySetValueTest extends InvocationPolicyEnforcerTestBa // expected. } } + + @Test + public void testConfigNotAllowed() throws Exception { + InvocationPolicy.Builder invocationPolicyBuilder = InvocationPolicy.newBuilder(); + invocationPolicyBuilder + .addFlagPoliciesBuilder() + .setFlagName("config") + .getSetValueBuilder() + .addFlagValue("foo"); + + InvocationPolicyEnforcer enforcer = createOptionsPolicyEnforcer(invocationPolicyBuilder); + parser.parse(); + try { + enforcer.enforce(parser, BUILD_COMMAND); + fail(); + } catch (OptionsParsingException expected) { + assertThat(expected) + .hasMessageThat() + .isEqualTo( + "Invocation policy is applied after --config expansion, changing config values now " + + "would have no effect and is disallowed to prevent confusion. Please remove " + + "the following policy : flag_name: \"config\"\n" + + "set_value {\n" + + " flag_value: \"foo\"\n" + + "}\n"); + } + } } |