diff options
author | 2017-11-09 22:26:01 +0100 | |
---|---|---|
committer | 2017-11-10 23:27:28 +0100 | |
commit | 4815f17763c362b8075fd8c87d1a754180be24eb (patch) | |
tree | a130c20e858dfbfba476cfd28c69bfe59761fbe2 | |
parent | af9d6cb3e818f2fb5b080922f3b22fb3d6d98d9d (diff) |
BEP: add commandline for reported actions
The build event protocol reports certain actions that are particularly
important to the user, in particular failed ones. Also report the precise
command line of those actions, if available. This is useful for IDEs
wanting to report errors in a more precise way.
Change-Id: I04224185ea46c608ad0dfcdb2e772071ca0736b3
PiperOrigin-RevId: 175203502
3 files changed, 17 insertions, 1 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java index 0bd2e5daab..3a5bb8d96f 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionExecutedEvent.java @@ -27,12 +27,16 @@ import com.google.devtools.build.lib.buildeventstream.NullConfiguration; import com.google.devtools.build.lib.buildeventstream.PathConverter; import com.google.devtools.build.lib.vfs.Path; import java.util.Collection; +import java.util.logging.Level; +import java.util.logging.Logger; /** * This event is fired during the build, when an action is executed. It contains information about * the action: the Action itself, and the output file names its stdout and stderr are recorded in. */ public class ActionExecutedEvent implements BuildEventWithConfiguration { + private static final Logger logger = Logger.getLogger(ActionExecutedEvent.class.getName()); + private final Action action; private final ActionExecutionException exception; private final Path stdout; @@ -152,6 +156,14 @@ public class ActionExecutedEvent implements BuildEventWithConfiguration { .setUri(pathConverter.apply(action.getPrimaryOutput().getPath())) .build()); } + try { + if (action instanceof CommandAction) { + actionBuilder.addAllCommandLine(((CommandAction) action).getArguments()); + } + } catch (CommandLineExpansionException e) { + // Command-line not avaiable, so just not report it + logger.log(Level.INFO, "Could no compute commandline of reported action", e); + } return GenericBuildEvent.protoChaining(this).setAction(actionBuilder.build()).build(); } diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto index 06e7deaa2b..b67f200a14 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto @@ -421,6 +421,9 @@ message ActionExecuted { // Primary output; only provided for successful actions. File primary_output = 6; + + // The command-line of the action, if the action is a command. + repeated string command_line = 9; } // Collection of all output files belonging to that output group. diff --git a/src/test/shell/integration/build_event_stream_test.sh b/src/test/shell/integration/build_event_stream_test.sh index f36127aaad..65d3ef3663 100755 --- a/src/test/shell/integration/build_event_stream_test.sh +++ b/src/test/shell/integration/build_event_stream_test.sh @@ -70,7 +70,7 @@ sh_test( genrule( name = "fails_to_build", outs = ["fails_to_build.txt"], - cmd = "false", + cmd = "echo This build will fail && false", executable = 1, ) sh_test( @@ -700,6 +700,7 @@ function test_test_fails_to_build() { expect_log 'last_message: true' expect_log 'BUILD_FAILURE' expect_log 'last_message: true' + expect_log 'command_line:.*This build will fail' expect_log_once '^build_tool_logs' } |