diff options
author | ruperts <ruperts@google.com> | 2018-03-02 16:10:43 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-03-02 16:12:27 -0800 |
commit | 76de73b979219fe2697aa9dc8f354020e1905d81 (patch) | |
tree | 88e765f3ef604d5bdd64c5a022e825dcc7f080d5 /src/main/java/com/google/devtools/build | |
parent | a6679aead65603162d57ee5d868ab06fed369fab (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build')
4 files changed, 66 insertions, 19 deletions
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<T extends BuildEventServiceOptions transports = transportsBuilder.build(); if (!transports.isEmpty()) { - return new BuildEventStreamer(transports, reporter); + BuildEventStreamOptions buildEventStreamOptions = + optionsProvider.getOptions(BuildEventStreamOptions.class); + return new BuildEventStreamer(transports, reporter, buildEventStreamOptions); } } catch (Exception e) { moduleEnvironment.exit(new AbruptExitException(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e)); diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventStreamOptions.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventStreamOptions.java index d2e689d92c..f489635747 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventStreamOptions.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/transports/BuildEventStreamOptions.java @@ -93,6 +93,16 @@ public class BuildEventStreamOptions extends OptionsBase { ) public boolean buildEventJsonFilePathConversion; + @Option( + name = "build_event_publish_all_actions", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.LOGGING, + effectTags = {OptionEffectTag.AFFECTS_OUTPUTS}, + help = "Whether all actions should be published." + ) + public boolean publishAllActions; + + // TODO(ruperts): Remove these public getter methods for consistency with other options classes? public String getBuildEventTextFile() { return buildEventTextFile; } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java index 7c54ec4600..178169320a 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.runtime; import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; import static com.google.devtools.build.lib.events.Event.of; import static com.google.devtools.build.lib.events.EventKind.PROGRESS; @@ -49,6 +50,7 @@ import com.google.devtools.build.lib.buildeventstream.ChainableEvent; import com.google.devtools.build.lib.buildeventstream.LastBuildEvent; import com.google.devtools.build.lib.buildeventstream.NullConfiguration; import com.google.devtools.build.lib.buildeventstream.ProgressEvent; +import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent; import com.google.devtools.build.lib.buildtool.buildevent.BuildInterruptedEvent; @@ -73,6 +75,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; +import javax.annotation.Nullable; /** * Listens for {@link BuildEvent}s and streams them to the provided {@link BuildEventTransport}s. @@ -88,6 +91,7 @@ public class BuildEventStreamer implements EventHandler { private final Collection<BuildEventTransport> transports; private final Reporter reporter; + private final BuildEventStreamOptions options; private Set<BuildEventId> announcedEvents; private final Set<BuildEventId> postedEvents = new HashSet<>(); private final Set<BuildEventId> configurationsPosted = new HashSet<>(); @@ -160,14 +164,26 @@ public class BuildEventStreamer implements EventHandler { } } - public BuildEventStreamer(Collection<BuildEventTransport> transports, Reporter reporter) { + /** Creates a new build event streamer. */ + public BuildEventStreamer( + Collection<BuildEventTransport> 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<BuildEventTransport> 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) { |