diff options
author | lberki <lberki@google.com> | 2018-02-28 04:52:30 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-02-28 04:54:26 -0800 |
commit | 3e4c8c801fab23ed66dc56afad0539e8e296fcc3 (patch) | |
tree | c93ddc8b7aeda66108319361377e4622b5c6008c /src/main/java/com/google/devtools/build | |
parent | a22a287f53598d2a2a7eb59b72fe4e98a02435ce (diff) |
Improve "blaze run --direct_run".
In particular:
- Make it support --script_path
- Make it add command line arguments specified on the command line to tests
- Remove a stale comment
This introduces the following differences in behavior wrt. --nodirect_run:
- Tests are run through the test setup script and get the environment variables specific to tests
- --test_arg arguments will be on the command line of test targets
- The script written by --script_path overwrites the environment of the binary with the client environment at the time of "blaze run" (for binaries) or the proper test environment (for tests)
RELNOTES: None.
PiperOrigin-RevId: 187309437
Diffstat (limited to 'src/main/java/com/google/devtools/build')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/runtime/commands/RunCommand.java | 20 |
1 files changed, 14 insertions, 6 deletions
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 dfbe4927da..6f7046061a 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 @@ -427,7 +427,7 @@ public class RunCommand implements BlazeCommand { Map<String, String> runEnvironment; Path workingDir; - List<String> cmdLine; + List<String> cmdLine = new ArrayList<>(); if (targetToRun.getProvider(TestProvider.class) != null) { // This is a test. Provide it with a reasonable approximation of the actual test environment @@ -459,10 +459,8 @@ public class RunCommand implements BlazeCommand { relativeTmpDir.getRelative(TestStrategy.getTmpDirName(testAction))); workingDir = env.getExecRoot(); try { - // It's unfortunate that this method requires the path to the coverage collection script. - // Fortunately, this is "blaze run" and not "blaze coverage", so it's okay unless someone - // calls "blaze run --collect_code_coverage". - cmdLine = TestStrategy.getArgs(testAction); + cmdLine.addAll(TestStrategy.getArgs(testAction)); + cmdLine.addAll(commandLineArgs); } catch (ExecException e) { env.getReporter().handle(Event.error(e.getMessage())); return BlazeCommandResult.exitCode(ExitCode.LOCAL_ENVIRONMENTAL_ERROR); @@ -473,13 +471,23 @@ public class RunCommand implements BlazeCommand { runEnvironment.put("BUILD_WORKSPACE_DIRECTORY", env.getWorkspace().getPathString()); runEnvironment.put("BUILD_WORKING_DIRECTORY", env.getWorkingDirectory().getPathString()); workingDir = runfilesDir; - cmdLine = new ArrayList<>(); List<String> prettyCmdLine = new ArrayList<>(); List<String> args = computeArgs(env, targetToRun, commandLineArgs); constructCommandLine(cmdLine, prettyCmdLine, env, configuration.getShellExecutable(), targetToRun, runUnderTarget, args); } + if (runOptions.scriptPath != null) { + String unisolatedCommand = CommandFailureUtils.describeCommand( + CommandDescriptionForm.COMPLETE_UNISOLATED, + cmdLine, runEnvironment, workingDir.getPathString()); + if (writeScript(env, runOptions.scriptPath, unisolatedCommand)) { + return BlazeCommandResult.exitCode(ExitCode.SUCCESS); + } else { + return BlazeCommandResult.exitCode(ExitCode.RUN_FAILURE); + } + } + ExecRequest.Builder execDescription = ExecRequest.newBuilder() .setWorkingDirectory( ByteString.copyFrom(workingDir.getPathString(), StandardCharsets.ISO_8859_1)); |