Search in sources :

Example 1 with BuildEvent

use of com.google.devtools.build.lib.buildeventstream.BuildEvent in project bazel by bazelbuild.

the class BuildEventStreamerTest method testMissingPrerequisits.

@Test
public void testMissingPrerequisits() {
    // Verify that an event where the prerequisite is never coming till the end of
    // the build still gets posted, with the prerequisite aborted.
    RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
    BuildEventStreamer streamer = new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport));
    BuildEventId expectedId = testId("the target");
    BuildEvent startEvent = new GenericBuildEvent(testId("Initial"), ImmutableSet.<BuildEventId>of(ProgressEvent.INITIAL_PROGRESS_UPDATE, expectedId, BuildEventId.buildFinished()));
    BuildEventId rootCauseId = testId("failure event");
    BuildEvent failedTarget = new GenericOrderEvent(expectedId, ImmutableSet.<BuildEventId>of(rootCauseId));
    streamer.buildEvent(startEvent);
    streamer.buildEvent(failedTarget);
    streamer.buildEvent(new BuildCompleteEvent(new BuildResult(0)));
    List<BuildEvent> allEventsSeen = transport.getEvents();
    assertThat(allEventsSeen).hasSize(6);
    assertEquals(startEvent.getEventId(), allEventsSeen.get(0).getEventId());
    assertEquals(BuildEventId.buildFinished(), allEventsSeen.get(1).getEventId());
    BuildEvent linkEvent = allEventsSeen.get(2);
    assertEquals(ProgressEvent.INITIAL_PROGRESS_UPDATE, linkEvent.getEventId());
    assertEquals(rootCauseId, allEventsSeen.get(3).getEventId());
    assertEquals(failedTarget.getEventId(), allEventsSeen.get(4).getEventId());
}
Also used : GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) BuildResult(com.google.devtools.build.lib.buildtool.BuildResult) BuildEventId(com.google.devtools.build.lib.buildeventstream.BuildEventId) BuildEvent(com.google.devtools.build.lib.buildeventstream.BuildEvent) GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) BuildCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent) Test(org.junit.Test)

Example 2 with BuildEvent

use of com.google.devtools.build.lib.buildeventstream.BuildEvent in project bazel by bazelbuild.

the class BuildEventStreamerTest method testBadInitialEvent.

@Test
public void testBadInitialEvent() {
    // Verify that, if the initial event does not announce the initial progress update event,
    // the initial progress event is used instead to chain that event; in this way, new
    // progress updates can always be chained in.
    RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
    BuildEventStreamer streamer = new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport));
    BuildEvent unexpectedStartEvent = new GenericBuildEvent(testId("unexpected start"), ImmutableSet.<BuildEventId>of());
    streamer.buildEvent(unexpectedStartEvent);
    List<BuildEvent> eventsSeen = transport.getEvents();
    assertThat(eventsSeen).hasSize(2);
    assertEquals(unexpectedStartEvent.getEventId(), eventsSeen.get(1).getEventId());
    BuildEvent initial = eventsSeen.get(0);
    assertEquals(ProgressEvent.INITIAL_PROGRESS_UPDATE, initial.getEventId());
    assertTrue("Event should be linked", initial.getChildrenEvents().contains(unexpectedStartEvent.getEventId()));
    // The initial event should also announce a new progress event; we test this
    // by streaming another unannounced event.
    BuildEvent unexpectedEvent = new GenericBuildEvent(testId("unexpected"), ImmutableSet.<BuildEventId>of());
    streamer.buildEvent(unexpectedEvent);
    List<BuildEvent> allEventsSeen = transport.getEvents();
    assertThat(allEventsSeen).hasSize(4);
    assertEquals(unexpectedEvent.getEventId(), allEventsSeen.get(3).getEventId());
    BuildEvent secondLinkEvent = allEventsSeen.get(2);
    assertTrue("Progress should have been announced", initial.getChildrenEvents().contains(secondLinkEvent.getEventId()));
    assertTrue("Second event should be linked", secondLinkEvent.getChildrenEvents().contains(unexpectedEvent.getEventId()));
}
Also used : GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) BuildEvent(com.google.devtools.build.lib.buildeventstream.BuildEvent) GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) Test(org.junit.Test)

Example 3 with BuildEvent

use of com.google.devtools.build.lib.buildeventstream.BuildEvent in project bazel by bazelbuild.

the class BuildEventStreamer method buildEvent.

@Subscribe
public void buildEvent(BuildEvent event) {
    if (isActionWithoutError(event) || bufferUntilPrerequisitesReceived(event)) {
        return;
    }
    post(event);
    // Reconsider all events blocked by the event just posted.
    Collection<BuildEvent> toReconsider = pendingEvents.removeAll(event.getEventId());
    for (BuildEvent freedEvent : toReconsider) {
        buildEvent(freedEvent);
    }
    if (event instanceof BuildCompleteEvent) {
        buildComplete();
    }
}
Also used : BuildEvent(com.google.devtools.build.lib.buildeventstream.BuildEvent) NoBuildEvent(com.google.devtools.build.lib.analysis.NoBuildEvent) BuildCompleteEvent(com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent) Subscribe(com.google.common.eventbus.Subscribe)

Example 4 with BuildEvent

use of com.google.devtools.build.lib.buildeventstream.BuildEvent in project bazel by bazelbuild.

the class BuildEventStreamer method post.

/**
   * Post a new event to all transports; simultaneously keep track of the events we announce to
   * still come.
   *
   * <p>Moreover, link unannounced events to the progress stream; we only expect failure events to
   * come before their parents.
   */
private void post(BuildEvent event) {
    BuildEvent linkEvent = null;
    BuildEventId id = event.getEventId();
    synchronized (this) {
        if (announcedEvents == null) {
            announcedEvents = new HashSet<>();
            postedEvents = new HashSet<>();
            if (!event.getChildrenEvents().contains(ProgressEvent.INITIAL_PROGRESS_UPDATE)) {
                linkEvent = ProgressEvent.progressChainIn(progressCount, event.getEventId());
                progressCount++;
                announcedEvents.addAll(linkEvent.getChildrenEvents());
                postedEvents.add(linkEvent.getEventId());
            }
        } else {
            if (!announcedEvents.contains(id)) {
                linkEvent = ProgressEvent.progressChainIn(progressCount, id);
                progressCount++;
                announcedEvents.addAll(linkEvent.getChildrenEvents());
                postedEvents.add(linkEvent.getEventId());
            }
            postedEvents.add(id);
        }
        announcedEvents.addAll(event.getChildrenEvents());
    }
    for (BuildEventTransport transport : transports) {
        try {
            if (linkEvent != null) {
                transport.sendBuildEvent(linkEvent);
            }
            transport.sendBuildEvent(event);
        } catch (IOException e) {
            // TODO(aehlig): signal that the build ought to be aborted
            log.severe("Failed to write to build event transport: " + e);
        }
    }
}
Also used : BuildEventId(com.google.devtools.build.lib.buildeventstream.BuildEventId) BuildEventTransport(com.google.devtools.build.lib.buildeventstream.BuildEventTransport) BuildEvent(com.google.devtools.build.lib.buildeventstream.BuildEvent) NoBuildEvent(com.google.devtools.build.lib.analysis.NoBuildEvent) IOException(java.io.IOException)

Example 5 with BuildEvent

use of com.google.devtools.build.lib.buildeventstream.BuildEvent in project bazel by bazelbuild.

the class BuildEventStreamerTest method testChaining.

@Test
public void testChaining() {
    // Verify that unannounced events are linked in with progress update events, assuming
    // a correctly formed initial event.
    RecordingBuildEventTransport transport = new RecordingBuildEventTransport();
    BuildEventStreamer streamer = new BuildEventStreamer(ImmutableSet.<BuildEventTransport>of(transport));
    BuildEvent startEvent = new GenericBuildEvent(testId("Initial"), ImmutableSet.of(ProgressEvent.INITIAL_PROGRESS_UPDATE));
    BuildEvent unexpectedEvent = new GenericBuildEvent(testId("unexpected"), ImmutableSet.<BuildEventId>of());
    streamer.buildEvent(startEvent);
    streamer.buildEvent(unexpectedEvent);
    List<BuildEvent> eventsSeen = transport.getEvents();
    assertThat(eventsSeen).hasSize(3);
    assertEquals(startEvent.getEventId(), eventsSeen.get(0).getEventId());
    assertEquals(unexpectedEvent.getEventId(), eventsSeen.get(2).getEventId());
    BuildEvent linkEvent = eventsSeen.get(1);
    assertEquals(ProgressEvent.INITIAL_PROGRESS_UPDATE, linkEvent.getEventId());
    assertTrue("Unexpected events should be linked", linkEvent.getChildrenEvents().contains(unexpectedEvent.getEventId()));
}
Also used : GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) BuildEvent(com.google.devtools.build.lib.buildeventstream.BuildEvent) GenericBuildEvent(com.google.devtools.build.lib.buildeventstream.GenericBuildEvent) Test(org.junit.Test)

Aggregations

BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEvent)8 GenericBuildEvent (com.google.devtools.build.lib.buildeventstream.GenericBuildEvent)6 Test (org.junit.Test)6 BuildCompleteEvent (com.google.devtools.build.lib.buildtool.buildevent.BuildCompleteEvent)4 BuildEventId (com.google.devtools.build.lib.buildeventstream.BuildEventId)3 BuildResult (com.google.devtools.build.lib.buildtool.BuildResult)3 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)2 Subscribe (com.google.common.eventbus.Subscribe)1 BuildEventTransport (com.google.devtools.build.lib.buildeventstream.BuildEventTransport)1 BuildEventWithOrderConstraint (com.google.devtools.build.lib.buildeventstream.BuildEventWithOrderConstraint)1 IOException (java.io.IOException)1