From 76de73b979219fe2697aa9dc8f354020e1905d81 Mon Sep 17 00:00:00 2001 From: ruperts Date: Fri, 2 Mar 2018 16:10:43 -0800 Subject: BEP: Add a --build_event_publish_all_actions flag to allow all actions to be published via the BEP, instead of only publishing failed actions and extra actions. RELNOTES: Add a --build_event_publish_all_actions flag to allow all actions to be published via the BEP. PiperOrigin-RevId: 187683799 --- src/main/java/com/google/devtools/build/lib/BUILD | 2 + .../buildeventservice/BuildEventServiceModule.java | 4 +- .../transports/BuildEventStreamOptions.java | 10 ++++ .../build/lib/runtime/BuildEventStreamer.java | 69 ++++++++++++++++------ 4 files changed, 66 insertions(+), 19 deletions(-) (limited to 'src/main/java/com/google/devtools/build') diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index c41711da16..8b5135122e 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -512,6 +512,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/analysis/skylark/annotations", "//src/main/java/com/google/devtools/build/lib/buildeventstream", "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", + "//src/main/java/com/google/devtools/build/lib/buildeventstream/transports", "//src/main/java/com/google/devtools/build/lib/causes", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect", @@ -1177,6 +1178,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib/bazel/repository/downloader", "//src/main/java/com/google/devtools/build/lib/buildeventstream", "//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto", + "//src/main/java/com/google/devtools/build/lib/buildeventstream/transports", "//src/main/java/com/google/devtools/build/lib/clock", "//src/main/java/com/google/devtools/build/lib/cmdline", "//src/main/java/com/google/devtools/build/lib/collect", diff --git a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java index 3998c36b9a..c8b4be81ba 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventservice/BuildEventServiceModule.java @@ -186,7 +186,9 @@ public abstract class BuildEventServiceModule transports; private final Reporter reporter; + private final BuildEventStreamOptions options; private Set announcedEvents; private final Set postedEvents = new HashSet<>(); private final Set configurationsPosted = new HashSet<>(); @@ -160,14 +164,26 @@ public class BuildEventStreamer implements EventHandler { } } - public BuildEventStreamer(Collection transports, Reporter reporter) { + /** Creates a new build event streamer. */ + public BuildEventStreamer( + Collection transports, + @Nullable Reporter reporter, + BuildEventStreamOptions options) { checkArgument(transports.size() > 0); + checkNotNull(options); this.transports = transports; this.reporter = reporter; + this.options = options; this.announcedEvents = null; this.progressCount = 0; } + /** Creates a new build event streamer with default options. */ + public BuildEventStreamer( + Collection transports, @Nullable Reporter reporter) { + this(transports, reporter, new BuildEventStreamOptions()); + } + public void registerOutErrProvider(OutErrProvider outErrProvider) { this.outErrProvider = outErrProvider; } @@ -441,15 +457,7 @@ public class BuildEventStreamer implements EventHandler { } } - if (isActionWithoutError(event) - || bufferUntilPrerequisitesReceived(event) - || isVacuousTestSummary(event)) { - return; - } - - if (isTestCommand && event instanceof BuildCompleteEvent) { - // In case of "bazel test" ignore the BuildCompleteEvent, as it will be followed by a - // TestingCompleteEvent that contains the correct exit code. + if (shouldIgnoreBuildEvent(event)) { return; } @@ -557,14 +565,39 @@ public class BuildEventStreamer implements EventHandler { } } - /** - * Return true, if the action is not worth being reported. This is the case, if the action - * executed successfully and is not an ExtraAction. - */ - private static boolean isActionWithoutError(BuildEvent event) { - return event instanceof ActionExecutedEvent - && ((ActionExecutedEvent) event).getException() == null - && (!(((ActionExecutedEvent) event).getAction() instanceof ExtraAction)); + /** Returns whether a {@link BuildEvent} should be ignored. */ + public boolean shouldIgnoreBuildEvent(BuildEvent event) { + if (event instanceof ActionExecutedEvent + && !shouldPublishActionExecutedEvent((ActionExecutedEvent) event)) { + return true; + } + + if (bufferUntilPrerequisitesReceived(event) || isVacuousTestSummary(event)) { + return true; + } + + if (isTestCommand && event instanceof BuildCompleteEvent) { + // In case of "bazel test" ignore the BuildCompleteEvent, as it will be followed by a + // TestingCompleteEvent that contains the correct exit code. + return true; + } + + return false; + } + + /** Returns whether an {@link ActionExecutedEvent} should be published. */ + private boolean shouldPublishActionExecutedEvent(ActionExecutedEvent event) { + if (options.publishAllActions) { + return true; + } + if (event.getException() != null) { + // Publish failed actions + return true; + } + if (event.getAction() instanceof ExtraAction) { + return true; + } + return false; } private boolean bufferUntilPrerequisitesReceived(BuildEvent event) { -- cgit v1.2.3