diff options
author | 2018-07-26 13:37:45 -0700 | |
---|---|---|
committer | 2018-07-26 13:39:20 -0700 | |
commit | be31bb8527a93659fb7540d8f4fc087e3b60411c (patch) | |
tree | caba5cc9f1977677260e383fa813fcfd052dda51 /src/main/java/com/google/devtools/build/lib/actions | |
parent | cd91d1c3b031d18daf63f8cc05c5155c654b1759 (diff) |
Modify --subcommands to allow pretty printing the arguments of a subcommand
as a list, rather than as a single line (i.e., newline delimited rather than
space delimited).
Before:
SUBCOMMAND: # //src/main/java/com/google/devtools/build/lib:string_util [action 'Building src/main/java/com/google/devtools/build/lib/libstring_util.jar (2 source files) [for host]']
(cd /tmp/devbazel_output_base/execroot/io_bazel && \
exec env - \
LC_CTYPE=en_US.UTF-8 \
external/embedded_jdk/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--patch-module=java.compiler=external/bazel_tools/third_party/java/jdk/langtools/java_compiler.jar' '--patch-module=jdk.compiler=external/bazel_tools/third_party/java/jdk/langtools/jdk_compiler.jar' '--add-opens=java.base/java.nio=ALL-UNNAMED' -jar external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar @bazel-out/host/bin/src/main/java/com/google/devtools/build/lib/libstring_util.jar-2.params)
After:
SUBCOMMAND: # //src/main/java/com/google/devtools/build/lib:string_util [action 'Building src/main/java/com/google/devtools/build/lib/libstring_util.jar (2 source files) [for host]']
(cd /tmp/devbazel_output_base/execroot/io_bazel && \
exec env - \
LC_CTYPE=en_US.UTF-8 \
external/embedded_jdk/bin/java \
-XX:+UseParallelOldGC \
-XX:-CompactStrings \
'--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' \
'--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' \
'--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' \
'--patch-module=java.compiler=external/bazel_tools/third_party/java/jdk/langtools/java_compiler.jar' \
'--patch-module=jdk.compiler=external/bazel_tools/third_party/java/jdk/langtools/jdk_compiler.jar' \
'--add-opens=java.base/java.nio=ALL-UNNAMED' \
-jar \
external/bazel_tools/tools/jdk/JavaBuilder_deploy.jar \
@bazel-out/host/bin/src/main/java/com/google/devtools/build/lib/libstring_util.jar-2.params)
RELNOTES: --subcommands can now take a "pretty_print" value ("--subcommands=pretty_print") to print the
arguments of subcommands as a list for easier reading.
PiperOrigin-RevId: 206213009
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/actions')
3 files changed, 38 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java index 2cea7155d4..037f47b1ad 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutionContext.java @@ -43,6 +43,19 @@ import javax.annotation.Nullable; */ public class ActionExecutionContext implements Closeable { + /** Enum for --subcommands flag */ + public enum ShowSubcommands { + TRUE(true, false), PRETTY_PRINT(true, true), FALSE(false, false); + + private final boolean shouldShowSubcommands; + private final boolean prettyPrintArgs; + + private ShowSubcommands(boolean shouldShowSubcommands, boolean prettyPrintArgs) { + this.shouldShowSubcommands = shouldShowSubcommands; + this.prettyPrintArgs = prettyPrintArgs; + } + } + private final Executor executor; private final MetadataProvider actionInputFileCache; private final ActionInputPrefetcher actionInputPrefetcher; @@ -236,19 +249,15 @@ public class ActionExecutionContext implements Closeable { } /** - * Whether this Executor reports subcommands. If not, reportSubcommand has no effect. - * This is provided so the caller of reportSubcommand can avoid wastefully constructing the - * subcommand string. - */ - public boolean reportsSubcommands() { - return executor.reportsSubcommands(); - } - - /** * Report a subcommand event to this Executor's Reporter and, if action * logging is enabled, post it on its EventBus. */ - public void reportSubcommand(Spawn spawn) { + public void maybeReportSubcommand(Spawn spawn) { + ShowSubcommands showSubcommands = executor.reportsSubcommands(); + if (!showSubcommands.shouldShowSubcommands) { + return; + } + String reason; ActionOwner owner = spawn.getResourceOwner().getOwner(); if (owner == null) { @@ -257,7 +266,7 @@ public class ActionExecutionContext implements Closeable { reason = Label.print(owner.getLabel()) + " [" + spawn.getResourceOwner().prettyPrint() + "]"; } - String message = Spawns.asShellCommand(spawn, getExecRoot()); + String message = Spawns.asShellCommand(spawn, getExecRoot(), showSubcommands.prettyPrintArgs); getEventHandler().handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message)); } diff --git a/src/main/java/com/google/devtools/build/lib/actions/Executor.java b/src/main/java/com/google/devtools/build/lib/actions/Executor.java index a2de3d6a78..2c90014454 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Executor.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Executor.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.actions; import com.google.common.eventbus.EventBus; +import com.google.devtools.build.lib.actions.ActionExecutionContext.ShowSubcommands; import com.google.devtools.build.lib.clock.Clock; import com.google.devtools.build.lib.events.ExtendedEventHandler; import com.google.devtools.build.lib.vfs.FileSystem; @@ -74,7 +75,7 @@ public interface Executor { * This is provided so the caller of reportSubcommand can avoid wastefully constructing the * subcommand string. */ - boolean reportsSubcommands(); + ShowSubcommands reportsSubcommands(); /** * An event listener to report messages to. Errors that signal a action failure should use diff --git a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java index 3174d5b112..0ca66b71c2 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/Spawns.java +++ b/src/main/java/com/google/devtools/build/lib/actions/Spawns.java @@ -89,17 +89,29 @@ public final class Spawns { } /** Convert a spawn into a Bourne shell command. */ - public static String asShellCommand(Spawn spawn, Path workingDirectory) { - return asShellCommand(spawn.getArguments(), workingDirectory, spawn.getEnvironment()); + public static String asShellCommand(Spawn spawn, Path workingDirectory, boolean prettyPrintArgs) { + return asShellCommand( + spawn.getArguments(), + workingDirectory, + spawn.getEnvironment(), + prettyPrintArgs); } /** Convert a working dir + environment map + arg list into a Bourne shell command. */ public static String asShellCommand( - Collection<String> arguments, Path workingDirectory, Map<String, String> environment) { + Collection<String> arguments, + Path workingDirectory, + Map<String, String> environment, + boolean prettyPrintArgs) { + // We print this command out in such a way that it can safely be // copied+pasted as a Bourne shell command. This is extremely valuable for // debugging. return CommandFailureUtils.describeCommand( - CommandDescriptionForm.COMPLETE, arguments, environment, workingDirectory.getPathString()); + CommandDescriptionForm.COMPLETE, + prettyPrintArgs, + arguments, + environment, + workingDirectory.getPathString()); } } |