aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--site/docs/user-manual.html13
-rw-r--r--src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java116
3 files changed, 34 insertions, 121 deletions
diff --git a/site/docs/user-manual.html b/site/docs/user-manual.html
index 3b28c49634..6d93e7dca1 100644
--- a/site/docs/user-manual.html
+++ b/site/docs/user-manual.html
@@ -3001,11 +3001,6 @@ Examples:
</pre>
<p>
- Bazel closes stdin, so you can't use <code>bazel run</code>
- if you want to start an interactive program or pipe data to it.
-</p>
-
-<p>
Note the use of the <code>--</code>. This is needed so that Bazel
does not interpret <code>--arg1</code> and <code>--arg2</code> as
Bazel options, but rather as part of the command line for running the binary.
@@ -3027,10 +3022,10 @@ Examples:
<p>
<code>bazel run</code> can also execute test binaries, which has the effect of
-running the test, but without the setup documented on the page
-<a href='test-encyclopedia.html'>Writing Tests</a>, so that the test runs
-in an environment closer to the current shell environment. Note that none of the
---test_* arguments have an effect when running a test in this manner.
+ running the test in a close approximation of the environment described at
+ <a href='test-encyclopedia.html'>Writing Tests</a>. Note that none of the
+ <code>--test_*</code>code> arguments have an effect when running a test in this manner except
+ <code>--test_arg</code> .
</p>
<h2 id='query'>Querying the dependency graph with Bazel</h2>
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
index 865a521942..0f333e90e0 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/BazelRulesModule.java
@@ -14,6 +14,7 @@
package com.google.devtools.build.lib.bazel.rules;
+import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.config.BuildOptions;
@@ -23,14 +24,33 @@ import com.google.devtools.build.lib.rules.cpp.FdoSupportFunction;
import com.google.devtools.build.lib.rules.cpp.FdoSupportValue;
import com.google.devtools.build.lib.runtime.BlazeModule;
import com.google.devtools.build.lib.runtime.BlazeRuntime;
+import com.google.devtools.build.lib.runtime.Command;
import com.google.devtools.build.lib.runtime.WorkspaceBuilder;
import com.google.devtools.build.lib.util.ResourceFileLoader;
+import com.google.devtools.common.options.Option;
+import com.google.devtools.common.options.OptionDocumentationCategory;
+import com.google.devtools.common.options.OptionEffectTag;
+import com.google.devtools.common.options.OptionMetadataTag;
+import com.google.devtools.common.options.OptionsBase;
import java.io.IOException;
/**
* Module implementing the rule set of Bazel.
*/
public class BazelRulesModule extends BlazeModule {
+ /** This is where deprecated options go to die. */
+ public static class GraveyardOptions extends OptionsBase {
+ @Deprecated
+ @Option(
+ name = "direct_run",
+ defaultValue = "true",
+ documentationCategory = OptionDocumentationCategory.UNDOCUMENTED,
+ effectTags = {OptionEffectTag.UNKNOWN},
+ metadataTags = {OptionMetadataTag.DEPRECATED},
+ help = "Deprecated no-op.")
+ public boolean directRun;
+ }
+
@Override
public void initializeRuleClasses(ConfiguredRuleClassProvider.Builder builder) {
builder.setToolsRepository(BazelRuleClassProvider.TOOLS_REPOSITORY);
@@ -60,4 +80,10 @@ public class BazelRulesModule extends BlazeModule {
return DefaultBuildOptionsForDiffing.getDefaultBuildOptionsForFragments(
blazeRuntime.getRuleClassProvider().getConfigurationOptions());
}
+
+ @Override
+ public Iterable<Class<? extends OptionsBase>> getCommandOptions(Command command) {
+ return "build".equals(command.name())
+ ? ImmutableList.of(GraveyardOptions.class) : ImmutableList.of();
+ }
}
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 5670569d3d..369b0be2cc 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
@@ -37,7 +37,6 @@ 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.buildtool.OutputDirectoryLinksUtils;
-import com.google.devtools.build.lib.buildtool.TargetValidator;
import com.google.devtools.build.lib.events.Event;
import com.google.devtools.build.lib.events.Reporter;
import com.google.devtools.build.lib.exec.ExecutionOptions;
@@ -58,19 +57,14 @@ import com.google.devtools.build.lib.runtime.BlazeCommandResult;
import com.google.devtools.build.lib.runtime.BlazeServerStartupOptions;
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;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.util.CommandBuilder;
import com.google.devtools.build.lib.util.CommandDescriptionForm;
import com.google.devtools.build.lib.util.CommandFailureUtils;
import com.google.devtools.build.lib.util.ExitCode;
import com.google.devtools.build.lib.util.FileType;
-import com.google.devtools.build.lib.util.OS;
import com.google.devtools.build.lib.util.OptionsUtils;
import com.google.devtools.build.lib.util.ShellEscaper;
import com.google.devtools.build.lib.util.io.OutErr;
@@ -121,18 +115,6 @@ public class RunCommand implements BlazeCommand {
public boolean asTest;
@Option(
- name = "direct_run",
- defaultValue = "true",
- 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",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
@@ -174,13 +156,9 @@ public class RunCommand implements BlazeCommand {
@VisibleForTesting // productionVisibility = Visibility.PRIVATE
protected BuildResult processRequest(final CommandEnvironment env, BuildRequest request) {
- return new BuildTool(env).processRequest(request, new TargetValidator() {
- @Override
- public void validateTargets(Collection<Target> targets, boolean keepGoing)
- throws LoadingFailedException {
- RunCommand.this.validateTargets(env.getReporter(), targets, keepGoing);
- }
- });
+ return new BuildTool(env).processRequest(request,
+ (Collection<Target> targets, boolean keepGoing) ->
+ RunCommand.this.validateTargets(env.getReporter(), targets, keepGoing));
}
@Override
@@ -210,83 +188,6 @@ public class RunCommand implements BlazeCommand {
return args;
}
- private BlazeCommandResult runTargetUnderServer(CommandEnvironment env,
- ConfiguredTarget targetToRun, PathFragment shellExecutable,
- ConfiguredTarget runUnderTarget, Path workingDir, List<String> commandLineArgs) {
- RunOptions runOptions = env.getOptions().getOptions(RunOptions.class);
- List<String> args = computeArgs(env, targetToRun, commandLineArgs);
- if (args == null) {
- return BlazeCommandResult.exitCode(ExitCode.ANALYSIS_FAILURE);
- }
-
- // We now have a unique executable ready to be run.
- //
- // We build up two different versions of the command to run: one with an absolute path, which
- // we'll actually run, and a prettier one with the long absolute path to the executable
- // replaced with a shorter relative path that uses the symlinks in the workspace.
- List<String> cmdLine = new ArrayList<>();
- // 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) {
- Preconditions.checkState(
- ProcessWrapperUtil.isSupported(env), "process-wrapper not found in embedded tools");
- cmdLine.add(ProcessWrapperUtil.getProcessWrapper(env).getPathString());
- }
- List<String> prettyCmdLine = new ArrayList<>();
- constructCommandLine(cmdLine, prettyCmdLine, env, shellExecutable,
- targetToRun, runUnderTarget, args);
-
- // Add a newline between the blaze output and the binary's output.
- env.getReporter().getOutErr().printErrLn("");
-
- if (runOptions.scriptPath != null) {
- String unisolatedCommand = CommandFailureUtils.describeCommand(
- CommandDescriptionForm.COMPLETE_UNISOLATED,
- cmdLine, null, workingDir.getPathString());
- if (writeScript(env, shellExecutable, runOptions.scriptPath, unisolatedCommand)) {
- return BlazeCommandResult.exitCode(ExitCode.SUCCESS);
- } else {
- return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE);
- }
- }
-
- env.getReporter().handle(Event.info(
- null, "Running command line: " + ShellEscaper.escapeJoinAll(prettyCmdLine)));
-
- 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();
-
- // The command API is a little strange in that the following statement will return normally
- // only if the program exits with exit code 0. If it ends with any other code, we have to
- // catch BadExitStatusException.
- command
- .execute(
- env.getReporter().getOutErr().getOutputStream(),
- env.getReporter().getOutErr().getErrorStream())
- .getTerminationStatus()
- .getExitCode();
- 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 BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE);
- } catch (AbnormalTerminationException e) {
- // The process was likely terminated by a signal in this case.
- return BlazeCommandResult.exitCode(ExitCode.INTERRUPTED);
- } catch (CommandException e) {
- env.getReporter().handle(Event.error("Error running program: " + e.getMessage()));
- return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE);
- }
- }
-
private void constructCommandLine(List<String> cmdLine, List<String> prettyCmdLine,
CommandEnvironment env, PathFragment shellExecutable, ConfiguredTarget targetToRun,
ConfiguredTarget runUnderTarget, List<String> args) {
@@ -462,11 +363,6 @@ public class RunCommand implements BlazeCommand {
return BlazeCommandResult.exitCode(ExitCode.COMMAND_LINE_ERROR);
}
- if (!runOptions.direct) {
- return runTargetUnderServer(
- env, targetToRun, shExecutable, runUnderTarget, runfilesDir, commandLineArgs);
- }
-
Map<String, String> runEnvironment = new TreeMap<>();
List<String> cmdLine = new ArrayList<>();
List<String> prettyCmdLine = new ArrayList<>();
@@ -587,10 +483,6 @@ public class RunCommand implements BlazeCommand {
/**
* Ensures that runfiles are built for the specified target. If they already
* are, does nothing, otherwise builds them.
- *
- * @param target the target to build runfiles for.
- * @return the path of the runfiles directory.
- * @throws CommandException
*/
private Path ensureRunfilesBuilt(CommandEnvironment env, RunfilesSupport runfilesSupport,
BuildConfiguration configuration) throws CommandException {
@@ -712,7 +604,7 @@ public class RunCommand implements BlazeCommand {
*/
private ExitCode fullyValidateTarget(CommandEnvironment env, ConfiguredTarget configuredTarget) {
- Target target = null;
+ Target target;
try {
target = env.getPackageManager().getTarget(env.getReporter(), configuredTarget.getLabel());
} catch (NoSuchTargetException | NoSuchPackageException | InterruptedException e) {