aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2017-04-15 00:40:50 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-04-18 11:28:19 +0200
commitc52d73e9a76989e483d2998250a132e8d5e10098 (patch)
tree921a36e4ca8f126d082482a6bbc16c94918b1f69 /src/main/java
parent0334cd446bb2fde1a6ee53525d463abd8bab2631 (diff)
Canonicalize-flags can now show the canonical invocation policy.
Canonicalize-flags will provide the expanded and filtered version of the policy passed to it as a command argument if also passed the command arg --canonicalize_policy. This is the version that would be actually applied to the command line in another command. In this mode, it will not also print out the interpretation of the flags passed after "--", so to get both outputs, it will have to be run twice. This was to keep the output clean and easy to parse. RELNOTES: new option for bazel canonicalize-flags, --canonicalize_policy PiperOrigin-RevId: 153215518
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/flags/InvocationPolicyEnforcer.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java35
2 files changed, 30 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/flags/InvocationPolicyEnforcer.java b/src/main/java/com/google/devtools/build/lib/flags/InvocationPolicyEnforcer.java
index a01ecd7077..6bd7da088a 100644
--- a/src/main/java/com/google/devtools/build/lib/flags/InvocationPolicyEnforcer.java
+++ b/src/main/java/com/google/devtools/build/lib/flags/InvocationPolicyEnforcer.java
@@ -193,7 +193,7 @@ public final class InvocationPolicyEnforcer {
*
* <p>Expands any policies on expansion flags.
*/
- private static List<FlagPolicy> getEffectivePolicy(
+ public static List<FlagPolicy> getEffectivePolicy(
InvocationPolicy invocationPolicy, OptionsParser parser) throws OptionsParsingException {
if (invocationPolicy == null) {
return ImmutableList.of();
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
index ee43018010..01519a54a1 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java
@@ -23,6 +23,8 @@ import com.google.devtools.build.lib.runtime.BlazeCommandUtils;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.CommandEnvironment;
+import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.FlagPolicy;
+import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;
@@ -62,6 +64,16 @@ public final class CanonicalizeCommand implements BlazeCommand {
public String invocationPolicy;
@Option(
+ name = "canonicalize_policy",
+ defaultValue = "false",
+ help =
+ "Output the canonical policy, after expansion and filtering. To keep the output "
+ + "clean, the canonicalized command arguments will NOT be shown when this option is "
+ + "set to true."
+ )
+ public boolean canonicalizePolicy;
+
+ @Option(
name = "show_warnings",
defaultValue = "false",
help = "Output parser warnings to standard error (e.g. for conflicting flag options)."
@@ -117,9 +129,9 @@ public final class CanonicalizeCommand implements BlazeCommand {
parser.setAllowResidue(false);
parser.parse(options.getResidue());
- InvocationPolicyEnforcer invocationPolicyEnforcer =
- new InvocationPolicyEnforcer(
- InvocationPolicyParser.parsePolicy(canonicalizeOptions.invocationPolicy));
+ InvocationPolicy policy =
+ InvocationPolicyParser.parsePolicy(canonicalizeOptions.invocationPolicy);
+ InvocationPolicyEnforcer invocationPolicyEnforcer = new InvocationPolicyEnforcer(policy);
invocationPolicyEnforcer.enforce(parser, commandName);
if (canonicalizeOptions.showWarnings) {
@@ -128,9 +140,20 @@ public final class CanonicalizeCommand implements BlazeCommand {
}
}
- List<String> result = parser.canonicalize();
- for (String piece : result) {
- env.getReporter().getOutErr().printOutLn(piece);
+ // Print out the canonical invocation policy if requested.
+ if (canonicalizeOptions.canonicalizePolicy) {
+ List<FlagPolicy> effectiveFlagPolicies =
+ InvocationPolicyEnforcer.getEffectivePolicy(policy, parser);
+ InvocationPolicy effectivePolicy =
+ InvocationPolicy.newBuilder().addAllFlagPolicies(effectiveFlagPolicies).build();
+ env.getReporter().getOutErr().printOutLn(effectivePolicy.toString());
+
+ } else {
+ // Otherwise, print out the canonical command line
+ List<String> result = parser.canonicalize();
+ for (String piece : result) {
+ env.getReporter().getOutErr().printOutLn(piece);
+ }
}
} catch (OptionsParsingException e) {
env.getReporter().handle(Event.error(e.getMessage()));