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 read(InputStream in) throws IOException { + public static ImmutableList read(InputStream in) throws IOException { ImmutableList.Builder result = ImmutableList.builder(); while (in.available() > 0) { SpawnExec ex = SpawnExec.parseDelimitedFrom(in); diff --git a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java index 9515288e95316d..aa90067e0d0dbf 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java +++ b/src/main/java/com/google/devtools/build/lib/exec/ExecutionOptions.java @@ -472,6 +472,17 @@ public boolean usingLocalTestJobs() { + " --subcommands (for displaying subcommands in terminal output).") public PathFragment executionLogJsonFile; + @Option( + name = "execution_log_sort", + defaultValue = "true", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + help = + "Whether to sort the execution log. Set to false to improve memory" + + " performance, at the cost of producing the log in nondeterministic" + + " order.") + public boolean executionLogSort; + @Option( name = "experimental_split_xml_generation", defaultValue = "true", diff --git a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java index b9efde8bd03ef1..186b8446900cfd 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SpawnLogContext.java @@ -332,4 +332,8 @@ private Digest computeDigest( .setSizeBytes(fileSize) .build(); } + + public boolean shouldSort() { + return executionOptions.executionLogSort; + } }