diff --git a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java index 684b41984511b7..7ff1feb72d8765 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/remote/RemoteSpawnRunner.java @@ -61,7 +61,6 @@ import com.google.devtools.build.lib.remote.common.BulkTransferException; import com.google.devtools.build.lib.remote.common.OperationObserver; import com.google.devtools.build.lib.remote.options.RemoteOptions; -import com.google.devtools.build.lib.remote.options.RemoteOptions.ExecutionMessagePrintMode; import com.google.devtools.build.lib.remote.util.Utils; import com.google.devtools.build.lib.remote.util.Utils.InMemoryOutput; import com.google.devtools.build.lib.sandbox.SandboxHelpers; @@ -273,21 +272,7 @@ public SpawnResult exec(Spawn spawn, SpawnExecutionContext context) // It's already late at this stage, but we should at least report once. reporter.reportExecutingIfNot(); - FileOutErr outErr = context.getFileOutErr(); - String message = result.getMessage(); - boolean printMessage = - ((!result.success() - && remoteOptions.remotePrintExecutionMessages - == ExecutionMessagePrintMode.FAILURE) - || (result.success() - && remoteOptions.remotePrintExecutionMessages - == ExecutionMessagePrintMode.SUCCESS) - || remoteOptions.remotePrintExecutionMessages - == ExecutionMessagePrintMode.ALL) - && !message.isEmpty(); - if (printMessage) { - outErr.printErr(message + "\n"); - } + maybePrintExecutionMessages(context, result.getMessage(), result.success()); profileAccounting(result.getExecutionMetadata()); spawnMetricsAccounting(spawnMetrics, result.getExecutionMetadata()); @@ -458,6 +443,17 @@ public boolean handlesCaching() { return true; } + private void maybePrintExecutionMessages( + SpawnExecutionContext context, String message, boolean success) { + FileOutErr outErr = context.getFileOutErr(); + boolean printMessage = + remoteOptions.remotePrintExecutionMessages.shouldPrintMessages(success) + && !message.isEmpty(); + if (printMessage) { + outErr.printErr(message + "\n"); + } + } + private void maybeWriteParamFilesLocally(Spawn spawn) throws IOException { if (!executionOptions.shouldMaterializeParamFiles()) { return; @@ -514,10 +510,11 @@ private SpawnResult execLocallyAndUploadOrFail( if (remoteOptions.remoteLocalFallback && !RemoteRetrierUtils.causedByExecTimeout(cause)) { return execLocallyAndUpload(action, spawn, context, uploadLocalResults); } - return handleError(action, cause); + return handleError(action, cause, context); } - private SpawnResult handleError(RemoteAction action, IOException exception) + private SpawnResult handleError( + RemoteAction action, IOException exception, SpawnExecutionContext context) throws ExecException, InterruptedException, IOException { boolean remoteCacheFailed = BulkTransferException.isOnlyCausedByCacheNotFoundException(exception); @@ -536,6 +533,7 @@ private SpawnResult handleError(RemoteAction action, IOException exception) } } if (e.isExecutionTimeout()) { + maybePrintExecutionMessages(context, e.getResponse().getMessage(), /* success = */ false); return new SpawnResult.Builder() .setRunnerName(getName()) .setStatus(Status.TIMEOUT) diff --git a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java index 507a221b96cd4a..841df554e66088 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java +++ b/src/main/java/com/google/devtools/build/lib/remote/options/RemoteOptions.java @@ -669,5 +669,11 @@ public Converter() { super(ExecutionMessagePrintMode.class, "execution message print mode"); } } + + public boolean shouldPrintMessages(boolean success) { + return ((!success && this == ExecutionMessagePrintMode.FAILURE) + || (success && this == ExecutionMessagePrintMode.SUCCESS) + || this == ExecutionMessagePrintMode.ALL); + } } }