summaryrefslogtreecommitdiff
path: root/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java
diff options
context:
space:
mode:
authorIvan Gavrilovic <gavra@google.com>2018-05-08 02:26:09 -0700
committerandroid-build-merger <android-build-merger@google.com>2018-05-08 02:26:09 -0700
commit2b50d295f5acc8ddf8924cd6536dfbfe45965ade (patch)
tree74deac1e16e97c2c13f226cd4635cd65abf19303 /java/com/google/devtools/common/options/InvocationPolicyEnforcer.java
parent301a69dfe6fbb59072b6c1af278ec31c10cbdf35 (diff)
parent6beb00b4744298d2ef28b6590c31b6848885b28d (diff)
downloaddesugar-2b50d295f5acc8ddf8924cd6536dfbfe45965ade.tar.gz
Merge remote-tracking branch upstream-master into master am: 9d2aa11004android-o-mr1-iot-release-1.0.4android-o-mr1-iot-release-1.0.3
am: 6beb00b474 Change-Id: I5f801929d952fac02c0b652fb9003295f4bf7820
Diffstat (limited to 'java/com/google/devtools/common/options/InvocationPolicyEnforcer.java')
-rw-r--r--java/com/google/devtools/common/options/InvocationPolicyEnforcer.java33
1 files changed, 24 insertions, 9 deletions
diff --git a/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java b/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java
index a53ff5b..3b42a29 100644
--- a/java/com/google/devtools/common/options/InvocationPolicyEnforcer.java
+++ b/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;
@@ -306,9 +315,7 @@ public final class InvocationPolicyEnforcer {
* <p>None of the flagPolicies returned should be on expansion flags.
*/
private static List<FlagPolicyWithContext> expandPolicy(
- FlagPolicyWithContext originalPolicy,
- OptionsParser parser,
- Level loglevel)
+ FlagPolicyWithContext originalPolicy, OptionsParser parser, Level loglevel)
throws OptionsParsingException {
List<FlagPolicyWithContext> expandedPolicies = new ArrayList<>();
@@ -701,11 +708,15 @@ public final class InvocationPolicyEnforcer {
}
// Check that if the default value of the flag is disallowed by the policy, that the policy
- // does not also set use_default. Otherwise the default value would will still be set if the
+ // does not also set use_default. Otherwise the default value would still be set if the
// user uses a disallowed value. This doesn't apply to repeatable flags since the default
- // value for repeatable flags is always the empty list.
- if (!optionDescription.getOptionDefinition().allowsMultiple()) {
-
+ // value for repeatable flags is always the empty list. It also doesn't apply to flags that
+ // are null by default, since these flags' default value is not parsed by the converter, so
+ // there is no guarantee that there exists an accepted user-input value that would also set
+ // the value to NULL. In these cases, we assume that "unset" is a distinct value that is
+ // always allowed.
+ if (!optionDescription.getOptionDefinition().allowsMultiple()
+ && !optionDescription.getOptionDefinition().isSpecialNullDefault()) {
boolean defaultValueAllowed =
isFlagValueAllowed(
convertedPolicyValues, optionDescription.getOptionDefinition().getDefaultValue());
@@ -749,8 +760,12 @@ public final class InvocationPolicyEnforcer {
throws OptionsParsingException {
OptionDefinition optionDefinition = optionDescription.getOptionDefinition();
- if (!isFlagValueAllowed(
- convertedPolicyValues, optionDescription.getOptionDefinition().getDefaultValue())) {
+ if (optionDefinition.isSpecialNullDefault()) {
+ // Do nothing, the unset value by definition cannot be set. In option filtering operations,
+ // the value is being filtered, but the value that is `no value` passes any filter.
+ // Otherwise, there is no way to "usedefault" on one of these options that has no value by
+ // default.
+ } else if (!isFlagValueAllowed(convertedPolicyValues, optionDefinition.getDefaultValue())) {
if (newValue != null) {
// Use the default value from the policy, since the original default is not allowed
logger.log(