Use CustomCommandLine directly instead of via SpawnAction.Builder.

This change forces use of CustomCommandLine.Builder, which has a richer interface for constructing memory-efficient command lines. It will also permit surveying the code base for inefficient patterns using an IDE.

This change was done by hand and split using Rosie to assist with rollbacks in case of bugs. Reviewers, please pay particular attention to:

* Each all to addInputArgument/addOutputArgument should come with a corresponding matching pair to SpawnAction.Builder#addInput and CustomCommandLine.Builder#addExecPath (eg.).
* The commandLine must be set on the SpawnAction using SpawnAction.Builder#setCommandLine.

Note that most calls to addPrefixed("arg=", val) should be more idiomatically expressed as add("arg", val), but this involves changing tests and making sure that the command line tools can accept the format.

PiperOrigin-RevId: 166106109
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java
index 3452c37..4773988 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java
@@ -23,6 +23,7 @@
 import com.google.devtools.build.lib.analysis.FilesToRunProvider;
 import com.google.devtools.build.lib.analysis.PseudoAction;
 import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
 import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
 import com.google.devtools.build.lib.analysis.actions.SpawnAction;
 import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction;
@@ -361,7 +362,7 @@
     @SuppressWarnings("unchecked")
     List<String> argumentsContents = arguments.getContents(String.class, "arguments");
 
-    builder.addArguments(argumentsContents);
+    builder.setCommandLine(CustomCommandLine.builder().addAll(argumentsContents).build());
     if (executableUnchecked instanceof Artifact) {
       Artifact executable = (Artifact) executableUnchecked;
       builder.addInput(executable);
@@ -515,17 +516,18 @@
 
     // TODO(bazel-team): builder still makes unnecessary copies of inputs, outputs and args.
     SpawnAction.Builder builder = new SpawnAction.Builder();
+    CustomCommandLine.Builder commandLine = CustomCommandLine.builder();
     if (arguments.size() > 0) {
       // When we use a shell command, add an empty argument before other arguments.
       //   e.g.  bash -c "cmd" '' 'arg1' 'arg2'
       // bash will use the empty argument as the value of $0 (which we don't care about).
       // arg1 and arg2 will be $1 and $2, as a user expects.
-      builder.addArgument("");
+      commandLine.add("");
     }
 
     @SuppressWarnings("unchecked")
     List<String> argumentsContents = arguments.getContents(String.class, "arguments");
-    builder.addArguments(argumentsContents);
+    commandLine.addAll(argumentsContents);
 
     if (commandUnchecked instanceof String) {
       builder.setShellCommand((String) commandUnchecked);
@@ -543,6 +545,7 @@
           "expected string or list of strings for command instead of "
               + EvalUtils.getDataTypeName(commandUnchecked));
     }
+    builder.setCommandLine(commandLine.build());
     registerSpawnAction(
         outputs,
         inputs,