aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-08-23 17:24:31 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-24 13:58:32 +0200
commitce10ea2a5e4e4ec9bc9fdf6ceda1b02255883ae1 (patch)
tree1f4d847738ae5c4584bec9feb7939fc8d455e62b /src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
parenta21bb62b5558a1e8a355ca7e4b7b7aa712c957f4 (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: 166203749
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
index 524ced33d3..824fef7b03 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/python/PythonUtils.java
@@ -20,13 +20,12 @@ import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
+import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -110,23 +109,23 @@ public final class PythonUtils {
FilesToRunProvider py2to3converter =
ruleContext.getExecutablePrerequisite("$python2to3", RuleConfiguredTarget.Mode.HOST);
Artifact output = get2to3OutputArtifact(ruleContext, input);
- List<String> argv = new ArrayList<>();
- argv.add("--no-diffs");
- argv.add("--nobackups");
- argv.add("--write");
- argv.add("--output-dir");
- argv.add(output.getExecPath().getParentDirectory().toString());
- argv.add("--write-unchanged-files");
- argv.add(input.getExecPathString());
+ CustomCommandLine.Builder commandLine =
+ CustomCommandLine.builder()
+ .add("--no-diffs")
+ .add("--nobackups")
+ .add("--write")
+ .addPath("--output-dir", output.getExecPath().getParentDirectory())
+ .add("--write-unchanged-files")
+ .addExecPath(input);
ruleContext.registerAction(
new SpawnAction.Builder()
.addInput(input)
.addOutput(output)
.setExecutable(py2to3converter)
- .addArguments(argv)
.setProgressMessage("Converting to Python 3: %s", input.prettyPrint())
.setMnemonic("2to3")
+ .setCommandLine(commandLine.build())
.build(ruleContext));
return output;
}