Skip to content

Commit

Permalink
Android,Windows: use default shell env in actions
Browse files Browse the repository at this point in the history
Bazel now creates all SpawnActions in
AndroidBinary, AndroidCommon, and DexArchiveAspect
such that they use the default shell environment.

The benefit of this is that these actions will
have a well-controlled, minimal environment, and
most importantly they'll have valid TMP and TEMP
environment variables, which is necessary for temp
file creaion on Windows.

I created this commit for the same reason as
bazelbuild@0abf5fa

See bazelbuild#3659

Change-Id: Ice42ea6424af8984d3c382ab01727e04cbd0c1b4
PiperOrigin-RevId: 167285724
  • Loading branch information
laszlocsomor authored and vladmos committed Sep 1, 2017
1 parent 37d6104 commit 8fb7d53
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
Builder rexActionBuilder = new SpawnAction.Builder();
CustomCommandLine.Builder commandLine = CustomCommandLine.builder();
rexActionBuilder
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite("$rex_wrapper", Mode.HOST))
.setMnemonic("Rex")
.setProgressMessage("Rexing dex files")
Expand Down Expand Up @@ -628,6 +629,7 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
ruleContext.getImplicitOutputArtifact(AndroidRuleClasses.DEX_MANIFEST);
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setMnemonic("AndroidDexManifest")
.setProgressMessage(
"Generating incremental installation manifest for %s", ruleContext.getLabel())
Expand Down Expand Up @@ -756,6 +758,7 @@ public static RuleConfiguredTargetBuilder createAndroidBinary(
Artifact splitMainApkResources = getDxArtifact(ruleContext, "split_main.ap_");
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setMnemonic("AndroidStripResources")
.setProgressMessage("Stripping resources from split main apk")
.setExecutable(ruleContext.getExecutablePrerequisite("$strip_resources", Mode.HOST))
Expand Down Expand Up @@ -888,6 +891,7 @@ private static void createSplitInstallAction(RuleContext ruleContext,
FilesToRunProvider adb = AndroidSdkProvider.fromRuleContext(ruleContext).getAdb();
SpawnAction.Builder builder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite("$incremental_install", Mode.HOST))
.addTool(adb)
.executeUnconditionally()
Expand Down Expand Up @@ -923,6 +927,7 @@ private static void createInstallAction(RuleContext ruleContext,
FilesToRunProvider adb = AndroidSdkProvider.fromRuleContext(ruleContext).getAdb();
SpawnAction.Builder builder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite("$incremental_install", Mode.HOST))
// We cannot know if the user connected a new device, uninstalled the app from the
// device
Expand Down Expand Up @@ -1374,6 +1379,7 @@ private static DexingOutput dex(
.build();
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setMnemonic("MergeDexZips")
.setProgressMessage("Merging dex shards for %s", ruleContext.getLabel())
.setExecutable(ruleContext.getExecutablePrerequisite("$merge_dexzips", Mode.HOST))
Expand Down Expand Up @@ -1467,6 +1473,7 @@ private static void createDexMergerAction(
Collection<String> dexopts) {
SpawnAction.Builder dexmerger =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite("$dexmerger", Mode.HOST))
.setMnemonic("DexMerger")
.setProgressMessage("Assembling dex files into %s", classesDex.getRootRelativePath())
Expand Down Expand Up @@ -1589,6 +1596,7 @@ private static Artifact createShuffleJarAction(

SpawnAction.Builder shardAction =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setMnemonic("ShardClassesToDex")
.setProgressMessage("Sharding classes for dexing for %s", ruleContext.getLabel())
.setExecutable(ruleContext.getExecutablePrerequisite("$shuffle_jars", Mode.HOST))
Expand Down Expand Up @@ -1669,7 +1677,7 @@ private static Artifact createShuffleJarAction(
// Adds the appropriate SpawnAction options depending on if SingleJar is a jar or not.
private static SpawnAction.Builder singleJarSpawnActionBuilder(RuleContext ruleContext) {
Artifact singleJar = JavaToolchainProvider.fromRuleContext(ruleContext).getSingleJar();
SpawnAction.Builder builder = new SpawnAction.Builder();
SpawnAction.Builder builder = new SpawnAction.Builder().useDefaultShellEnvironment();
if (singleJar.getFilename().endsWith(".jar")) {
builder
.setJarExecutable(
Expand Down Expand Up @@ -1724,6 +1732,7 @@ static Artifact createMainDexListAction(
AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
SpawnAction.Builder streamlinedBuilder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.addOutput(strippedJar)
.setExecutable(sdk.getProguard())
.setProgressMessage("Generating streamlined input jar for main dex classes list")
Expand Down Expand Up @@ -1794,6 +1803,7 @@ private static Artifact createSplitApkResources(RuleContext ruleContext,
AndroidSdkProvider sdk = AndroidSdkProvider.fromRuleContext(ruleContext);
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(sdk.getAapt())
.setMnemonic("AaptSplitResourceApk")
.setProgressMessage("Generating resource apk for split %s", splitName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public static void createDexAction(

SpawnAction.Builder builder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(AndroidSdkProvider.fromRuleContext(ruleContext).getDx())
.addInput(jarToDex)
.addOutput(classesDex)
Expand Down Expand Up @@ -495,6 +496,7 @@ private void createJarJarActions(

ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(jarjar)
.setProgressMessage("Repackaging jar")
.setMnemonic("AndroidRepackageJar")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ private static Artifact createDesugarAction(
ISO_8859_1));
ruleContext.registerAction(
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite(desugarPrereqName, Mode.HOST))
.addInput(jar)
.addInput(paramFile)
Expand Down Expand Up @@ -442,6 +443,7 @@ private static Artifact createDexArchiveAction(RuleContext ruleContext, String d
ISO_8859_1));
SpawnAction.Builder dexbuilder =
new SpawnAction.Builder()
.useDefaultShellEnvironment()
.setExecutable(ruleContext.getExecutablePrerequisite(dexbuilderPrereq, Mode.HOST))
// WorkerSpawnStrategy expects the last argument to be @paramfile
.addInput(jar)
Expand Down

0 comments on commit 8fb7d53

Please sign in to comment.