From c7c25d9bc86cc5565b4f5a32a08a0ff22a6aa95d Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Mon, 31 Aug 2015 16:30:17 +0000 Subject: Send the output of spawns ran in worker processes to the outErr of the execution context instead of printing it to System.err. -- MOS_MIGRATED_REVID=101941516 --- .../devtools/build/lib/worker/WorkerSpawnStrategy.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java index d696fc988f..8fb7ef29a6 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnStrategy.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.SpawnActionContext; import com.google.devtools.build.lib.actions.UserExecException; import com.google.devtools.build.lib.concurrent.ThreadSafety; +import com.google.devtools.build.lib.util.io.FileOutErr; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.worker.WorkerProtocol.WorkRequest; import com.google.devtools.build.lib.worker.WorkerProtocol.WorkResponse; @@ -78,6 +79,8 @@ final class WorkerSpawnStrategy implements SpawnActionContext { false, "Must have parameter file as last arg, got args: " + spawn.getArguments()); } + FileOutErr outErr = actionExecutionContext.getFileOutErr(); + ImmutableList args = ImmutableList.builder() .addAll(spawn.getArguments().subList(0, spawn.getArguments().size() - 1)) .add("--persistent_worker") @@ -98,17 +101,19 @@ final class WorkerSpawnStrategy implements SpawnActionContext { WorkResponse response = WorkResponse.parseDelimitedFrom(worker.getInputStream()); if (response == null) { - throw new UserExecException("Worker did not return a correct WorkResponse"); + throw new UserExecException( + "Worker process did not return a correct WorkResponse. This is probably caused by a " + + "bug in the worker, writing unexpected other data to stdout."); } String trimmedOutput = response.getOutput().trim(); if (!trimmedOutput.isEmpty()) { - System.err.println(trimmedOutput); + outErr.getErrorStream().write(trimmedOutput.getBytes()); } if (response.getExitCode() != 0) { - throw new UserExecException(String.format("Failed with exit code: %d.", - response.getExitCode())); + throw new UserExecException( + String.format("Worker process failed with exit code: %d.", response.getExitCode())); } } finally { if (worker != null) { -- cgit v1.2.3