diff options
author | 2017-04-06 22:11:05 +0000 | |
---|---|---|
committer | 2017-04-07 11:17:42 +0200 | |
commit | 681f433545a22c8169bed8643fee560f3b500607 (patch) | |
tree | f19e32a153664c4c67644b59cba3bd9bc64cdfdf /src/main/java/com/google/devtools | |
parent | 0ddda7899d8be0420130f5b963510434e35b7197 (diff) |
Remove --no_ support.
--no_ prefixes for boolean flags are deprecated. Error out nicely if --no_ is supplied.
PiperOrigin-RevId: 152434290
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java | 7 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/common/options/OptionsParserImpl.java | 18 |
2 files changed, 16 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java b/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java index 5074b99bf5..084daaddc8 100644 --- a/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java +++ b/src/main/java/com/google/devtools/common/options/IsolatedOptionsData.java @@ -294,13 +294,10 @@ public class IsolatedOptionsData extends OpaqueOptionsData { Map<String, Field> nameToFieldMap, Map<String, String> booleanAliasMap, String optionName) { - // Check that the two aliases do not conflict with existing flags. - checkForCollisions(nameToFieldMap, "no_" + optionName, "boolean option alias"); + // Check that the negating alias does not conflict with existing flags. checkForCollisions(nameToFieldMap, "no" + optionName, "boolean option alias"); - // Record that the boolean option takes up additional namespace for its two negating - // aliases. - booleanAliasMap.put("no_" + optionName, optionName); + // Record that the boolean option takes up additional namespace for its negating alias. booleanAliasMap.put("no" + optionName, optionName); } diff --git a/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java b/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java index fd3a8cea13..8394d07c2e 100644 --- a/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java +++ b/src/main/java/com/google/devtools/common/options/OptionsParserImpl.java @@ -641,11 +641,21 @@ class OptionsParserImpl { value = equalsAt == -1 ? null : arg.substring(equalsAt + 1); field = optionsData.getFieldFromName(name); - // Look for a "no"-prefixed option name: "no<optionName>" or "no_<optionName>". - // Note: It is impossible to specify "--no_foo" for a flag named "--_foo", since that'll be - // interpreted as the "no_" negating prefix for "--foo". + // Look for a "no"-prefixed option name: "no<optionName>". if (field == null && name.startsWith("no")) { - name = name.substring(name.startsWith("no_") ? 3 : 2); + // Give a nice error if someone is using the deprecated --no_ prefix. + // Note: With this check in place, is impossible to specify "--no_foo" for a flag named + // "--_foo", if a --foo flag also exists, since that'll be interpreted as the "no_" + // negating prefix for "--foo". Let that be a warning to anyone wanting to make flags that + // start with underscores. + // TODO(Bazel-team): Remove the --no_ check when sufficient time has passed for users of + // that feature to have stopped using it. + if (name.startsWith("no_") && optionsData.getFieldFromName(name.substring(3)) != null) { + throw new OptionsParsingException( + "'no_' prefixes are no longer accepted, --no<flag> is an accepted alternative.", + name.substring(3)); + } + name = name.substring(2); field = optionsData.getFieldFromName(name); booleanValue = false; if (field != null) { |