diff options
Diffstat (limited to 'src')
3 files changed, 77 insertions, 3 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/buildeventstream/AbortedEvent.java b/src/main/java/com/google/devtools/build/lib/buildeventstream/AbortedEvent.java index 5816ecd3bd..0638c29552 100644 --- a/src/main/java/com/google/devtools/build/lib/buildeventstream/AbortedEvent.java +++ b/src/main/java/com/google/devtools/build/lib/buildeventstream/AbortedEvent.java @@ -16,7 +16,7 @@ package com.google.devtools.build.lib.buildeventstream; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.cmdline.Label; - +import java.util.Collection; import javax.annotation.Nullable; /** A {@link BuildEvent} reporting an event not coming due to the build being aborted. */ @@ -26,15 +26,34 @@ public class AbortedEvent extends GenericBuildEvent { @Nullable private final Label label; public AbortedEvent( - BuildEventId id, BuildEventStreamProtos.Aborted.AbortReason reason, String description, + BuildEventId id, + Collection<BuildEventId> children, + BuildEventStreamProtos.Aborted.AbortReason reason, + String description, @Nullable Label label) { - super(id, ImmutableList.<BuildEventId>of()); + super(id, children); this.reason = reason; this.description = description; this.label = label; } public AbortedEvent( + BuildEventId id, + BuildEventStreamProtos.Aborted.AbortReason reason, + String description, + @Nullable Label label) { + this(id, ImmutableList.<BuildEventId>of(), reason, description, label); + } + + public AbortedEvent( + BuildEventId id, + Collection<BuildEventId> children, + BuildEventStreamProtos.Aborted.AbortReason reason, + String description) { + this(id, children, reason, description, null); + } + + public AbortedEvent( BuildEventId id, BuildEventStreamProtos.Aborted.AbortReason reason, String description) { this(id, reason, description, null); } 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 3353d577e8..b393af0cb8 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 @@ -254,6 +254,27 @@ public class BuildEventStreamer implements EventHandler { } } + /** + * If some events are blocked on the absence of a build_started event, generate such an event; + * moreover, make that artificial start event announce all events blocked on it, as well as the + * {@link BuildCompletingEvent} that caused the early end of the stream. + */ + private void clearMissingStartEvent(BuildEventId id) { + if (pendingEvents.containsKey(BuildEventId.buildStartedId())) { + ImmutableSet.Builder<BuildEventId> children = ImmutableSet.<BuildEventId>builder(); + children.add(ProgressEvent.INITIAL_PROGRESS_UPDATE); + children.add(id); + children.addAll( + pendingEvents + .get(BuildEventId.buildStartedId()) + .stream() + .map(BuildEvent::getEventId) + .collect(ImmutableSet.<BuildEventId>toImmutableSet())); + buildEvent( + new AbortedEvent(BuildEventId.buildStartedId(), children.build(), abortReason, "")); + } + } + /** Clear pending events by generating aborted events for all their requisits. */ private void clearPendingEvents() { while (!pendingEvents.isEmpty()) { @@ -404,6 +425,11 @@ public class BuildEventStreamer implements EventHandler { } } + if (event instanceof BuildCompletingEvent + && !event.getEventId().equals(BuildEventId.buildStartedId())) { + clearMissingStartEvent(event.getEventId()); + } + post(event); // Reconsider all events blocked by the event just posted. diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index 2c5a263fc2..452384de81 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -734,4 +734,33 @@ public class BuildEventStreamerTest extends FoundationTestCase { verify(outErr, times(1)).getOut(); verify(outErr, times(1)).getErr(); } + + @Test + public void testEarlyAbort() throws Exception { + // For a build that is aborted before a build-started event is generated, + // we still expect that, if a build-started event is forced by some order + // constraint (e.g., CommandLine wants to come after build started), then + // that gets sorted to the beginning. + RecordingBuildEventTransport transport = new RecordingBuildEventTransport(); + BuildEventStreamer streamer = + new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport), reporter); + + BuildEvent orderEvent = + new GenericOrderEvent( + testId("event depending on start"), + ImmutableList.of(), + ImmutableList.of(BuildEventId.buildStartedId())); + + streamer.buildEvent(orderEvent); + streamer.buildEvent(new BuildCompleteEvent(new BuildResult(0))); + + List<BuildEvent> eventsSeen = transport.getEvents(); + assertThat(eventsSeen).hasSize(4); + assertThat(eventsSeen.get(0).getEventId()).isEqualTo(BuildEventId.buildStartedId()); + assertThat(eventsSeen.get(1).getEventId()).isEqualTo(orderEvent.getEventId()); + assertThat(ImmutableSet.of(eventsSeen.get(2).getEventId(), eventsSeen.get(3).getEventId())) + .isEqualTo( + ImmutableSet.of(BuildEventId.buildFinished(), ProgressEvent.INITIAL_PROGRESS_UPDATE)); + assertThat(transport.getEventProtos().get(3).getLastMessage()).isTrue(); + } } |