aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google
diff options
context:
space:
mode:
authorGravatar tomlu <tomlu@google.com>2017-08-22 18:14:54 +0200
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2017-08-23 13:28:44 +0200
commit5d8c44a875961d2bc215a5d373bcdfadabf743d1 (patch)
tree3826f98270ea8ee93fe8d39d6c1f7f855d848b72 /src/main/java/com/google
parent0baff0f51ecbc7956086d21e5c01201bc6672df9 (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: 166068661
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java45
1 files changed, 26 insertions, 19 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
index e535c1529e..3b296a4856 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.RunfilesProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
+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.test.InstrumentedFilesCollector.InstrumentationSpec;
@@ -70,7 +71,6 @@ import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.PathFragment;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.annotation.Nullable;
@@ -197,35 +197,35 @@ public class AndroidCommon {
RuleContext ruleContext,
Artifact jarToDex, Artifact classesDex, List<String> dexOptions, boolean multidex,
Artifact mainDexList) {
- List<String> args = new ArrayList<>();
- args.add("--dex");
+ CustomCommandLine.Builder commandLine = CustomCommandLine.builder();
+ commandLine.add("--dex");
// Multithreaded dex does not work when using --multi-dex.
if (!multidex) {
// Multithreaded dex tends to run faster, but only up to about 5 threads (at which point the
// law of diminishing returns kicks in). This was determined experimentally, with 5-thread dex
// performing about 25% faster than 1-thread dex.
- args.add("--num-threads=5");
+ commandLine.add("--num-threads=5");
}
- args.addAll(dexOptions);
+ commandLine.addAll(dexOptions);
if (multidex) {
- args.add("--multi-dex");
+ commandLine.add("--multi-dex");
if (mainDexList != null) {
- args.add("--main-dex-list=" + mainDexList.getExecPathString());
+ commandLine.addPrefixedExecPath("--main-dex-list=", mainDexList);
}
}
- args.add("--output=" + classesDex.getExecPathString());
- args.add(jarToDex.getExecPathString());
+ commandLine.addPrefixedExecPath("--output=", classesDex);
+ commandLine.addExecPath(jarToDex);
SpawnAction.Builder builder =
new SpawnAction.Builder()
.setExecutable(AndroidSdkProvider.fromRuleContext(ruleContext).getDx())
.addInput(jarToDex)
.addOutput(classesDex)
- .addArguments(args)
.setProgressMessage("Converting %s to dex format", jarToDex.getExecPathString())
.setMnemonic("AndroidDexer")
+ .setCommandLine(commandLine.build())
.setResources(ResourceSet.createWithRamCpuIo(4096.0, 5.0, 0.0));
if (mainDexList != null) {
builder.addInput(mainDexList);
@@ -494,15 +494,22 @@ public class AndroidCommon {
FilesToRunProvider jarjar =
ruleContext.getExecutablePrerequisite("$jarjar_bin", Mode.HOST);
- ruleContext.registerAction(new SpawnAction.Builder()
- .setExecutable(jarjar)
- .addArgument("process")
- .addInputArgument(jarJarRuleFile)
- .addInputArgument(binaryResourcesJar)
- .addOutputArgument(resourcesJar)
- .setProgressMessage("Repackaging jar")
- .setMnemonic("AndroidRepackageJar")
- .build(ruleContext));
+ ruleContext.registerAction(
+ new SpawnAction.Builder()
+ .setExecutable(jarjar)
+ .setProgressMessage("Repackaging jar")
+ .setMnemonic("AndroidRepackageJar")
+ .addInput(jarJarRuleFile)
+ .addInput(binaryResourcesJar)
+ .addOutput(resourcesJar)
+ .setCommandLine(
+ CustomCommandLine.builder()
+ .add("process")
+ .addExecPath(jarJarRuleFile)
+ .addExecPath(binaryResourcesJar)
+ .addExecPath(resourcesJar)
+ .build())
+ .build(ruleContext));
jarsProducedForRuntime.add(resourcesJar);
}
}