aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
authorGravatar Klaus Aehlig <aehlig@google.com>2017-03-24 14:26:02 +0000
committerGravatar Philipp Wollermann <philwo@google.com>2017-03-27 11:34:46 +0000
commit5e9abe661f20fd77a89cb1cf22b68de28f56367f (patch)
treecbce841dfdb05956a8aaafb17f12f64d90c62dd7 /src/main
parent407dd44e827ff53214437720eb5d8bd99349d809 (diff)
BuildEventStreamerModule: catch early build events
Abusing the checkEnvironment method, register early on the event bus and catch all events till the time we are supposed to process the options. This solves the problem that events relevant to the build event stream are posted (e.g., the GotOptions event) before(!) we know if a BuildEventStreamer is required. -- Change-Id: Iac63302351b862772638791932bcaa58b60b22fb Reviewed-on: https://cr.bazel.build/9457 PiperOrigin-RevId: 151123359 MOS_MIGRATED_REVID=151123359
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java
index 47f5b089d6..983aeb38e5 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BuildEventStreamerModule.java
@@ -22,6 +22,8 @@ import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
+import com.google.common.eventbus.Subscribe;
+import com.google.devtools.build.lib.buildeventstream.BuildEvent;
import com.google.devtools.build.lib.buildeventstream.BuildEventTransport;
import com.google.devtools.build.lib.buildeventstream.PathConverter;
import com.google.devtools.build.lib.buildeventstream.transports.BuildEventStreamOptions;
@@ -31,6 +33,8 @@ import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.common.options.OptionsBase;
import com.google.devtools.common.options.OptionsProvider;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
/** Module responsible for configuring BuildEventStreamer and transports. */
@@ -38,26 +42,48 @@ public class BuildEventStreamerModule extends BlazeModule {
private CommandEnvironment commandEnvironment;
+ private static class BuildEventRecorder {
+ private final List<BuildEvent> events = new ArrayList<>();
+
+ @Subscribe
+ public void buildEvent(BuildEvent event) {
+ events.add(event);
+ }
+
+ List<BuildEvent> getEvents() {
+ return events;
+ }
+ }
+
+ private BuildEventRecorder buildEventRecorder;
+
@Override
public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
return ImmutableList.<Class<? extends OptionsBase>>of(BuildEventStreamOptions.class);
}
@Override
- public void beforeCommand(Command command, CommandEnvironment commandEnvironment)
- throws AbruptExitException {
+ public void checkEnvironment(CommandEnvironment commandEnvironment) {
this.commandEnvironment = commandEnvironment;
+ this.buildEventRecorder = new BuildEventRecorder();
+ commandEnvironment.getEventBus().register(buildEventRecorder);
}
@Override
public void handleOptions(OptionsProvider optionsProvider) {
checkState(commandEnvironment != null, "Methods called out of order");
- Optional<BuildEventStreamer> streamer =
+ Optional<BuildEventStreamer> maybeStreamer =
tryCreateStreamer(optionsProvider, commandEnvironment.getBlazeModuleEnvironment());
- if (streamer.isPresent()) {
- commandEnvironment.getReporter().addHandler(streamer.get());
- commandEnvironment.getEventBus().register(streamer.get());
+ if (maybeStreamer.isPresent()) {
+ BuildEventStreamer streamer = maybeStreamer.get();
+ commandEnvironment.getReporter().addHandler(streamer);
+ commandEnvironment.getEventBus().register(streamer);
+ for (BuildEvent event : buildEventRecorder.getEvents()) {
+ streamer.buildEvent(event);
+ }
}
+ commandEnvironment.getEventBus().unregister(buildEventRecorder);
+ this.buildEventRecorder = null;
}
@VisibleForTesting