aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-08-22 22:33:35 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-23 13:31:26 +0200
commit3595c9566bca1afae252375130bc9d6a4b7bd1ac (patch)
treede7a6040dbabc261696a717ed0665654ee405652 /src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java
parent4040c9fc7c955d36454682653f873c7b3e279b98 (diff)
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkActionFactory.java9
1 files changed, 6 insertions, 3 deletions
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 3452c3781f..4773988ebe 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.actions.extra.SpawnInfo;
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 @@ public class SkylarkActionFactory implements SkylarkValue {
@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 @@ public class SkylarkActionFactory implements SkylarkValue {
// 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 @@ public class SkylarkActionFactory implements SkylarkValue {
"expected string or list of strings for command instead of "
+ EvalUtils.getDataTypeName(commandUnchecked));
}
+ builder.setCommandLine(commandLine.build());
registerSpawnAction(
outputs,
inputs,