aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
index cbd8e564ec..453cd7c24b 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java
@@ -367,10 +367,13 @@ public class BlazeCommandDispatcher {
OptionsProvider options = optionsResult.get();
// The initCommand call also records the start time for the timestamp granularity monitor.
- CommandEnvironment env = workspace.initCommand(commandAnnotation);
+ CommandEnvironment env = workspace.initCommand(commandAnnotation, options);
// Record the command's starting time for use by the commands themselves.
env.recordCommandStartTime(firstContactTime);
+ // Temporary: there is one module that outputs events during beforeCommand, but the reporter
+ // isn't setup yet. Add the stored event handler to catch those events.
+ env.getReporter().addHandler(eventHandler);
for (BlazeModule module : runtime.getBlazeModules()) {
try {
module.beforeCommand(env);
@@ -385,6 +388,7 @@ public class BlazeCommandDispatcher {
earlyExitCode = e.getExitCode();
}
}
+ env.getReporter().removeHandler(eventHandler);
// We may only start writing to outErr once we've given the modules the chance to hook into it.
for (BlazeModule module : runtime.getBlazeModules()) {
@@ -502,9 +506,6 @@ public class BlazeCommandDispatcher {
reporter.handle(Event.error(e.getMessage()));
return e.getExitCode().getNumericExitCode();
}
- for (BlazeModule module : runtime.getBlazeModules()) {
- module.handleOptions(options);
- }
env.getEventBus().post(originalCommandLine);
@@ -573,6 +574,16 @@ public class BlazeCommandDispatcher {
// applied the invocation policy.
AtomicReference<OptionsProvider> parsedOptions,
List<String> rcfileNotes) {
+ OptionsParser optionsParser;
+ try {
+ optionsParser = createOptionsParser(command);
+ // We need to set this early so it's not null when we return.
+ parsedOptions.set(optionsParser);
+ } catch (OptionsParser.ConstructionException e) {
+ // This should never happen.
+ throw new IllegalStateException(e);
+ }
+
// The initialization code here was carefully written to parse the options early before we call
// into the BlazeModule APIs, which means we must not generate any output to outErr, return, or
// throw an exception. All the events happening here are instead stored in a temporary event
@@ -584,8 +595,6 @@ public class BlazeCommandDispatcher {
}
try {
- OptionsParser optionsParser = createOptionsParser(command);
-
// TODO(ulfjack): The second parameter is supposed to be the working directory, except that
// the client passes that as part of CommonCommandOptions, and we can't know those until
// after we've parsed them.
@@ -624,10 +633,6 @@ public class BlazeCommandDispatcher {
for (String warning : optionsParser.getWarnings()) {
eventHandler.handle(Event.warn(warning));
}
- parsedOptions.set(optionsParser);
- } catch (OptionsParser.ConstructionException e) {
- // This should never happen.
- throw new IllegalStateException(e);
} catch (OptionsParsingException e) {
eventHandler.handle(Event.error(e.getMessage()));
return ExitCode.COMMAND_LINE_ERROR;