diff --git a/src/main/java/com/google/devtools/build/lib/bazel/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/BUILD index 1a49e15f964b6e..456dd41870a5b0 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/BUILD @@ -123,6 +123,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/util/io", "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/protobuf:failure_details_java_proto", + "//src/main/protobuf:spawn_java_proto", ], ) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java index f0ed66c41d0566..9a762e5d303c51 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/SpawnLogModule.java @@ -23,12 +23,14 @@ import com.google.devtools.build.lib.remote.options.RemoteOptions; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.CommandEnvironment; +import com.google.devtools.build.lib.exec.Protos.SpawnExec; import com.google.devtools.build.lib.server.FailureDetails.Execution; import com.google.devtools.build.lib.server.FailureDetails.Execution.Code; import com.google.devtools.build.lib.server.FailureDetails.FailureDetail; import com.google.devtools.build.lib.util.AbruptExitException; import com.google.devtools.build.lib.util.DetailedExitCode; import com.google.devtools.build.lib.util.io.AsynchronousFileOutputStream; +import com.google.devtools.build.lib.util.io.MessageOutputStream; import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.BinaryOutputStreamWrapper; import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.JsonOutputStreamWrapper; import com.google.devtools.build.lib.util.io.MessageOutputStreamWrapper.MessageOutputStreamCollection; @@ -162,7 +164,11 @@ public void afterCommand() throws AbruptExitException { spawnLogContext.close(); if (!outputStreams.isEmpty()) { InputStream in = rawOutput.getInputStream(); - StableSort.stableSort(in, outputStreams); + if (spawnLogContext.shouldSort()) { + StableSort.stableSort(in, outputStreams); + } else { + ignoreSort(in, outputStreams); + } outputStreams.close(); } done = true; @@ -183,6 +189,12 @@ public void afterCommand() throws AbruptExitException { } } + private void ignoreSort(InputStream in, MessageOutputStream out) throws IOException { + for (SpawnExec ex : StableSort.read(in)) { + out.write(ex); + } + } + private static DetailedExitCode createDetailedExitCode(String message, Code detailedCode) { return DetailedExitCode.of( FailureDetail.newBuilder() diff --git a/src/main/java/com/google/devtools/build/lib/bazel/execlog/StableSort.java b/src/main/java/com/google/devtools/build/lib/bazel/execlog/StableSort.java index fb5a283a82cfca..2950550408cc7c 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/execlog/StableSort.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/execlog/StableSort.java @@ -33,7 +33,7 @@ *
This is needed to allow textual diff comparisons of resultant logs.
*/
public final class StableSort {
- private static ImmutableList