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
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 dfbe492..6f70460 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 @@
 
     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 @@
           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 @@
       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));