diff options
author | aehlig <aehlig@google.com> | 2017-10-26 11:45:35 +0200 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2017-10-26 14:37:24 +0200 |
commit | 03d55f3c4af2b37d1177b7faad68e19276f26344 (patch) | |
tree | 0d32886fb92a8098b5d3d0fc8b19a737b9bb00f9 /src/main/java/com/google/devtools/build/lib/runtime | |
parent | dbbcbcb8d227b0f35000f2a07b75524bfe1b681b (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java | 57 |
1 files changed, 50 insertions, 7 deletions
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<BuildEventId> 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<BuildEventId> 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(); + } } /** |