Skip to content

Commit a9b8457

Browse files
calpeyserdamienmg
authored andcommitted
Propogate BAZEL_VERBOSE_FAILURES and BAZEL_SUBCOMMANDS to the execution environments of runtime tools.
-- MOS_MIGRATED_REVID=112149571
1 parent fc2a01b commit a9b8457

5 files changed

Lines changed: 61 additions & 6 deletions

File tree

src/main/java/com/google/devtools/build/lib/analysis/actions/SpawnAction.java

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ void extend(ExtraActionInfo.Builder builder) {
8383

8484
private static final String GUID = "ebd6fce3-093e-45ee-adb6-bf513b602f0d";
8585

86+
private static final String VERBOSE_FAILURES_KEY = "BAZEL_VERBOSE_FAILURES";
87+
private static final String SUBCOMMANDS_KEY = "BAZEL_SUBCOMMANDS";
88+
8689
private final CommandLine argv;
8790

8891
private final boolean executeUnconditionally;
@@ -92,11 +95,13 @@ void extend(ExtraActionInfo.Builder builder) {
9295
private final ImmutableMap<PathFragment, Artifact> inputManifests;
9396

9497
private final ResourceSet resourceSet;
95-
private final ImmutableMap<String, String> environment;
98+
private ImmutableMap<String, String> environment;
9699
private final ImmutableMap<String, String> executionInfo;
97100

98101
private final ExtraActionInfoSupplier<?> extraActionInfoSupplier;
99102

103+
private final boolean verboseFailuresAndSubcommandsInEnv;
104+
100105
/**
101106
* Constructs a SpawnAction using direct initialization arguments.
102107
* <p>
@@ -140,7 +145,8 @@ public SpawnAction(
140145
ImmutableMap.<PathFragment, Artifact>of(),
141146
mnemonic,
142147
false,
143-
null);
148+
null,
149+
false);
144150
}
145151

146152
/**
@@ -165,6 +171,9 @@ public SpawnAction(
165171
* @param inputManifests entries in inputs that are symlink manifest files.
166172
* These are passed to remote execution in the environment rather than as inputs.
167173
* @param mnemonic the mnemonic that is reported in the master log.
174+
* @param verboseFailuresAndSubcommandsInEnv if the presense of "--verbose_failures" and/or
175+
* "--subcommands" in the execution should be propogated to the environment of the
176+
* action.
168177
*/
169178
public SpawnAction(
170179
ActionOwner owner,
@@ -179,7 +188,8 @@ public SpawnAction(
179188
ImmutableMap<PathFragment, Artifact> inputManifests,
180189
String mnemonic,
181190
boolean executeUnconditionally,
182-
ExtraActionInfoSupplier<?> extraActionInfoSupplier) {
191+
ExtraActionInfoSupplier<?> extraActionInfoSupplier,
192+
boolean verboseFailuresAndSubcommandsInEnv) {
183193
super(owner, tools, inputs, outputs);
184194
this.resourceSet = resourceSet;
185195
this.executionInfo = executionInfo;
@@ -190,6 +200,7 @@ public SpawnAction(
190200
this.mnemonic = mnemonic;
191201
this.executeUnconditionally = executeUnconditionally;
192202
this.extraActionInfoSupplier = extraActionInfoSupplier;
203+
this.verboseFailuresAndSubcommandsInEnv = verboseFailuresAndSubcommandsInEnv;
193204
}
194205

195206
/**
@@ -246,6 +257,22 @@ protected void internalExecute(
246257
public void execute(ActionExecutionContext actionExecutionContext)
247258
throws ActionExecutionException, InterruptedException {
248259
Executor executor = actionExecutionContext.getExecutor();
260+
261+
// Reconstruct environment to communicate if verbose_failures and/or subcommands is set.
262+
if (verboseFailuresAndSubcommandsInEnv) {
263+
ImmutableMap.Builder<String, String> environmentBuilder =
264+
new ImmutableMap.Builder<String, String>().putAll(environment);
265+
266+
if (executor.getVerboseFailures()) {
267+
environmentBuilder.put(VERBOSE_FAILURES_KEY, "true");
268+
}
269+
if (executor.reportsSubcommands()) {
270+
environmentBuilder.put(SUBCOMMANDS_KEY, "true");
271+
}
272+
273+
this.environment = environmentBuilder.build();
274+
}
275+
249276
try {
250277
internalExecute(actionExecutionContext);
251278
} catch (ExecException e) {
@@ -356,6 +383,11 @@ public ExtraActionInfo.Builder getExtraActionInfo() {
356383

357384
/**
358385
* Returns the environment in which to run this action.
386+
*
387+
* <p>Note that if setVerboseFailuresAndSubcommandsInEnv() is called on the builder, and either
388+
* verbose_failures or subcommands is specified in the execution context, corresponding variables
389+
* will be added to the environment. These variables will not be known until execution time,
390+
* however, and so are not returned by getEnvironment().
359391
*/
360392
public Map<String, String> getEnvironment() {
361393
return environment;
@@ -464,6 +496,8 @@ public static class Builder {
464496
private String mnemonic = "Unknown";
465497
private ExtraActionInfoSupplier<?> extraActionInfoSupplier = null;
466498

499+
private boolean verboseFailuresAndSubcommandsInEnv = false;
500+
467501
/**
468502
* Creates a SpawnAction builder.
469503
*/
@@ -492,6 +526,7 @@ public Builder(Builder other) {
492526
this.progressMessage = other.progressMessage;
493527
this.paramFileInfo = other.paramFileInfo;
494528
this.mnemonic = other.mnemonic;
529+
this.verboseFailuresAndSubcommandsInEnv = other.verboseFailuresAndSubcommandsInEnv;
495530
}
496531

497532
/**
@@ -578,7 +613,8 @@ public Action[] build(ActionOwner owner, AnalysisEnvironment analysisEnvironment
578613
ImmutableMap.copyOf(inputAndToolManifests),
579614
mnemonic,
580615
executeUnconditionally,
581-
extraActionInfoSupplier));
616+
extraActionInfoSupplier,
617+
verboseFailuresAndSubcommandsInEnv));
582618
return actions.toArray(new Action[actions.size()]);
583619
}
584620

@@ -677,6 +713,17 @@ public Builder useDefaultShellEnvironment() {
677713
return this;
678714
}
679715

716+
/**
717+
* Sets the environment variable "BAZEL_VERBOSE_FAILURES" to "true" if --verbose_failures is
718+
* set in the execution context. Sets the environment variable "BAZEL_SUBCOMMANDS" to "true"
719+
* if --subcommands is set in the execution context.
720+
*
721+
*/
722+
public Builder setVerboseFailuresAndSubcommandsInEnv() {
723+
this.verboseFailuresAndSubcommandsInEnv = true;
724+
return this;
725+
}
726+
680727
/**
681728
* Makes the action always execute, even if none of its inputs have changed.
682729
*

src/main/java/com/google/devtools/build/lib/bazel/rules/genrule/GenRuleAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ public GenRuleAction(
6060
runfilesManifests,
6161
"Genrule",
6262
false,
63-
null);
63+
null,
64+
false);
6465
}
6566

6667
@Override

src/main/java/com/google/devtools/build/lib/rules/extra/ExtraAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ public ExtraAction(
9999
getManifests(shadowedAction),
100100
mnemonic,
101101
false,
102-
null);
102+
null,
103+
false);
103104
this.shadowedAction = shadowedAction;
104105
this.runfilesManifests = ImmutableMap.copyOf(runfilesManifests);
105106
this.createDummyOutput = createDummyOutput;

src/main/java/com/google/devtools/build/lib/rules/objc/BundleSupport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ private void registerInterfaceBuilderActions(ObjcProvider objcProvider) {
242242
// https://github.com/bazelbuild/bazel/issues/285 is fixed.
243243
.addInput(attributes.realpath())
244244
.addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable())
245+
.setVerboseFailuresAndSubcommandsInEnv()
245246
.build(ruleContext));
246247
}
247248
}
@@ -285,6 +286,7 @@ private void registerMomczipActions(ObjcProvider objcProvider) {
285286
// https://github.com/google/bazel/issues/285 is fixed.
286287
.addInput(attributes.realpath())
287288
.addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable())
289+
.setVerboseFailuresAndSubcommandsInEnv()
288290
.setCommandLine(CustomCommandLine.builder()
289291
.addPath(outputZip.getExecPath())
290292
.add(datamodel.archiveRootForMomczip())
@@ -318,6 +320,7 @@ private void registerConvertXibsActions(ObjcProvider objcProvider) {
318320
// https://github.com/bazelbuild/bazel/issues/285 is fixed.
319321
.addInput(attributes.realpath())
320322
.addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable())
323+
.setVerboseFailuresAndSubcommandsInEnv()
321324
.build(ruleContext));
322325
}
323326
}
@@ -372,6 +375,7 @@ private void registerMergeInfoplistAction(
372375
.addInputArgument(plMergeControlArtifact)
373376
.addTransitiveInputs(mergingContentArtifacts)
374377
.addOutput(ObjcRuleClasses.intermediateArtifacts(ruleContext).mergedInfoplist())
378+
.setVerboseFailuresAndSubcommandsInEnv()
375379
.build(ruleContext));
376380
}
377381

@@ -400,6 +404,7 @@ private void registerActoolActionIfNecessary(ObjcProvider objcProvider) {
400404
// https://github.com/google/bazel/issues/285 is fixed.
401405
.addInput(attributes.realpath())
402406
.addInput(CompilationSupport.xcrunwrapper(ruleContext).getExecutable())
407+
.setVerboseFailuresAndSubcommandsInEnv()
403408
.setCommandLine(actoolzipCommandLine(
404409
objcProvider,
405410
zipOutput,

src/main/java/com/google/devtools/build/lib/rules/objc/ReleaseBundlingSupport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,7 @@ private void registerBundleMergeActions(Artifact ipaUnsigned,
747747
.addInputArgument(bundleMergeControlArtifact)
748748
.addTransitiveInputs(bundleContentArtifacts)
749749
.addOutput(ipaUnsigned)
750+
.setVerboseFailuresAndSubcommandsInEnv()
750751
.build(ruleContext));
751752
}
752753

0 commit comments

Comments
 (0)