aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/util
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-09-26 14:42:31 -0400
committerGravatar John Cater <jcater@google.com>2017-09-27 10:01:09 -0400
commit659feca7dee332f75801010b018505b7ba5a185e (patch)
tree183cbd7b3a1ad10939c3a23d05033ce176c311d2 /src/main/java/com/google/devtools/build/lib/util
parent5b98fb43ecaa6a9343ba4aa649f74193f0cf0956 (diff)
Move the canonicalization of an option value to the option value itself.
Ideally, the canonical form we output from OptionUtils would be the same as for the command canonicalize-flags, but that must wait for dependencies to be cleaned up. Still, in the meantime, keep the --foo=1 normalization of --foo, and apply it to all other boolean flag values (t,true,yes,y, and false equivalents), so that the canoncalize-flags output is more canonical, even if it isn't using the --[no]foo form yet. RELNOTES: Boolean flag values will now get normalized to 1 or 0 in canonicalize-flags output. PiperOrigin-RevId: 170084599
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/util')
-rw-r--r--src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java37
1 files changed, 2 insertions, 35 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java b/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java
index bae41d869f..c94863ed86 100644
--- a/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/util/OptionsUtils.java
@@ -17,8 +17,6 @@ package com.google.devtools.build.lib.util;
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.common.options.Converter;
-import com.google.devtools.common.options.Converters;
-import com.google.devtools.common.options.OptionsParsingException;
import com.google.devtools.common.options.OptionsProvider;
import com.google.devtools.common.options.ParsedOptionDescription;
import java.util.ArrayList;
@@ -43,23 +41,7 @@ public final class OptionsUtils {
if (result.length() != 0) {
result.append(' ');
}
- String value = option.getUnconvertedValue();
- if (option.isBooleanOption()) {
- boolean isEnabled = false;
- try {
- isEnabled = new Converters.BooleanConverter().convert(value);
- } catch (OptionsParsingException e) {
- throw new RuntimeException("Unexpected parsing exception", e);
- }
- result
- .append(isEnabled ? "--" : "--no")
- .append(option.getOptionDefinition().getOptionName());
- } else {
- result.append("--").append(option.getOptionDefinition().getOptionName());
- if (value != null) { // Can be null for Void options.
- result.append("=").append(ShellEscaper.escapeString(value));
- }
- }
+ result.append(option.getCanonicalFormWithValueEscaper(ShellEscaper::escapeString));
}
return result.toString();
}
@@ -82,22 +64,7 @@ public final class OptionsUtils {
if (option.isHidden()) {
continue;
}
- String value = option.getUnconvertedValue();
- if (option.isBooleanOption()) {
- boolean isEnabled = false;
- try {
- isEnabled = new Converters.BooleanConverter().convert(value);
- } catch (OptionsParsingException e) {
- throw new RuntimeException("Unexpected parsing exception", e);
- }
- builder.add((isEnabled ? "--" : "--no") + option.getOptionDefinition().getOptionName());
- } else {
- String optionString = "--" + option.getOptionDefinition().getOptionName();
- if (value != null) { // Can be null for Void options.
- optionString += "=" + value;
- }
- builder.add(optionString);
- }
+ builder.add(option.getCanonicalForm());
}
return builder.build();
}