From 6766ebbc7be2b296f7861b25b4c8f373a8503ab3 Mon Sep 17 00:00:00 2001 From: Lukacs Berki Date: Wed, 30 Mar 2016 10:16:28 +0000 Subject: Use the local shell environment for invoking build-runfiles. This is necessary because build-runfiles depends on the msys shared library, which (as per DLL lookup rules on Windows) is checked under the entries of PATH. -- MOS_MIGRATED_REVID=118556684 --- .../google/devtools/build/lib/analysis/RunfilesSupport.java | 3 ++- .../devtools/build/lib/analysis/SymlinkTreeAction.java | 8 ++++++-- .../build/lib/analysis/SymlinkTreeActionContext.java | 4 +++- .../google/devtools/build/lib/exec/SymlinkTreeHelper.java | 5 +++-- .../google/devtools/build/lib/exec/SymlinkTreeStrategy.java | 7 +++++-- .../google/devtools/build/lib/rules/android/NativeLibs.java | 3 ++- .../build/lib/rules/test/StandaloneTestStrategy.java | 5 ++--- .../devtools/build/lib/rules/test/TestRunnerAction.java | 8 +++++--- .../google/devtools/build/lib/rules/test/TestStrategy.java | 13 ++++++++----- 9 files changed, 36 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java b/src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java index b96a7e7049..07282a2bd0 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/RunfilesSupport.java @@ -301,7 +301,8 @@ public class RunfilesSupport { artifactsMiddleman, outputManifest, /*filesetTree=*/ false, - config.getShExecutable())); + config.getShExecutable(), + config.getLocalShellEnvironment())); return outputManifest; } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeAction.java b/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeAction.java index 1e560c9bb6..0e98408a15 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeAction.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeAction.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.analysis; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.AbstractAction; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; @@ -39,6 +40,7 @@ public class SymlinkTreeAction extends AbstractAction { private final Artifact outputManifest; private final boolean filesetTree; private final PathFragment shExecutable; + private final ImmutableMap shellEnviroment; /** * Creates SymlinkTreeAction instance. @@ -60,13 +62,15 @@ public class SymlinkTreeAction extends AbstractAction { @Nullable Artifact artifactMiddleman, Artifact outputManifest, boolean filesetTree, - PathFragment shExecutable) { + PathFragment shExecutable, + ImmutableMap shellEnvironment) { super(owner, computeInputs(inputManifest, artifactMiddleman), ImmutableList.of(outputManifest)); Preconditions.checkArgument(outputManifest.getPath().getBaseName().equals("MANIFEST")); this.inputManifest = inputManifest; this.outputManifest = outputManifest; this.filesetTree = filesetTree; this.shExecutable = shExecutable; + this.shellEnviroment = shellEnvironment; } private static ImmutableList computeInputs( @@ -123,6 +127,6 @@ public class SymlinkTreeAction extends AbstractAction { actionExecutionContext .getExecutor() .getContext(SymlinkTreeActionContext.class) - .createSymlinks(this, actionExecutionContext, shExecutable); + .createSymlinks(this, actionExecutionContext, shExecutable, shellEnviroment); } } diff --git a/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeActionContext.java b/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeActionContext.java index dcf6ecbe4f..fa9182abd2 100644 --- a/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeActionContext.java +++ b/src/main/java/com/google/devtools/build/lib/analysis/SymlinkTreeActionContext.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.analysis; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.Executor.ActionContext; @@ -29,6 +30,7 @@ public interface SymlinkTreeActionContext extends ActionContext { void createSymlinks( SymlinkTreeAction action, ActionExecutionContext actionExecutionContext, - PathFragment shExecutable) + PathFragment shExecutable, + ImmutableMap shellEnvironment) throws ActionExecutionException, InterruptedException; } diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java index 494f4454ca..2980c718a5 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeHelper.java @@ -112,14 +112,15 @@ public final class SymlinkTreeHelper { AbstractAction action, ActionExecutionContext actionExecutionContext, BinTools binTools, - PathFragment shExecutable) + PathFragment shExecutable, + ImmutableMap shellEnvironment) throws ExecException, InterruptedException { List args = getSpawnArgumentList( actionExecutionContext.getExecutor().getExecRoot(), binTools, shExecutable); try (ResourceHandle handle = ResourceManager.instance().acquireResources(action, RESOURCE_SET)) { actionExecutionContext.getExecutor().getSpawnActionContext(action.getMnemonic()).exec( - new BaseSpawn.Local(args, ImmutableMap.of(), action), + new BaseSpawn.Local(args, shellEnvironment, action), actionExecutionContext); } } diff --git a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java index 609ce57998..e34a6b4bef 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SymlinkTreeStrategy.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.exec; +import com.google.common.collect.ImmutableMap; import com.google.devtools.build.lib.actions.ActionExecutionContext; import com.google.devtools.build.lib.actions.ActionExecutionException; import com.google.devtools.build.lib.actions.ExecException; @@ -46,7 +47,8 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { public void createSymlinks( SymlinkTreeAction action, ActionExecutionContext actionExecutionContext, - PathFragment shExecutable) + PathFragment shExecutable, + ImmutableMap shellEnvironment) throws ActionExecutionException, InterruptedException { Executor executor = actionExecutionContext.getExecutor(); try (AutoProfiler p = @@ -61,7 +63,8 @@ public final class SymlinkTreeStrategy implements SymlinkTreeActionContext { action.getOutputManifest().getPath(), action.isFilesetTree(), helper.getSymlinkTreeRoot()); } else { - helper.createSymlinks(action, actionExecutionContext, binTools, shExecutable); + helper.createSymlinks( + action, actionExecutionContext, binTools, shExecutable, shellEnvironment); } } catch (ExecException e) { throw e.toActionExecutionException( diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java index e11ff8ecfc..78c8db2cde 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/NativeLibs.java @@ -163,7 +163,8 @@ public final class NativeLibs { nativeLibsMiddleman, outputManifest, false, - ruleContext.getConfiguration().getShExecutable())); + ruleContext.getConfiguration().getShExecutable(), + ruleContext.getConfiguration().getLocalShellEnvironment())); return outputManifest; } diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java index d80fff8caf..a474521544 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/rules/test/StandaloneTestStrategy.java @@ -70,9 +70,8 @@ public class StandaloneTestStrategy extends TestStrategy { throws ExecException, InterruptedException { Path runfilesDir = null; try { - runfilesDir = - TestStrategy.getLocalRunfilesDirectory( - action, actionExecutionContext, binTools, action.getShExecutable()); + runfilesDir = TestStrategy.getLocalRunfilesDirectory(action, actionExecutionContext, binTools, + action.getShExecutable(), action.getLocalShellEnvironment()); } catch (ExecException e) { throw new TestExecException(e.getMessage()); } diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java index 5f456d7a53..687d6228a4 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java +++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestRunnerAction.java @@ -88,7 +88,6 @@ public class TestRunnerAction extends AbstractAction implements NotifyOnActionCa private final int shardNum; private final int runNumber; private final String workspaceName; - private final PathFragment shExecutable; // Mutable state related to test caching. private boolean checkedCaching = false; @@ -168,7 +167,6 @@ public class TestRunnerAction extends AbstractAction implements NotifyOnActionCa this.undeclaredOutputsAnnotationsPath = undeclaredOutputsAnnotationsDir.getChild("ANNOTATIONS"); this.testInfrastructureFailure = baseDir.getChild(namePrefix + ".infrastructure_failure"); this.workspaceName = workspaceName; - this.shExecutable = configuration.getShExecutable(); Map mergedTestEnv = new HashMap<>(configuration.getTestEnv()); mergedTestEnv.putAll(extraTestEnv); @@ -557,7 +555,11 @@ public class TestRunnerAction extends AbstractAction implements NotifyOnActionCa } public PathFragment getShExecutable() { - return shExecutable; + return configuration.getShExecutable(); + } + + public ImmutableMap getLocalShellEnvironment() { + return configuration.getLocalShellEnvironment(); } /** diff --git a/src/main/java/com/google/devtools/build/lib/rules/test/TestStrategy.java b/src/main/java/com/google/devtools/build/lib/rules/test/TestStrategy.java index 2ac016bbde..9423f10c27 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/test/TestStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/rules/test/TestStrategy.java @@ -349,7 +349,8 @@ public abstract class TestStrategy implements TestActionContext { TestRunnerAction testAction, ActionExecutionContext actionExecutionContext, BinTools binTools, - PathFragment shExecutable) + PathFragment shExecutable, + ImmutableMap shellEnvironment) throws ExecException, InterruptedException { TestTargetExecutionSettings execSettings = testAction.getExecutionSettings(); @@ -372,8 +373,8 @@ public abstract class TestStrategy implements TestActionContext { long startTime = Profiler.nanoTimeMaybe(); synchronized (execSettings.getInputManifest()) { Profiler.instance().logSimpleTask(startTime, ProfilerTask.WAIT, testAction); - updateLocalRunfilesDirectory( - testAction, runfilesDir, actionExecutionContext, binTools, shExecutable); + updateLocalRunfilesDirectory(testAction, runfilesDir, actionExecutionContext, binTools, + shExecutable, shellEnvironment); } return runfilesDir; @@ -390,7 +391,8 @@ public abstract class TestStrategy implements TestActionContext { Path runfilesDir, ActionExecutionContext actionExecutionContext, BinTools binTools, - PathFragment shExecutable) + PathFragment shExecutable, + ImmutableMap shellEnvironment) throws ExecException, InterruptedException { Executor executor = actionExecutionContext.getExecutor(); @@ -413,7 +415,8 @@ public abstract class TestStrategy implements TestActionContext { execSettings.getInputManifest().getExecPath(), runfilesDir.relativeTo(executor.getExecRoot()), /* filesetTree= */ false) - .createSymlinks(testAction, actionExecutionContext, binTools, shExecutable); + .createSymlinks( + testAction, actionExecutionContext, binTools, shExecutable, shellEnvironment); executor.getEventHandler().handle(Event.progress(testAction.getProgressMessage())); } -- cgit v1.2.3