aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build
diff options
context:
space:
mode:
authorGravatar aehlig <aehlig@google.com>2017-10-26 11:45:35 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-26 14:37:24 +0200
commit03d55f3c4af2b37d1177b7faad68e19276f26344 (patch)
tree0d32886fb92a8098b5d3d0fc8b19a737b9bb00f9 /src/main/java/com/google/devtools/build
parentdbbcbcb8d227b0f35000f2a07b75524bfe1b681b (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')
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildeventstream/BuildCompletingEvent.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamer.java57
3 files changed, 69 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildCompletingEvent.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildCompletingEvent.java
index a1b5b284d3..72b6e085f1 100644
--- a/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildCompletingEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/BuildCompletingEvent.java
@@ -27,10 +27,17 @@ import java.util.Collection;
public abstract class BuildCompletingEvent implements BuildEvent {
private final ExitCode exitCode;
private final long finishTimeMillis;
+ private final Collection<BuildEventId> children;
- public BuildCompletingEvent(ExitCode exitCode, long finishTimeMillis) {
+ public BuildCompletingEvent(
+ ExitCode exitCode, long finishTimeMillis, Collection<BuildEventId> children) {
this.exitCode = exitCode;
this.finishTimeMillis = finishTimeMillis;
+ this.children = children;
+ }
+
+ public BuildCompletingEvent(ExitCode exitCode, long finishTimeMillis) {
+ this(exitCode, finishTimeMillis, ImmutableList.of());
}
public ExitCode getExitCode() {
@@ -44,7 +51,7 @@ public abstract class BuildCompletingEvent implements BuildEvent {
@Override
public Collection<BuildEventId> getChildrenEvents() {
- return ImmutableList.of();
+ return children;
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java
index d1c2cb79d4..3c63692c41 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/buildevent/BuildCompleteEvent.java
@@ -16,8 +16,11 @@ package com.google.devtools.build.lib.buildtool.buildevent;
import static com.google.devtools.build.lib.util.Preconditions.checkNotNull;
+import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.buildeventstream.BuildCompletingEvent;
+import com.google.devtools.build.lib.buildeventstream.BuildEventId;
import com.google.devtools.build.lib.buildtool.BuildResult;
+import java.util.Collection;
/**
* This event is fired from BuildTool#stopRequest().
@@ -27,14 +30,16 @@ import com.google.devtools.build.lib.buildtool.BuildResult;
public final class BuildCompleteEvent extends BuildCompletingEvent {
private final BuildResult result;
- /**
- * Construct the BuildCompleteEvent.
- */
- public BuildCompleteEvent(BuildResult result) {
- super(result.getExitCondition(), result.getStopTime());
+ /** Construct the BuildCompleteEvent. */
+ public BuildCompleteEvent(BuildResult result, Collection<BuildEventId> children) {
+ super(result.getExitCondition(), result.getStopTime(), children);
this.result = checkNotNull(result);
}
+ public BuildCompleteEvent(BuildResult result) {
+ this(result, ImmutableList.<BuildEventId>of());
+ }
+
/**
* @return the build summary
*/
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();
+ }
}
/**