diff options
author | ahumesky <ahumesky@google.com> | 2018-07-26 13:37:45 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-07-26 13:39:20 -0700 |
commit | be31bb8527a93659fb7540d8f4fc087e3b60411c (patch) | |
tree | caba5cc9f1977677260e383fa813fcfd052dda51 /src/main/java/com/google/devtools/build/lib/util | |
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/util')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java b/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java index dad0d72db6..5317e818c9 100644 --- a/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java +++ b/src/main/java/com/google/devtools/build/lib/util/CommandFailureUtils.java @@ -139,17 +139,23 @@ public class CommandFailureUtils { * @param form Form of the command to generate; see the documentation of the * {@link CommandDescriptionForm} values. */ - public static String describeCommand(CommandDescriptionForm form, + public static String describeCommand( + CommandDescriptionForm form, + boolean prettyPrintArgs, Collection<String> commandLineElements, - @Nullable Map<String, String> environment, @Nullable String cwd) { + @Nullable Map<String, String> environment, + @Nullable String cwd) { + Preconditions.checkNotNull(form); final int APPROXIMATE_MAXIMUM_MESSAGE_LENGTH = 200; StringBuilder message = new StringBuilder(); int size = commandLineElements.size(); int numberRemaining = size; + if (form == CommandDescriptionForm.COMPLETE) { describeCommandImpl.describeCommandBeginIsolate(message); } + if (form != CommandDescriptionForm.ABBREVIATED) { if (cwd != null) { describeCommandImpl.describeCommandCwd(cwd, message); @@ -195,6 +201,7 @@ public class CommandFailureUtils { } } } + for (String commandElement : commandLineElements) { if (form == CommandDescriptionForm.ABBREVIATED && message.length() + commandElement.length() > APPROXIMATE_MAXIMUM_MESSAGE_LENGTH) { @@ -203,15 +210,17 @@ public class CommandFailureUtils { break; } else { if (numberRemaining < size) { - message.append(' '); + message.append(prettyPrintArgs ? " \\\n " : " "); } describeCommandImpl.describeCommandElement(message, commandElement); numberRemaining--; } } + if (form == CommandDescriptionForm.COMPLETE) { describeCommandImpl.describeCommandEndIsolate(message); } + return message.toString(); } @@ -220,14 +229,17 @@ public class CommandFailureUtils { * Currently this returns a message of the form "error executing command foo * bar baz". */ - public static String describeCommandError(boolean verbose, - Collection<String> commandLineElements, - Map<String, String> env, String cwd) { + public static String describeCommandError( + boolean verbose, + Collection<String> commandLineElements, + Map<String, String> env, + String cwd) { + CommandDescriptionForm form = verbose ? CommandDescriptionForm.COMPLETE : CommandDescriptionForm.ABBREVIATED; return "error executing command " + (verbose ? "\n " : "") - + describeCommand(form, commandLineElements, env, cwd); + + describeCommand(form, /* prettyPrintArgs= */false, commandLineElements, env, cwd); } /** @@ -235,9 +247,12 @@ public class CommandFailureUtils { * Currently this returns a message of the form "foo failed: error executing * command /dir/foo bar baz". */ - public static String describeCommandFailure(boolean verbose, - Collection<String> commandLineElements, - Map<String, String> env, String cwd) { + public static String describeCommandFailure( + boolean verbose, + Collection<String> commandLineElements, + Map<String, String> env, + String cwd) { + String commandName = commandLineElements.iterator().next(); // Extract the part of the command name after the last "/", if any. String shortCommandName = new File(commandName).getName(); |