From 4040c9fc7c955d36454682653f873c7b3e279b98 Mon Sep 17 00:00:00 2001 From: tomlu Date: Tue, 22 Aug 2017 22:33:32 +0200 Subject: 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: 166106104 --- .../lib/rules/android/ApplicationManifest.java | 80 +++++++++++++--------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/rules') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java index 01031e9dee..f15eba6697 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApplicationManifest.java @@ -27,6 +27,7 @@ import com.google.devtools.build.lib.analysis.FileProvider; import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode; import com.google.devtools.build.lib.analysis.RuleContext; import com.google.devtools.build.lib.analysis.TransitiveInfoCollection; +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.config.CompilationMode; @@ -70,21 +71,25 @@ public final class ApplicationManifest { ruleContext.getExecutablePrerequisite("$build_split_manifest", Mode.HOST)) .setProgressMessage("Creating manifest for split %s", splitName) .setMnemonic("AndroidBuildSplitManifest") - .addArgument("--main_manifest") - .addInputArgument(manifest) - .addArgument("--split_manifest") - .addOutputArgument(result) - .addArgument("--split") - .addArgument(splitName) - .addArgument(hasCode ? "--hascode" : "--nohascode"); + .addInput(manifest) + .addOutput(result); + CustomCommandLine.Builder commandLine = + CustomCommandLine.builder() + .addExecPath("--main_manifest", manifest) + .addExecPath("--split_manifest", result) + .add("--split", splitName); + if (hasCode) { + commandLine.add("--hascode"); + } else { + commandLine.add("--nohascode"); + } String overridePackage = manifestValues.get("applicationId"); if (overridePackage != null) { - builder - .addArgument("--override_package") - .addArgument(overridePackage); + commandLine.add("--override_package", overridePackage); } + builder.setCommandLine(commandLine.build()); ruleContext.registerAction(builder.build(ruleContext)); return new ApplicationManifest(ruleContext, result, targetAaptVersion); } @@ -94,26 +99,31 @@ public final class ApplicationManifest { Artifact stubManifest = ruleContext.getImplicitOutputArtifact( AndroidRuleClasses.MOBILE_INSTALL_STUB_APPLICATION_MANIFEST); + Artifact stubData = + ruleContext.getImplicitOutputArtifact( + AndroidRuleClasses.MOBILE_INSTALL_STUB_APPLICATION_DATA); - SpawnAction.Builder builder = new SpawnAction.Builder() - .setExecutable(ruleContext.getExecutablePrerequisite("$stubify_manifest", Mode.HOST)) - .setProgressMessage("Injecting mobile install stub application") - .setMnemonic("InjectMobileInstallStubApplication") - .addArgument("--mode=mobile_install") - .addArgument("--input_manifest") - .addInputArgument(manifest) - .addArgument("--output_manifest") - .addOutputArgument(stubManifest) - .addArgument("--output_datafile") - .addOutputArgument(ruleContext.getImplicitOutputArtifact( - AndroidRuleClasses.MOBILE_INSTALL_STUB_APPLICATION_DATA)); + SpawnAction.Builder builder = + new SpawnAction.Builder() + .setExecutable(ruleContext.getExecutablePrerequisite("$stubify_manifest", Mode.HOST)) + .setProgressMessage("Injecting mobile install stub application") + .setMnemonic("InjectMobileInstallStubApplication") + .addInput(manifest) + .addOutput(stubManifest) + .addOutput(stubData); + CustomCommandLine.Builder commandLine = + CustomCommandLine.builder() + .add("--mode=mobile_install") + .addExecPath("--input_manifest", manifest) + .addExecPath("--output_manifest", stubManifest) + .addExecPath("--output_datafile", stubData); String overridePackage = manifestValues.get("applicationId"); if (overridePackage != null) { - builder.addArgument("--override_package"); - builder.addArgument(overridePackage); + commandLine.add("--override_package", overridePackage); } + builder.setCommandLine(commandLine.build()); ruleContext.registerAction(builder.build(ruleContext)); return new ApplicationManifest(ruleContext, stubManifest, targetAaptVersion); @@ -125,15 +135,19 @@ public final class ApplicationManifest { Artifact stubManifest = ruleContext.getImplicitOutputArtifact( AndroidRuleClasses.INSTANT_RUN_STUB_APPLICATION_MANIFEST); - SpawnAction.Builder builder = new SpawnAction.Builder() - .setExecutable(ruleContext.getExecutablePrerequisite("$stubify_manifest", Mode.HOST)) - .setProgressMessage("Injecting instant run stub application") - .setMnemonic("InjectInstantRunStubApplication") - .addArgument("--mode=instant_run") - .addArgument("--input_manifest") - .addInputArgument(manifest) - .addArgument("--output_manifest") - .addOutputArgument(stubManifest); + SpawnAction.Builder builder = + new SpawnAction.Builder() + .setExecutable(ruleContext.getExecutablePrerequisite("$stubify_manifest", Mode.HOST)) + .setProgressMessage("Injecting instant run stub application") + .setMnemonic("InjectInstantRunStubApplication") + .addInput(manifest) + .addOutput(stubManifest) + .setCommandLine( + CustomCommandLine.builder() + .add("--mode=instant_run") + .addExecPath("--input_manifest", manifest) + .addExecPath("--output_manifest", stubManifest) + .build()); ruleContext.registerAction(builder.build(ruleContext)); -- cgit v1.2.3