aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/common/options/OptionsParser.java
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-12-21 14:17:10 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-21 14:20:23 -0800
commit0421d7d8566a6fbe35e17a1edc3ab4d622aa6c9e (patch)
treecdd56cfd0361aabc0d960a3306f992f109e7d1fe /src/main/java/com/google/devtools/common/options/OptionsParser.java
parentcc99efdc6bec68979334345175e18066249e78e8 (diff)
Warn about config expansions as we do for other expansions.
If an expanded value overrides an explicit value, users who do not know the contents of the expansion may be surprised. We already warned about this for hard-coded expansions, and this is now applicable for --config expansions as well. This will only warn when a single-valued option has its value replaced. Options that accumulate multiple values in a list (e.g., --copt) will silently include both explicit and expanded values. RELNOTES: None. PiperOrigin-RevId: 179857526
Diffstat (limited to 'src/main/java/com/google/devtools/common/options/OptionsParser.java')
-rw-r--r--src/main/java/com/google/devtools/common/options/OptionsParser.java23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/common/options/OptionsParser.java b/src/main/java/com/google/devtools/common/options/OptionsParser.java
index fb7161ca46..b7da00466e 100644
--- a/src/main/java/com/google/devtools/common/options/OptionsParser.java
+++ b/src/main/java/com/google/devtools/common/options/OptionsParser.java
@@ -619,13 +619,26 @@ public class OptionsParser implements OptionsProvider {
}
}
- public void parseOptionsFixedAtSpecificPriority(
- OptionPriority priority, String source, List<String> args) throws OptionsParsingException {
- Preconditions.checkNotNull(priority, "Priority not specified for arglist " + args);
+ /**
+ * Parses the args at the priority of the provided option. This is useful for after-the-fact
+ * expansion.
+ *
+ * @param optionToExpand the option that is being "expanded" after the fact. The provided args
+ * will have the same priority as this option.
+ * @param source a description of where the expansion arguments came from.
+ * @param args the arguments to parse as the expansion. Order matters, as the value of a flag may
+ * be in the following argument.
+ */
+ public void parseArgsFixedAsExpansionOfOption(
+ ParsedOptionDescription optionToExpand, String source, List<String> args)
+ throws OptionsParsingException {
+ Preconditions.checkNotNull(
+ optionToExpand, "Option for expansion not specified for arglist " + args);
Preconditions.checkArgument(
- priority.getPriorityCategory() != OptionPriority.PriorityCategory.DEFAULT,
+ optionToExpand.getPriority().getPriorityCategory()
+ != OptionPriority.PriorityCategory.DEFAULT,
"Priority cannot be default, which was specified for arglist " + args);
- residue.addAll(impl.parseOptionsFixedAtSpecificPriority(priority, o -> source, args));
+ residue.addAll(impl.parseArgsFixedAsExpansionOfOption(optionToExpand, o -> source, args));
if (!allowResidue && !residue.isEmpty()) {
String errorMsg = "Unrecognized arguments: " + Joiner.on(' ').join(residue);
throw new OptionsParsingException(errorMsg);