diff options
author | lberki <lberki@google.com> | 2018-02-05 07:59:13 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-05 08:01:17 -0800 |
commit | 4741aa83145fd2d3ab0599314f7732c5b80977bd (patch) | |
tree | b33310e226d9733ae0e538e433a54e337d6a67ed /src/main/java/com/google/devtools/build/lib/runtime/commands | |
parent | 03ad9155f765fcdc0ccf4aae30a4def9914ea0b4 (diff) |
Add a "direct" mode to "blaze run" that makes the process being run a direct
child of the process where the Blaze client itself was run.
Limitations:
- Untested on Windows; it should work because ExecuteProgram() is implemented there, too, but since Windows doesn't support exec(), there is at least one process in between
Progress towards #2815.
RELNOTES[NEW]: The new "--direct_run" flag on "blaze run" lets one run interactive binaries.
PiperOrigin-RevId: 184528845
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/runtime/commands')
15 files changed, 152 insertions, 97 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java index a02c991839..4803aaf115 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/BuildCommand.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.exec.local.LocalExecutionOptions; import com.google.devtools.build.lib.pkgcache.LoadingOptions; import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -62,7 +63,7 @@ public final class BuildCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { BlazeRuntime runtime = env.getRuntime(); List<String> targets = ProjectFileSupport.getTargets(runtime.getProjectFileProvider(), options); @@ -71,6 +72,7 @@ public final class BuildCommand implements BlazeCommand { runtime.getStartupOptionsProvider(), targets, env.getReporter().getOutErr(), env.getCommandId(), env.getCommandStartTime()); - return new BuildTool(env).processRequest(request, null).getExitCondition(); + ExitCode exitCode = new BuildTool(env).processRequest(request, null).getExitCondition(); + return BlazeCommandResult.exitCode(exitCode); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java index c2951f1d28..d17b281fbb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CanonicalizeCommand.java @@ -17,6 +17,7 @@ import com.google.common.base.Joiner; import com.google.common.collect.ImmutableList; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeCommandUtils; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; @@ -127,7 +128,7 @@ public final class CanonicalizeCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { BlazeRuntime runtime = env.getRuntime(); Options canonicalizeOptions = options.getOptions(Options.class); String commandName = canonicalizeOptions.forCommand; @@ -135,7 +136,7 @@ public final class CanonicalizeCommand implements BlazeCommand { if (command == null) { env.getReporter().handle(Event.error("Not a valid command: '" + commandName + "' (should be one of " + Joiner.on(", ").join(runtime.getCommandMap().keySet()) + ")")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } Collection<Class<? extends OptionsBase>> optionsClasses = ImmutableList.<Class<? extends OptionsBase>>builder() @@ -175,9 +176,9 @@ public final class CanonicalizeCommand implements BlazeCommand { } } catch (OptionsParsingException e) { env.getReporter().handle(Event.error(e.getMessage())); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java index 721a0644fc..bf88f451a0 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CleanCommand.java @@ -21,6 +21,7 @@ import com.google.devtools.build.lib.buildtool.OutputDirectoryLinksUtils; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.ShutdownBlazeServerException; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.shell.CommandException; @@ -127,7 +128,7 @@ public final class CleanCommand implements BlazeCommand { private static final Logger logger = Logger.getLogger(CleanCommand.class.getName()); @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) throws ShutdownBlazeServerException { Options cleanOptions = options.getOptions(Options.class); boolean async = cleanOptions.async; @@ -165,16 +166,16 @@ public final class CleanCommand implements BlazeCommand { .getOptions(BuildRequestOptions.class) .getSymlinkPrefix(env.getRuntime().getProductName()); actuallyClean(env, env.getOutputBase(), cleanOptions.expunge, async, symlinkPrefix); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } catch (IOException e) { env.getReporter().handle(Event.error(e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } catch (CommandException | ExecException e) { env.getReporter().handle(Event.error(e.getMessage())); - return ExitCode.RUN_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE); } catch (InterruptedException e) { env.getReporter().handle(Event.error("clean interrupted")); - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } } @@ -265,7 +266,7 @@ public final class CleanCommand implements BlazeCommand { // shutdown on expunge cleans if (expunge) { - throw new ShutdownBlazeServerException(0); + throw new ShutdownBlazeServerException(ExitCode.SUCCESS); } System.gc(); } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java index b99002ad9c..1aa6c8dc4e 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/CqueryCommand.java @@ -25,6 +25,7 @@ import com.google.devtools.build.lib.query2.engine.QueryException; import com.google.devtools.build.lib.query2.engine.QueryExpression; import com.google.devtools.build.lib.query2.engine.QueryParser; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -66,13 +67,13 @@ public final class CqueryCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { if (options.getResidue().isEmpty()) { env.getReporter() .handle( Event.error( "Missing query expression. Use the 'help cquery' command for syntax and help.")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } String query = Joiner.on(' ').join(options.getResidue()); HashMap<String, QueryFunction> functions = new HashMap<>(); @@ -85,7 +86,7 @@ public final class CqueryCommand implements BlazeCommand { } catch (QueryException e) { env.getReporter() .handle(Event.error("Error while parsing '" + query + "': " + e.getMessage())); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } List<String> topLevelTargets = options.getOptions(CommonQueryOptions.class).universeScope; @@ -104,6 +105,7 @@ public final class CqueryCommand implements BlazeCommand { env.getReporter().getOutErr(), env.getCommandId(), env.getCommandStartTime()); - return new BuildTool(env).processRequest(request, null, expr).getExitCondition(); + ExitCode exitCode = new BuildTool(env).processRequest(request, null, expr).getExitCondition(); + return BlazeCommandResult.exitCode(exitCode); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java index 96b3149463..6f92ae0a06 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/DumpCommand.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.profiler.memory.AllocationTracker; import com.google.devtools.build.lib.profiler.memory.AllocationTracker.RuleBytes; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeCommandUtils; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.BlazeWorkspace; @@ -166,7 +167,7 @@ public class DumpCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) {} @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { BlazeRuntime runtime = env.getRuntime(); DumpOptions dumpOptions = options.getOptions(DumpOptions.class); @@ -190,7 +191,7 @@ public class DumpCommand implements BlazeCommand { getClass(), optionList, categories, OptionsParser.HelpVerbosity.LONG, runtime.getProductName())); - return ExitCode.ANALYSIS_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.ANALYSIS_FAILURE); } PrintStream out = new PrintStream(env.getReporter().getOutErr().getOutputStream()); try { @@ -241,7 +242,7 @@ public class DumpCommand implements BlazeCommand { out.println(); } - return success ? ExitCode.SUCCESS : ExitCode.ANALYSIS_FAILURE; + return BlazeCommandResult.exitCode(success ? ExitCode.SUCCESS : ExitCode.ANALYSIS_FAILURE); } finally { out.flush(); diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java index 1e163e295e..6f47e3d1fb 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/HelpCommand.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.packages.RuleClass; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeCommandUtils; import com.google.devtools.build.lib.runtime.BlazeModule; import com.google.devtools.build.lib.runtime.BlazeRuntime; @@ -176,7 +177,7 @@ public final class HelpCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) {} @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { env.getEventBus().post(new NoBuildEvent()); BlazeRuntime runtime = env.getRuntime(); @@ -185,11 +186,11 @@ public final class HelpCommand implements BlazeCommand { if (options.getResidue().isEmpty()) { emitBlazeVersionInfo(outErr, runtime.getProductName()); emitGenericHelp(outErr, runtime); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } if (options.getResidue().size() != 1) { env.getReporter().handle(Event.error("You must specify exactly one command")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } String helpSubject = options.getResidue().get(0); String productName = runtime.getProductName(); @@ -203,7 +204,7 @@ public final class HelpCommand implements BlazeCommand { runtime, getDeprecatedOptionCategoriesDescriptions(productName), helpOptions.useNewCategoryEnum); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); case "target-syntax": emitBlazeVersionInfo(outErr, runtime.getProductName()); emitTargetSyntaxHelp( @@ -212,19 +213,19 @@ public final class HelpCommand implements BlazeCommand { productName, helpOptions.useNewCategoryEnum); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); case "info-keys": emitInfoKeysHelp(env, outErr); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); case "completion": emitCompletionHelp(runtime, outErr); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); case "flags-as-proto": emitFlagsAsProtoHelp(runtime, outErr); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); case "everything-as-html": new HtmlEmitter(runtime, helpOptions.useNewCategoryEnum).emit(outErr); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); default: // fall out } @@ -236,11 +237,11 @@ public final class HelpCommand implements BlazeCommand { // There is a rule with a corresponding name outErr.printOut( BlazeRuleHelpPrinter.getRuleDoc(helpSubject, runtime.getProductName(), provider)); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } else { env.getReporter().handle(Event.error( null, "'" + helpSubject + "' is neither a command nor a build rule")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } } emitBlazeVersionInfo(outErr, productName); @@ -254,7 +255,7 @@ public final class HelpCommand implements BlazeCommand { productName, helpOptions.useNewCategoryEnum)); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } private void emitBlazeVersionInfo(OutErr outErr, String productName) { diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java index ca32232cc0..e10e5735e1 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoCommand.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.analysis.config.BuildConfiguration; import com.google.devtools.build.lib.analysis.config.InvalidConfigurationException; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -101,7 +102,8 @@ public class InfoCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) { } @Override - public ExitCode exec(final CommandEnvironment env, final OptionsProvider optionsProvider) { + public BlazeCommandResult exec( + final CommandEnvironment env, final OptionsProvider optionsProvider) { final BlazeRuntime runtime = env.getRuntime(); env.getReporter().switchToAnsiAllowingHandler(); Options infoOptions = optionsProvider.getOptions(Options.class); @@ -152,7 +154,7 @@ public class InfoCommand implements BlazeCommand { List<String> residue = optionsProvider.getResidue(); if (residue.size() > 1) { env.getReporter().handle(Event.error("at most one key may be specified")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } String key = residue.size() == 1 ? residue.get(0) : null; @@ -163,14 +165,14 @@ public class InfoCommand implements BlazeCommand { value = items.get(key).get(configurationSupplier, env); } else { env.getReporter().handle(Event.error("unknown key: '" + key + "'")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } try { outErr.getOutputStream().write(value); outErr.getOutputStream().flush(); } catch (IOException e) { env.getReporter().handle(Event.error("Cannot write info block: " + e.getMessage())); - return ExitCode.ANALYSIS_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.ANALYSIS_FAILURE); } } else { // print them all configurationSupplier.get(); // We'll need this later anyway @@ -184,15 +186,15 @@ public class InfoCommand implements BlazeCommand { } } } catch (AbruptExitException e) { - return e.getExitCode(); + return BlazeCommandResult.exitCode(e.getExitCode()); } catch (ExitCausingRuntimeException e) { - return e.getExitCode(); + return BlazeCommandResult.exitCode(e.getExitCode()); } catch (IOException e) { - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } catch (InterruptedException e) { - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } static Map<String, InfoItem> getHardwiredInfoItemMap(OptionsProvider commandOptions, diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java index b735107e79..7ad512acb6 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/LicenseCommand.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.runtime.commands; import com.google.common.io.Files; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; @@ -52,7 +53,7 @@ public class LicenseCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { env.getEventBus().post(new NoBuildEvent()); OutErr outErr = env.getReporter().getOutErr(); @@ -81,7 +82,7 @@ public class LicenseCommand implements BlazeCommand { printJavaLicenseFiles(outErr, bundledJre); } - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } private static void printJavaLicenseFiles(OutErr outErr, Path bundledJdkOrJre) { diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java index 930575f674..6b4b266076 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/PrintActionCommand.java @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.pkgcache.LoadingOptions; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -99,7 +100,7 @@ public final class PrintActionCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { LoadingOptions loadingOptions = options.getOptions(LoadingOptions.class); @@ -107,7 +108,7 @@ public final class PrintActionCommand implements BlazeCommand { PrintActionRunner runner = new PrintActionRunner(loadingOptions.compileOneDependency, options, env.getReporter().getOutErr(), options.getResidue(), Sets.newHashSet(printActionOptions.printActionMnemonics)); - return runner.printActionsForTargets(env); + return BlazeCommandResult.exitCode(runner.printActionsForTargets(env)); } /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java index 951e5c490b..f39f0054b3 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProfileCommand.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.profiler.statistics.MultiProfileStatistics; import com.google.devtools.build.lib.profiler.statistics.PhaseStatistics; import com.google.devtools.build.lib.profiler.statistics.PhaseSummaryStatistics; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; @@ -212,7 +213,7 @@ public final class ProfileCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) {} @Override - public ExitCode exec(final CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(final CommandEnvironment env, OptionsProvider options) { ProfileOptions opts = options.getOptions(ProfileOptions.class); @@ -325,7 +326,7 @@ public final class ProfileCommand implements BlazeCommand { } } } - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java index d34ae7b4a5..75b20fea68 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/QueryCommand.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.query2.output.OutputFormatter.StreamedForma import com.google.devtools.build.lib.query2.output.QueryOptions; import com.google.devtools.build.lib.query2.output.QueryOutputUtils; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -85,7 +86,7 @@ public final class QueryCommand implements BlazeCommand { * (only when --keep_going is in effect.) */ @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { BlazeRuntime runtime = env.getRuntime(); QueryOptions queryOptions = options.getOptions(QueryOptions.class); @@ -93,10 +94,10 @@ public final class QueryCommand implements BlazeCommand { env.setupPackageCache(options, runtime.getDefaultsPackageContent()); } catch (InterruptedException e) { env.getReporter().handle(Event.error("query interrupted")); - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } catch (AbruptExitException e) { env.getReporter().handle(Event.error(null, "Unknown error: " + e.getMessage())); - return e.getExitCode(); + return BlazeCommandResult.exitCode(e.getExitCode()); } String query; @@ -104,7 +105,7 @@ public final class QueryCommand implements BlazeCommand { if (!queryOptions.queryFile.isEmpty()) { env.getReporter() .handle(Event.error("Command-line query and --query_file cannot both be specified")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } query = Joiner.on(' ').join(options.getResidue()); } else if (!queryOptions.queryFile.isEmpty()) { @@ -115,13 +116,13 @@ public final class QueryCommand implements BlazeCommand { } catch (IOException e) { env.getReporter() .handle(Event.error("I/O error reading from " + residuePath.getPathString())); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } } else { env.getReporter().handle(Event.error(String.format( "missing query expression. Type '%s help query' for syntax and help", runtime.getProductName()))); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } Iterable<OutputFormatter> formatters = runtime.getQueryOutputFormatters(); @@ -131,7 +132,7 @@ public final class QueryCommand implements BlazeCommand { env.getReporter().handle(Event.error( String.format("Invalid output format '%s'. Valid values are: %s", queryOptions.outputFormat, OutputFormatter.formatterNames(formatters)))); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } Set<Setting> settings = queryOptions.toSettings(); @@ -151,14 +152,14 @@ public final class QueryCommand implements BlazeCommand { } catch (QueryException e) { env.getReporter() .handle(Event.error(null, "Error while parsing '" + query + "': " + e.getMessage())); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } try { formatter.verifyCompatible(queryEnv, expr); } catch (QueryException e) { env.getReporter().handle(Event.error(e.getMessage())); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } expr = queryEnv.transformParsedQuery(expr); @@ -194,21 +195,21 @@ public final class QueryCommand implements BlazeCommand { // TODO(bazel-team): this is a kludge to fix a bug observed in the wild. We should make // sure no null error messages ever get in. .handle(Event.error(e.getMessage() == null ? e.toString() : e.getMessage())); - return ExitCode.ANALYSIS_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.ANALYSIS_FAILURE); } catch (InterruptedException e) { catastrophe = false; IOException ioException = callback.getIoException(); if (ioException == null || ioException instanceof ClosedByInterruptException) { env.getReporter().handle(Event.error("query interrupted")); - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } else { env.getReporter().handle(Event.error("I/O error: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } } catch (IOException e) { catastrophe = false; env.getReporter().handle(Event.error("I/O error: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } finally { if (!catastrophe) { try { @@ -216,7 +217,7 @@ public final class QueryCommand implements BlazeCommand { } catch (IOException e) { env.getReporter().handle( Event.error("Failed to flush query results: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } } } @@ -236,17 +237,17 @@ public final class QueryCommand implements BlazeCommand { queryOptions.aspectDeps.createResolver(env.getPackageManager(), env.getReporter())); } catch (ClosedByInterruptException | InterruptedException e) { env.getReporter().handle(Event.error("query interrupted")); - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } catch (IOException e) { env.getReporter().handle(Event.error("I/O error: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } finally { try { out.flush(); } catch (IOException e) { env.getReporter().handle( Event.error("Failed to flush query results: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } } } @@ -258,7 +259,7 @@ public final class QueryCommand implements BlazeCommand { ExitCode exitCode = result.getSuccess() ? ExitCode.SUCCESS : ExitCode.PARTIAL_ANALYSIS_FAILURE; env.getEventBus() .post(new NoBuildRequestFinishedEvent(exitCode, runtime.getClock().currentTimeMillis())); - return exitCode; + return BlazeCommandResult.exitCode(exitCode); } /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java index 921fd7dda0..8535616a4b 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java @@ -46,9 +46,12 @@ import com.google.devtools.build.lib.packages.Target; import com.google.devtools.build.lib.packages.TargetUtils; import com.google.devtools.build.lib.pkgcache.LoadingFailedException; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.runtime.ProcessWrapperUtil; +import com.google.devtools.build.lib.server.CommandProtos.EnvironmentVariable; +import com.google.devtools.build.lib.server.CommandProtos.ExecRequest; import com.google.devtools.build.lib.shell.AbnormalTerminationException; import com.google.devtools.build.lib.shell.BadExitStatusException; import com.google.devtools.build.lib.shell.CommandException; @@ -71,11 +74,13 @@ import com.google.devtools.common.options.OptionEffectTag; import com.google.devtools.common.options.OptionsBase; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsProvider; +import com.google.protobuf.ByteString; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Map; /** * Builds and run a target with the given command line arguments. @@ -92,9 +97,21 @@ import java.util.List; completion = "label-bin", binaryStdErr = true) public class RunCommand implements BlazeCommand { - public static class RunOptions extends OptionsBase { @Option( + name = "direct_run", + category = "run", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS, + effectTags = {OptionEffectTag.EXECUTION}, + help = "If set, the 'run' command will execute the binary to be executed in the terminal " + + "where the command was called. Otherwise, it'll be executed as a child of the server " + + "process. If set, the binary will have access to direct terminal I/O and the command " + + "lock will not be held during its execution. This makes it possible to run other " + + "commands in parallel.") + public boolean direct; + + @Option( name = "script_path", category = "run", defaultValue = "null", @@ -139,7 +156,7 @@ public class RunCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { RunOptions runOptions = options.getOptions(RunOptions.class); // This list should look like: ["//executable:target", "arg1", "arg2"] List<String> targetAndArgs = options.getResidue(); @@ -147,7 +164,7 @@ public class RunCommand implements BlazeCommand { // The user must at the least specify an executable target. if (targetAndArgs.isEmpty()) { env.getReporter().handle(Event.error("Must specify a target to run")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } String targetString = targetAndArgs.get(0); List<String> runTargetArgs = targetAndArgs.subList(1, targetAndArgs.size()); @@ -172,7 +189,7 @@ public class RunCommand implements BlazeCommand { if (!result.getSuccess()) { env.getReporter().handle(Event.error("Build failed. Not running target")); - return result.getExitCondition(); + return BlazeCommandResult.exitCode(result.getExitCondition()); } // Make sure that we have exactly 1 built target (excluding --run_under), @@ -187,25 +204,25 @@ public class RunCommand implements BlazeCommand { int maxTargets = runUnder != null && runUnder.getLabel() != null ? 2 : 1; if (targetsBuilt.size() > maxTargets) { env.getReporter().handle(Event.error(SINGLE_TARGET_MESSAGE)); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } for (ConfiguredTarget target : targetsBuilt) { ExitCode targetValidation = fullyValidateTarget(env, target); if (!targetValidation.equals(ExitCode.SUCCESS)) { - return targetValidation; + return BlazeCommandResult.exitCode(targetValidation); } if (runUnder != null && target.getLabel().equals(runUnder.getLabel())) { if (runUnderTarget != null) { env.getReporter().handle(Event.error( null, "Can't identify the run_under target from multiple options?")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } runUnderTarget = target; } else if (targetToRun == null) { targetToRun = target; } else { env.getReporter().handle(Event.error(SINGLE_TARGET_MESSAGE)); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } } } @@ -215,7 +232,7 @@ public class RunCommand implements BlazeCommand { } if (targetToRun == null) { env.getReporter().handle(Event.error(NO_TARGET_MESSAGE)); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } Path executablePath = Preconditions.checkNotNull( @@ -231,13 +248,13 @@ public class RunCommand implements BlazeCommand { env.getReporter() .handle( Event.error("--nobuild_runfile_manifests is incompatible with the \"run\" command")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } try { workingDir = ensureRunfilesBuilt(env, targetToRun); } catch (CommandException e) { env.getReporter().handle(Event.error("Error creating runfiles: " + e.getMessage())); - return ExitCode.LOCAL_ENVIRONMENTAL_ERROR; + return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); } List<String> args = Lists.newArrayList(); @@ -250,7 +267,7 @@ public class RunCommand implements BlazeCommand { Iterables.addAll(args, targetArgs.arguments()); } catch (CommandLineExpansionException e) { env.getReporter().handle(Event.error("Could not expand target command line: " + e)); - return ExitCode.ANALYSIS_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.ANALYSIS_FAILURE); } } args.addAll(runTargetArgs); @@ -271,7 +288,8 @@ public class RunCommand implements BlazeCommand { // process-wrapper does not work on Windows (nor is it necessary), so don't use it // on that platform. Also we skip it when writing the command-line to a file instead // of executing it directly. - if (OS.getCurrent() != OS.WINDOWS && runOptions.scriptPath == null) { + if (OS.getCurrent() != OS.WINDOWS && runOptions.scriptPath == null + && !runOptions.direct) { Preconditions.checkState(ProcessWrapperUtil.isSupported(env), "process-wraper not found in embedded tools"); cmdLine.add(ProcessWrapperUtil.getProcessWrapper(env).getPathString()); @@ -317,19 +335,38 @@ public class RunCommand implements BlazeCommand { CommandDescriptionForm.COMPLETE_UNISOLATED, cmdLine, null, workingDir.getPathString()); if (writeScript(env, runOptions.scriptPath, unisolatedCommand)) { - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } else { - return ExitCode.RUN_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE); } } env.getReporter().handle(Event.info( null, "Running command line: " + ShellEscaper.escapeJoinAll(prettyCmdLine))); - com.google.devtools.build.lib.shell.Command command = new CommandBuilder() - .addArgs(cmdLine).setEnv(env.getClientEnv()).setWorkingDir(workingDir).build(); + if (runOptions.direct) { + ExecRequest.Builder execDescription = ExecRequest.newBuilder() + .setWorkingDirectory( + ByteString.copyFrom(workingDir.getPathString(), StandardCharsets.ISO_8859_1)); + + for (String arg : cmdLine) { + execDescription.addArgv(ByteString.copyFrom(arg, StandardCharsets.ISO_8859_1)); + } + + for (Map.Entry<String, String> variable : env.getClientEnv().entrySet()) { + execDescription.addEnvironmentVariable(EnvironmentVariable.newBuilder() + .setName(ByteString.copyFrom(variable.getKey(), StandardCharsets.ISO_8859_1)) + .setValue(ByteString.copyFrom(variable.getValue(), StandardCharsets.ISO_8859_1)) + .build()); + } + + return BlazeCommandResult.execute(execDescription.build()); + } try { + com.google.devtools.build.lib.shell.Command command = new CommandBuilder() + .addArgs(cmdLine).setEnv(env.getClientEnv()).setWorkingDir(workingDir).build(); + // Restore a raw EventHandler if it is registered. This allows for blaze run to produce the // actual output of the command being run even if --color=no is specified. env.getReporter().switchToAnsiAllowingHandler(); @@ -341,19 +378,19 @@ public class RunCommand implements BlazeCommand { .execute(outErr.getOutputStream(), outErr.getErrorStream()) .getTerminationStatus() .getExitCode(); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } catch (BadExitStatusException e) { String message = "Non-zero return code '" + e.getResult().getTerminationStatus().getExitCode() + "' from command: " + e.getMessage(); env.getReporter().handle(Event.error(message)); - return ExitCode.RUN_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE); } catch (AbnormalTerminationException e) { // The process was likely terminated by a signal in this case. - return ExitCode.INTERRUPTED; + return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED); } catch (CommandException e) { env.getReporter().handle(Event.error("Error running program: " + e.getMessage())); - return ExitCode.RUN_FAILURE; + return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE); } } @@ -480,7 +517,8 @@ public class RunCommand implements BlazeCommand { * Performs all available validation checks on an individual target. * * @param configuredTarget ConfiguredTarget to validate - * @return ExitCode.SUCCESS if all checks succeeded, otherwise a different error code. + * @return BlazeCommandResult.exitCode(ExitCode.SUCCESS) if all checks succeeded, otherwise a + * different error code. * @throws IllegalStateException if unable to find a target from the package manager. */ private ExitCode fullyValidateTarget(CommandEnvironment env, ConfiguredTarget configuredTarget) { diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ShutdownCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ShutdownCommand.java index 09423c0b56..f242c9d7ce 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ShutdownCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ShutdownCommand.java @@ -15,6 +15,7 @@ package com.google.devtools.build.lib.runtime.commands; import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.ShutdownBlazeServerException; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; @@ -56,7 +57,7 @@ public final class ShutdownCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) {} @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) throws ShutdownBlazeServerException { int limit = options.getOptions(Options.class).heapSizeLimit; @@ -69,9 +70,9 @@ public final class ShutdownCommand implements BlazeCommand { if (limit == 0 || Runtime.getRuntime().totalMemory() > limit * 1000L * 1000) { - throw new ShutdownBlazeServerException(0); + throw new ShutdownBlazeServerException(ExitCode.SUCCESS); } - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } } diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java index 1e3f61a97a..5887aa59da 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/TestCommand.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.exec.TestStrategy.TestOutputFormat; import com.google.devtools.build.lib.runtime.AggregatingTestListener; import com.google.devtools.build.lib.runtime.BlazeCommand; import com.google.devtools.build.lib.runtime.BlazeCommandEventHandler; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.BlazeRuntime; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; @@ -81,7 +82,7 @@ public class TestCommand implements BlazeCommand { } @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { TestOutputFormat testOutput = options.getOptions(ExecutionOptions.class).testOutput; if (testOutput == TestStrategy.TestOutputFormat.STREAMED) { env.getReporter().handle(Event.warn( @@ -105,7 +106,7 @@ public class TestCommand implements BlazeCommand { return doTest(env, options, testListener); } - private ExitCode doTest(CommandEnvironment env, + private BlazeCommandResult doTest(CommandEnvironment env, OptionsProvider options, AggregatingTestListener testListener) { BlazeRuntime runtime = env.getRuntime(); @@ -134,7 +135,7 @@ public class TestCommand implements BlazeCommand { ExitCode exitCode = buildResult.getSuccess() ? ExitCode.PARSING_FAILURE : buildResult.getExitCondition(); env.getEventBus().post(new TestingCompleteEvent(exitCode, buildResult.getStopTime())); - return exitCode; + return BlazeCommandResult.exitCode(exitCode); } // TODO(bazel-team): the check above shadows NO_TESTS_FOUND, but switching the conditions breaks // more tests @@ -146,7 +147,7 @@ public class TestCommand implements BlazeCommand { buildResult.getSuccess() ? ExitCode.NO_TESTS_FOUND : buildResult.getExitCondition(); env.getEventBus() .post(new NoTestsFound(exitCode, env.getRuntime().getClock().currentTimeMillis())); - return exitCode; + return BlazeCommandResult.exitCode(exitCode); } boolean buildSuccess = buildResult.getSuccess(); @@ -165,7 +166,7 @@ public class TestCommand implements BlazeCommand { ? (testSuccess ? ExitCode.SUCCESS : ExitCode.TESTS_FAILED) : buildResult.getExitCondition(); env.getEventBus().post(new TestingCompleteEvent(exitCode, buildResult.getStopTime())); - return exitCode; + return BlazeCommandResult.exitCode(exitCode); } /** diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/VersionCommand.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/VersionCommand.java index eff8700248..729c3b7c25 100644 --- a/src/main/java/com/google/devtools/build/lib/runtime/commands/VersionCommand.java +++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/VersionCommand.java @@ -17,6 +17,7 @@ import com.google.devtools.build.lib.analysis.BlazeVersionInfo; import com.google.devtools.build.lib.analysis.NoBuildEvent; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.runtime.BlazeCommand; +import com.google.devtools.build.lib.runtime.BlazeCommandResult; import com.google.devtools.build.lib.runtime.Command; import com.google.devtools.build.lib.runtime.CommandEnvironment; import com.google.devtools.build.lib.util.ExitCode; @@ -38,14 +39,14 @@ public final class VersionCommand implements BlazeCommand { public void editOptions(OptionsParser optionsParser) {} @Override - public ExitCode exec(CommandEnvironment env, OptionsProvider options) { + public BlazeCommandResult exec(CommandEnvironment env, OptionsProvider options) { BlazeVersionInfo info = BlazeVersionInfo.instance(); if (info.getSummary() == null) { env.getReporter().handle(Event.error("Version information not available")); - return ExitCode.COMMAND_LINE_ERROR; + return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR); } env.getEventBus().post(new NoBuildEvent()); env.getReporter().getOutErr().printOutLn(info.getSummary()); - return ExitCode.SUCCESS; + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); } } |