aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/runtime
diff options
context:
space:
mode:
authorGravatar ulfjack <ulfjack@google.com>2017-06-14 10:19:34 +0200
committerGravatar Yun Peng <pcloudy@google.com>2017-06-14 13:17:23 +0200
commit45820abe0e4da93b8f1ce97d4296e7d42f0d617e (patch)
tree71da361a3063af546c8b0c27302bd8ca4d50d676 /src/main/java/com/google/devtools/build/lib/runtime
parent3cc84f2f43b93ff2d909358e5cb32bff16968232 (diff)
Use EventHandler even before we have a Reporter instance
...instead of relying on all the methods to call printErrLn with exactly the right format string. PiperOrigin-RevId: 158951236
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime')
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/BlazeCommandDispatcher.java69
1 files changed, 41 insertions, 28 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 7751ca60e0..e15d202866 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
@@ -31,6 +31,8 @@ import com.google.common.io.Flushables;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.EventHandler;
+import com.google.devtools.build.lib.events.EventKind;
+import com.google.devtools.build.lib.events.PrintingEventHandler;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.runtime.commands.ProjectFileSupport;
import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy;
@@ -157,22 +159,25 @@ public class BlazeCommandDispatcher {
* was called from the output directory and fail if it was.
*/
private ExitCode checkCwdInWorkspace(CommandEnvironment env, Command commandAnnotation,
- String commandName, OutErr outErr) {
+ String commandName, EventHandler eventHandler) {
if (!commandAnnotation.mustRunInWorkspace()) {
return ExitCode.SUCCESS;
}
if (!env.inWorkspace()) {
- outErr.printErrLn(
- "The '" + commandName + "' command is only supported from within a workspace.");
+ eventHandler.handle(
+ Event.error(
+ "The '" + commandName + "' command is only supported from within a workspace."));
return ExitCode.COMMAND_LINE_ERROR;
}
Path workspace = env.getWorkspace();
// TODO(kchodorow): Remove this once spaces are supported.
if (workspace.getPathString().contains(" ")) {
- outErr.printErrLn(runtime.getProductName() + " does not currently work properly from paths "
- + "containing spaces (" + workspace + ").");
+ eventHandler.handle(
+ Event.error(
+ runtime.getProductName() + " does not currently work properly from paths "
+ + "containing spaces (" + workspace + ")."));
return ExitCode.LOCAL_ENVIRONMENTAL_ERROR;
}
@@ -181,21 +186,21 @@ public class BlazeCommandDispatcher {
if (doNotBuild.exists()) {
if (!commandAnnotation.canRunInOutputDirectory()) {
- outErr.printErrLn(getNotInRealWorkspaceError(doNotBuild));
+ eventHandler.handle(Event.error(getNotInRealWorkspaceError(doNotBuild)));
return ExitCode.COMMAND_LINE_ERROR;
} else {
- outErr.printErrLn(
- "WARNING: "
- + runtime.getProductName()
- + " is run from output directory. This is unsound.");
+ eventHandler.handle(
+ Event.warn(
+ runtime.getProductName() + " is run from output directory. This is unsound."));
}
}
return ExitCode.SUCCESS;
}
private ExitCode parseArgsAndConfigs(CommandEnvironment env, OptionsParser optionsParser,
- Command commandAnnotation, List<String> args, List<String> rcfileNotes, OutErr outErr)
- throws OptionsParsingException {
+ Command commandAnnotation, List<String> args, List<String> rcfileNotes,
+ EventHandler eventHandler)
+ throws OptionsParsingException {
Function<String, String> commandOptionSourceFunction =
new Function<String, String>() {
@@ -218,7 +223,7 @@ public class BlazeCommandDispatcher {
// and --rc_source. A no-op if none are provided.
CommonCommandOptions rcFileOptions = optionsParser.getOptions(CommonCommandOptions.class);
List<Pair<String, ListMultimap<String, String>>> optionsMap =
- getOptionsMap(outErr, rcFileOptions.rcSource, rcFileOptions.optionsOverrides,
+ getOptionsMap(eventHandler, rcFileOptions.rcSource, rcFileOptions.optionsOverrides,
runtime.getCommandMap().keySet());
parseOptionsForCommand(rcfileNotes, commandAnnotation, optionsParser, optionsMap, null, null);
@@ -240,11 +245,15 @@ public class BlazeCommandDispatcher {
}
if (!unknownConfigs.isEmpty()) {
if (commonOptions.allowUndefinedConfigs) {
- outErr.printErrLn("WARNING: Config values are not defined in any .rc file: "
- + Joiner.on(", ").join(unknownConfigs));
+ eventHandler.handle(
+ Event.warn(
+ "Config values are not defined in any .rc file: "
+ + Joiner.on(", ").join(unknownConfigs)));
} else {
- outErr.printErrLn("ERROR: Config values are not defined in any .rc file: "
- + Joiner.on(", ").join(unknownConfigs));
+ eventHandler.handle(
+ Event.error(
+ "Config values are not defined in any .rc file: "
+ + Joiner.on(", ").join(unknownConfigs)));
return ExitCode.COMMAND_LINE_ERROR;
}
}
@@ -395,7 +404,8 @@ public class BlazeCommandDispatcher {
LoggingUtil.logToRemote(Level.WARNING, "Unable to delete or open command.log", ioException);
}
- ExitCode result = checkCwdInWorkspace(env, commandAnnotation, commandName, outErr);
+ EventHandler eventHandler = new PrintingEventHandler(outErr, EventKind.ALL_EVENTS);
+ ExitCode result = checkCwdInWorkspace(env, commandAnnotation, commandName, eventHandler);
if (!result.equals(ExitCode.SUCCESS)) {
return result.getNumericExitCode();
}
@@ -407,12 +417,14 @@ public class BlazeCommandDispatcher {
try {
optionsParser = createOptionsParser(command);
} catch (OptionsParser.ConstructionException e) {
- outErr.printErrLn("Internal error while constructing options parser: " + e.getMessage());
+ eventHandler.handle(
+ Event.error("Internal error while constructing options parser: " + e.getMessage()));
return ExitCode.BLAZE_INTERNAL_ERROR.getNumericExitCode();
}
try {
ExitCode parseResult =
- parseArgsAndConfigs(env, optionsParser, commandAnnotation, args, rcfileNotes, outErr);
+ parseArgsAndConfigs(
+ env, optionsParser, commandAnnotation, args, rcfileNotes, eventHandler);
if (!parseResult.equals(ExitCode.SUCCESS)) {
return parseResult.getNumericExitCode();
}
@@ -428,9 +440,9 @@ public class BlazeCommandDispatcher {
optionsPolicyEnforcer.enforce(optionsParser, commandName);
} catch (OptionsParsingException e) {
for (String note : rcfileNotes) {
- outErr.printErrLn("INFO: " + note);
+ eventHandler.handle(Event.info(note));
}
- outErr.printErrLn(e.getMessage());
+ eventHandler.handle(Event.error(e.getMessage()));
return ExitCode.COMMAND_LINE_ERROR.getNumericExitCode();
}
@@ -758,7 +770,7 @@ public class BlazeCommandDispatcher {
*/
@VisibleForTesting
static List<Pair<String, ListMultimap<String, String>>> getOptionsMap(
- OutErr outErr,
+ EventHandler eventHandler,
List<String> rcFiles,
List<CommonCommandOptions.OptionOverride> overrides,
Set<String> validCommands) {
@@ -768,8 +780,8 @@ public class BlazeCommandDispatcher {
ListMultimap<String, String> lastMap = null;
for (CommonCommandOptions.OptionOverride override : overrides) {
if (override.blazeRc < 0 || override.blazeRc >= rcFiles.size()) {
- outErr.printErrLn("WARNING: inconsistency in generated command line "
- + "args. Ignoring bogus argument\n");
+ eventHandler.handle(
+ Event.warn("inconsistency in generated command line args. Ignoring bogus argument\n"));
continue;
}
String rcFile = rcFiles.get(override.blazeRc);
@@ -780,9 +792,10 @@ public class BlazeCommandDispatcher {
command = command.substring(0, index);
}
if (!validCommands.contains(command) && !command.equals("common")) {
- outErr.printErrLn("WARNING: while reading option defaults file '"
- + rcFile + "':\n"
- + " invalid command name '" + override.command + "'.");
+ eventHandler.handle(
+ Event.warn(
+ "while reading option defaults file '" + rcFile + "':\n"
+ + " invalid command name '" + override.command + "'."));
continue;
}