diff options
author | Cal Peyser <cpeyser@google.com> | 2016-01-14 15:28:36 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-01-15 09:22:18 +0000 |
commit | a9b84575a32476a5faf991da22b44661d75c19b6 (patch) | |
tree | 080572fe2495f64211b8e6ca71f756e4ea45ddbe | |
parent | fc2a01bcedaf85c2a4fd7675f80e877203cc57cb (diff) |
Propogate BAZEL_VERBOSE_FAILURES and BAZEL_SUBCOMMANDS to the execution environments of runtime tools.
--
MOS_MIGRATED_REVID=112149571
5 files changed, 61 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java index 84619f329d..48e56c88da 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java @@ -83,6 +83,9 @@ public class SpawnAction extends AbstractAction { private static final String GUID = "ebd6fce3-093e-45ee-adb6-bf513b602f0d"; + private static final String VERBOSE_FAILURES_KEY = "BAZEL_VERBOSE_FAILURES"; + private static final String SUBCOMMANDS_KEY = "BAZEL_SUBCOMMANDS"; + private final CommandLine argv; private final boolean executeUnconditionally; @@ -92,11 +95,13 @@ public class SpawnAction extends AbstractAction { private final ImmutableMap<PathFragment, Artifact> inputManifests; private final ResourceSet resourceSet; - private final ImmutableMap<String, String> environment; + private ImmutableMap<String, String> environment; private final ImmutableMap<String, String> executionInfo; private final ExtraActionInfoSupplier<?> extraActionInfoSupplier; + private final boolean verboseFailuresAndSubcommandsInEnv; + /** * Constructs a SpawnAction using direct initialization arguments. * <p> @@ -140,7 +145,8 @@ public class SpawnAction extends AbstractAction { ImmutableMap.<PathFragment, Artifact>of(), mnemonic, false, - null); + null, + false); } /** @@ -165,6 +171,9 @@ public class SpawnAction extends AbstractAction { * @param inputManifests entries in inputs that are symlink manifest files. * These are passed to remote execution in the environment rather than as inputs. * @param mnemonic the mnemonic that is reported in the master log. + * @param verboseFailuresAndSubcommandsInEnv if the presense of "--verbose_failures" and/or + * "--subcommands" in the execution should be propogated to the environment of the + * action. */ public SpawnAction( ActionOwner owner, @@ -179,7 +188,8 @@ public class SpawnAction extends AbstractAction { ImmutableMap<PathFragment, Artifact> inputManifests, String mnemonic, boolean executeUnconditionally, - ExtraActionInfoSupplier<?> extraActionInfoSupplier) { + ExtraActionInfoSupplier<?> extraActionInfoSupplier, + boolean verboseFailuresAndSubcommandsInEnv) { super(owner, tools, inputs, outputs); this.resourceSet = resourceSet; this.executionInfo = executionInfo; @@ -190,6 +200,7 @@ public class SpawnAction extends AbstractAction { this.mnemonic = mnemonic; this.executeUnconditionally = executeUnconditionally; this.extraActionInfoSupplier = extraActionInfoSupplier; + this.verboseFailuresAndSubcommandsInEnv = verboseFailuresAndSubcommandsInEnv; } /** @@ -246,6 +257,22 @@ public class SpawnAction extends AbstractAction { public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException { Executor executor = actionExecutionContext.getExecutor(); + + // Reconstruct environment to communicate if verbose_failures and/or subcommands is set. + if (verboseFailuresAndSubcommandsInEnv) { + ImmutableMap.Builder<String, String> environmentBuilder = + new ImmutableMap.Builder<String, String>().putAll(environment); + + if (executor.getVerboseFailures()) { + environmentBuilder.put(VERBOSE_FAILURES_KEY, "true"); + } + if (executor.reportsSubcommands()) { + environmentBuilder.put(SUBCOMMANDS_KEY, "true"); + } + + this.environment = environmentBuilder.build(); + } + try { internalExecute(actionExecutionContext); } catch (ExecException e) { @@ -356,6 +383,11 @@ public class SpawnAction extends AbstractAction { /** * Returns the environment in which to run this action. + * + * <p>Note that if setVerboseFailuresAndSubcommandsInEnv() is called on the builder, and either + * verbose_failures or subcommands is specified in the execution context, corresponding variables + * will be added to the environment. These variables will not be known until execution time, + * however, and so are not returned by getEnvironment(). */ public Map<String, String> getEnvironment() { return environment; @@ -464,6 +496,8 @@ public class SpawnAction extends AbstractAction { private String mnemonic = "Unknown"; private ExtraActionInfoSupplier<?> extraActionInfoSupplier = null; + private boolean verboseFailuresAndSubcommandsInEnv = false; + /** * Creates a SpawnAction builder. */ @@ -492,6 +526,7 @@ public class SpawnAction extends AbstractAction { this.progressMessage = other.progressMessage; this.paramFileInfo = other.paramFileInfo; this.mnemonic = other.mnemonic; + this.verboseFailuresAndSubcommandsInEnv = other.verboseFailuresAndSubcommandsInEnv; } /** @@ -578,7 +613,8 @@ public class SpawnAction extends AbstractAction { ImmutableMap.copyOf(inputAndToolManifests), mnemonic, executeUnconditionally, - extraActionInfoSupplier)); + extraActionInfoSupplier, + verboseFailuresAndSubcommandsInEnv)); return actions.toArray(new Action[actions.size()]); } @@ -678,6 +714,17 @@ public class SpawnAction extends AbstractAction { } /** + * Sets the environment variable "BAZEL_VERBOSE_FAILURES" to "true" if --verbose_failures is + * set in the execution context. Sets the environment variable "BAZEL_SUBCOMMANDS" to "true" + * if --subcommands is set in the execution context. + * + */ + public Builder setVerboseFailuresAndSubcommandsInEnv() { + this.verboseFailuresAndSubcommandsInEnv = true; + return this; + } + + /** * Makes the action always execute, even if none of its inputs have changed. * * <p>Only use this when absolutely necessary, since this is a performance hit and we'd like to diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRuleAction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRuleAction.java index 7481cdcadc..6d4d63492e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRuleAction.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRuleAction.java @@ -60,7 +60,8 @@ public final class GenRuleAction extends SpawnAction { runfilesManifests, "Genrule", false, - null); + null, + false); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraAction.java b/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraAction.java index 2b8c618752..88e51e8a03 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/extra/ExtraAction.java @@ -99,7 +99,8 @@ public final class ExtraAction extends SpawnAction { getManifests(shadowedAction), mnemonic, false, - null); + null, + false); this.shadowedAction = shadowedAction; this.runfilesManifests = ImmutableMap.copyOf(runfilesManifests); this.createDummyOutput = createDummyOutput; diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java index 70c53d131f..d2c72394d9 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java @@ -242,6 +242,7 @@ final class BundleSupport { // https://github.com/bazelbuild/bazel/issues/285 is fixed. .addInput(attributes.realpath()) .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) + .setVerboseFailuresAndSubcommandsInEnv() .build(ruleContext)); } } @@ -285,6 +286,7 @@ final class BundleSupport { // https://github.com/google/bazel/issues/285 is fixed. .addInput(attributes.realpath()) .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) + .setVerboseFailuresAndSubcommandsInEnv() .setCommandLine(CustomCommandLine.builder() .addPath(outputZip.getExecPath()) .add(datamodel.archiveRootForMomczip()) @@ -318,6 +320,7 @@ final class BundleSupport { // https://github.com/bazelbuild/bazel/issues/285 is fixed. .addInput(attributes.realpath()) .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) + .setVerboseFailuresAndSubcommandsInEnv() .build(ruleContext)); } } @@ -372,6 +375,7 @@ final class BundleSupport { .addInputArgument(plMergeControlArtifact) .addTransitiveInputs(mergingContentArtifacts) .addOutput(ObjcRuleClasses.intermediateArtifacts(ruleContext).mergedInfoplist()) + .setVerboseFailuresAndSubcommandsInEnv() .build(ruleContext)); } @@ -400,6 +404,7 @@ final class BundleSupport { // https://github.com/google/bazel/issues/285 is fixed. .addInput(attributes.realpath()) .addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable()) + .setVerboseFailuresAndSubcommandsInEnv() .setCommandLine(actoolzipCommandLine( objcProvider, zipOutput, diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java index 36e25ca455..f00b6f2cd1 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java @@ -747,6 +747,7 @@ public final class ReleaseBundlingSupport { .addInputArgument(bundleMergeControlArtifact) .addTransitiveInputs(bundleContentArtifacts) .addOutput(ipaUnsigned) + .setVerboseFailuresAndSubcommandsInEnv() .build(ruleContext)); } |