From 03d55f3c4af2b37d1177b7faad68e19276f26344 Mon Sep 17 00:00:00 2001 From: aehlig Date: Thu, 26 Oct 2017 11:45:35 +0200 Subject: BuildEventStreamer: allow final messages After receiving a BuildCompletingEvent, allow some final late messages, but only those not yet seen and announced by that BuildCompletingEvent. This mechanism will be used in a follow-up change to add a message with tool statistics. Change-Id: I979bec5bd946208068faff9a4ddd5245a769f096 PiperOrigin-RevId: 173514552 --- .../build/lib/runtime/BuildEventStreamer.java | 57 +++++++++++++++++++--- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/runtime') 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 33adad0aab..109065385b 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 @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.buildeventstream.BuildEventTransport; import com.google.devtools.build.lib.buildeventstream.BuildEventTransportClosedEvent; import com.google.devtools.build.lib.buildeventstream.BuildEventWithConfiguration; import com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint; +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; @@ -98,6 +99,14 @@ public class BuildEventStreamer implements EventHandler { // Will be set to true if the build was invoked through "bazel test". private boolean isTestCommand; + // After a BuildCompetingEvent we might expect a whitelisted set of events. If non-null, + // the streamer is restricted to only allow those events and fully close after having seen + // them. + private Set finalEventsToCome = null; + + // True, if we already closed the stream. + private boolean closed; + private static final Logger logger = Logger.getLogger(BuildEventStreamer.class.getName()); /** @@ -289,7 +298,7 @@ public class BuildEventStreamer implements EventHandler { * Clear all events that are still announced; events not naturally closed by the expected event * normally only occur if the build is aborted. */ - private void clearAnnouncedEvents() { + private void clearAnnouncedEvents(Collection dontclear) { if (announcedEvents != null) { // create a copy of the identifiers to clear, as the post method // will change the set of already announced events. @@ -298,7 +307,9 @@ public class BuildEventStreamer implements EventHandler { ids = Sets.difference(announcedEvents, postedEvents); } for (BuildEventId id : ids) { - post(new AbortedEvent(id, abortReason, "")); + if (!dontclear.contains(id)) { + post(new AbortedEvent(id, abortReason, "")); + } } } } @@ -320,7 +331,18 @@ public class BuildEventStreamer implements EventHandler { TimeUnit.SECONDS); } + public boolean isClosed() { + return closed; + } + private void close() { + synchronized (this) { + if (closed) { + return; + } + closed = true; + } + ScheduledExecutorService executor = null; try { executor = Executors.newSingleThreadScheduledExecutor(); @@ -407,6 +429,17 @@ public class BuildEventStreamer implements EventHandler { @Subscribe public void buildEvent(BuildEvent event) { + if (finalEventsToCome != null) { + synchronized (this) { + BuildEventId id = event.getEventId(); + if (finalEventsToCome.contains(id)) { + finalEventsToCome.remove(id); + } else { + return; + } + } + } + if (isActionWithoutError(event) || bufferUntilPrerequisitesReceived(event) || isVacuousTestSummary(event)) { @@ -451,14 +484,18 @@ public class BuildEventStreamer implements EventHandler { } if (event instanceof BuildCompletingEvent) { - buildComplete(); + buildComplete(event); } if (event instanceof NoBuildEvent) { if (!((NoBuildEvent) event).separateFinishedEvent()) { - buildComplete(); + buildComplete(event); } } + + if (finalEventsToCome != null && finalEventsToCome.isEmpty()) { + close(); + } } private synchronized BuildEvent flushStdoutStderrEvent(String out, String err) { @@ -496,7 +533,7 @@ public class BuildEventStreamer implements EventHandler { return ImmutableSet.copyOf(transports); } - private void buildComplete() { + private void buildComplete(ChainableEvent event) { clearPendingEvents(); String out = null; String err = null; @@ -505,8 +542,14 @@ public class BuildEventStreamer implements EventHandler { err = outErrProvider.getErr(); } post(ProgressEvent.finalProgressUpdate(progressCount, out, err)); - clearAnnouncedEvents(); - close(); + clearAnnouncedEvents(event.getChildrenEvents()); + + finalEventsToCome = new HashSet<>(announcedEvents); + finalEventsToCome.removeAll(postedEvents); + + if (finalEventsToCome.isEmpty()) { + close(); + } } /** -- cgit v1.2.3