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();
}
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();
}
}
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);
}
}
}
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();
}
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();
}
Aggregations