Update `BlazeRuntimeWrapper` to replay events posted during `beforeCommand`, just as `BlazeCommandDispatcher` does. This helps to catch bugs with incorrect handling of duplicate posts.
@@ -36,6 +36,8 @@ import com.google.devtools.build.lib.buildtool.BuildRequestOptions;
import com.google.devtools.build.lib.buildtool.BuildResult;
import com.google.devtools.build.lib.buildtool.BuildTool;
import com.google.devtools.build.lib.clock.JavaClock;
+import com.google.devtools.build.lib.events.Reporter;
+import com.google.devtools.build.lib.events.StoredEventHandler;
import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
import com.google.devtools.build.lib.exec.BinTools;
import com.google.devtools.build.lib.exec.ExecutionOptions;
@@ -293,8 +295,8 @@ public class BlazeRuntimeWrapper {
}
commandCreated = false;
BuildTool buildTool = new BuildTool(env);
- try (OutErr.SystemPatcher systemOutErrPatcher =
- env.getReporter().getOutErr().getSystemPatcher()) {
+ Reporter reporter = env.getReporter();
+ try (OutErr.SystemPatcher systemOutErrPatcher = reporter.getOutErr().getSystemPatcher()) {
Profiler.instance()
.start(
/*profiledTasks=*/ ImmutableSet.of(),
@@ -311,17 +313,25 @@ public class BlazeRuntimeWrapper {
/*includeTargetLabel=*/ false,
/*collectTaskHistograms=*/ true);
+ StoredEventHandler storedEventHandler = new StoredEventHandler();
+ reporter.addHandler(storedEventHandler);
+
// This cannot go into newCommand, because we hook up the EventCollectionApparatus as a
// module, and after that ran, further changes to the apparatus aren't reflected on the
// reporter.
for (BlazeModule module : runtime.getBlazeModules()) {
module.beforeCommand(env);
}
+ reporter.removeHandler(storedEventHandler);
+
EventBus eventBus = env.getEventBus();
for (Object subscriber : eventBusSubscribers) {
eventBus.register(subscriber);
}
+ // Replay events from beforeCommand, just as BlazeCommandDispatcher does.
+ storedEventHandler.replayOn(reporter);
+
env.beforeCommand(InvocationPolicy.getDefaultInstance());
lastRequest = createRequest(env.getCommandName(), targets);
@@ -352,11 +362,11 @@ public class BlazeRuntimeWrapper {
crash != null ? crash.getThrowable() : null,
detailedExitCode,
/*startSuspendCount=*/ 0);
- getSkyframeExecutor().notifyCommandComplete(env.getReporter());
+ getSkyframeExecutor().notifyCommandComplete(reporter);
if (crash != null) {
runtime
.getBugReporter()
- .handleCrash(crash, CrashContext.keepAlive().reportingTo(env.getReporter()));
+ .handleCrash(crash, CrashContext.keepAlive().reportingTo(reporter));
}
}
} finally {
