Search in sources :

Example 1 with BuildEventTransport

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

the class BuildEventTransportFactoryTest method testCreatesBinaryFormatFileTransport.

@Test
public void testCreatesBinaryFormatFileTransport() throws IOException {
    File binaryFile = tmp.newFile();
    when(options.getBuildEventTextFile()).thenReturn("");
    when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath());
    ImmutableSet<BuildEventTransport> transports = BuildEventTransportFactory.createFromOptions(options, pathConverter);
    assertThat(FluentIterable.from(transports).transform(GET_CLASS)).containsExactly(BinaryFormatFileTransport.class);
    sendEventsAndClose(buildEvent, transports);
    assertThat(binaryFile.exists()).isTrue();
}
Also used : BuildEventTransport(com.google.devtools.build.lib.buildeventstream.BuildEventTransport) File(java.io.File) Test(org.junit.Test)

Example 2 with BuildEventTransport

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

the class BuildEventTransportFactoryTest method sendEventsAndClose.

private void sendEventsAndClose(BuildEvent event, Iterable<BuildEventTransport> transports) throws IOException {
    for (BuildEventTransport transport : transports) {
        transport.sendBuildEvent(event);
        transport.close();
    }
}
Also used : BuildEventTransport(com.google.devtools.build.lib.buildeventstream.BuildEventTransport)

Example 3 with BuildEventTransport

use of com.google.devtools.build.lib.buildeventstream.BuildEventTransport 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 4 with BuildEventTransport

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

the class BuildEventStreamerModule method tryCreateStreamer.

@VisibleForTesting
Optional<BuildEventStreamer> tryCreateStreamer(OptionsProvider optionsProvider, ModuleEnvironment moduleEnvironment) {
    try {
        PathConverter pathConverter;
        if (commandEnvironment == null) {
            pathConverter = new PathConverter() {

                @Override
                public String apply(Path path) {
                    return path.getPathString();
                }
            };
        } else {
            pathConverter = commandEnvironment.getRuntime().getPathToUriConverter();
        }
        BuildEventStreamOptions besOptions = checkNotNull(optionsProvider.getOptions(BuildEventStreamOptions.class), "Could not get BuildEventStreamOptions");
        ImmutableSet<BuildEventTransport> buildEventTransports = createFromOptions(besOptions, pathConverter);
        if (!buildEventTransports.isEmpty()) {
            BuildEventStreamer streamer = new BuildEventStreamer(buildEventTransports);
            return Optional.of(streamer);
        }
    } catch (IOException e) {
        moduleEnvironment.exit(new AbruptExitException(ExitCode.LOCAL_ENVIRONMENTAL_ERROR, e));
    }
    return Optional.absent();
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) BuildEventStreamOptions(com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions) BuildEventTransport(com.google.devtools.build.lib.buildeventstream.BuildEventTransport) PathConverter(com.google.devtools.build.lib.buildeventstream.PathConverter) IOException(java.io.IOException) AbruptExitException(com.google.devtools.build.lib.util.AbruptExitException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 5 with BuildEventTransport

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

the class BuildEventTransportFactoryTest method testCreatesAllTransports.

@Test
public void testCreatesAllTransports() throws IOException {
    File textFile = tmp.newFile();
    File binaryFile = tmp.newFile();
    when(options.getBuildEventTextFile()).thenReturn(textFile.getAbsolutePath());
    when(options.getBuildEventBinaryFile()).thenReturn(binaryFile.getAbsolutePath());
    ImmutableSet<BuildEventTransport> transports = BuildEventTransportFactory.createFromOptions(options, pathConverter);
    assertThat(FluentIterable.from(transports).transform(GET_CLASS)).containsExactly(TextFormatFileTransport.class, BinaryFormatFileTransport.class);
    sendEventsAndClose(buildEvent, transports);
    assertThat(textFile.exists()).isTrue();
    assertThat(binaryFile.exists()).isTrue();
}
Also used : BuildEventTransport(com.google.devtools.build.lib.buildeventstream.BuildEventTransport) File(java.io.File) Test(org.junit.Test)

Aggregations

BuildEventTransport (com.google.devtools.build.lib.buildeventstream.BuildEventTransport)6 File (java.io.File)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NoBuildEvent (com.google.devtools.build.lib.analysis.NoBuildEvent)1 BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEvent)1 BuildEventId (com.google.devtools.build.lib.buildeventstream.BuildEventId)1 PathConverter (com.google.devtools.build.lib.buildeventstream.PathConverter)1 BuildEventStreamOptions (com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions)1 AbruptExitException (com.google.devtools.build.lib.util.AbruptExitException)1 Path (com.google.devtools.build.lib.vfs.Path)1