Skip to content

Commit

Permalink
Register the BuildEventStreamer
Browse files Browse the repository at this point in the history
...so that it gets informed about all relevant events happening
during the build. For the time being, we only consider one transport,
that to a text file.

--
Change-Id: I429c957f39a07b795a71acbeaa1360178574a1d1
Reviewed-on: https://bazel-review.googlesource.com/#/c/6276
MOS_MIGRATED_REVID=135464059
aehlig authored and damienmg committed Oct 7, 2016
1 parent a71d2ff commit 0436ce0
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/google/devtools/build/lib/BUILD
Original file line number Diff line number Diff line change
@@ -1001,6 +1001,7 @@ java_library(
"//src/main/java/com/google/devtools/build/docgen:docgen_javalib",
"//src/main/java/com/google/devtools/build/lib/actions",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/proto:build_event_stream_java_proto",
"//src/main/java/com/google/devtools/build/lib/buildeventstream/transports",
"//src/main/java/com/google/devtools/build/lib/cmdline",
"//src/main/java/com/google/devtools/build/lib/query2",
"//src/main/java/com/google/devtools/build/lib/query2:query-engine",
Original file line number Diff line number Diff line change
@@ -27,6 +27,8 @@
import com.google.common.collect.Iterables;
import com.google.common.collect.ListMultimap;
import com.google.common.io.Flushables;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.transports.TextFormatFileTransport;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.events.Reporter;
@@ -452,6 +454,18 @@ private int execExclusively(List<String> args, OutErr outErr, long firstContactT
Reporter reporter = env.getReporter();
reporter.addHandler(handler);
env.getEventBus().register(handler);
if (eventHandlerOptions.buildEventTextFile.length() > 0) {
try {
BuildEventStreamer streamer =
new BuildEventStreamer(
ImmutableSet.<BuildEventTransport>of(
new TextFormatFileTransport(eventHandlerOptions.buildEventTextFile)));
reporter.addHandler(streamer);
env.getEventBus().register(streamer);
} catch (IOException e) {
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR.getNumericExitCode();
}
}

// We register an ANSI-allowing handler associated with {@code handler} so that ANSI control
// codes can be re-introduced later even if blaze is invoked with --color=no. This is useful
Original file line number Diff line number Diff line change
@@ -21,17 +21,15 @@
import com.google.devtools.common.options.EnumConverter;
import com.google.devtools.common.options.Option;
import com.google.devtools.common.options.OptionsBase;

import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.EnumSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

/**
* BlazeCommandEventHandler: an event handler established for the duration of a
@@ -170,6 +168,15 @@ public static class Options extends OptionsBase {
)
public int experimentalUiActionsShown;


@Option(
name = "experimental_build_event_text_file",
defaultValue = "",
category = "hidden",
help = "If non-empty, write a textual representation of the build event protocol to that file"
)
public String buildEventTextFile;

public boolean useColor() {
return useColorEnum == UseColor.YES || (useColorEnum == UseColor.AUTO && isATty);
}

0 comments on commit 0436ce0

Please sign in to comment.