diff options
author | 2017-03-20 10:58:11 +0000 | |
---|---|---|
committer | 2017-03-20 11:47:24 +0000 | |
commit | 5e60e3868b4bafacc138f786b304589dbd687016 (patch) | |
tree | c0d85fc4347b7ff67225bead1834ed19cc021e74 /src/main/java/com/google/devtools/build/lib/sandbox | |
parent | 2cea8bc6e17b4df623ed73155c6be7a97cfbe957 (diff) |
Rollback of commit 59180a4ea66b1395b5b85defd732859ecae919ea.
*** Reason for rollback ***
Break bazel-tests and many other jobs on CI.
http://ci.bazel.io/job/bazel-tests/BAZEL_VERSION=HEAD,PLATFORM_NAME=linux-x86_64/651/console
*** Original change description ***
Add SpawnInputExpander helper class to arrange runfiles for spawn strategies
This new class is a combination of SpawnHelper and our internal code; the
plan is to migrate all spawn strategies to the new class. The strict flag
should be enabled by default, but that's a breaking change, so we need to do
it later.
- Use it in SandboxStrategy.
- Add ActionInput.getExecPath to return a PathFragment; this avoids lots of
back and forth between path fragments and strings.
This is a step towards #159...
***
--
PiperOrigin-RevId: 150610616
MOS_MIGRATED_REVID=150610616
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/sandbox')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java index a8da48e4f5..274377831b 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxStrategy.java @@ -17,8 +17,6 @@ package com.google.devtools.build.lib.sandbox; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.devtools.build.lib.actions.ActionExecutionContext; -import com.google.devtools.build.lib.actions.ActionInput; -import com.google.devtools.build.lib.actions.Artifact; import com.google.devtools.build.lib.actions.EnvironmentalExecException; import com.google.devtools.build.lib.actions.ExecException; import com.google.devtools.build.lib.actions.SandboxedSpawnActionContext; @@ -30,17 +28,12 @@ import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.buildtool.BuildRequest; import com.google.devtools.build.lib.events.Event; import com.google.devtools.build.lib.events.EventHandler; -import com.google.devtools.build.lib.exec.SpawnInputExpander; -import com.google.devtools.build.lib.rules.fileset.FilesetActionContext; import com.google.devtools.build.lib.util.io.OutErr; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.concurrent.atomic.AtomicReference; /** Abstract common ancestor for sandbox strategies implementing the common parts. */ @@ -51,7 +44,7 @@ abstract class SandboxStrategy implements SandboxedSpawnActionContext { private final Path execRoot; private final boolean verboseFailures; private final SandboxOptions sandboxOptions; - private final SpawnInputExpander spawnInputExpander; + private final SpawnHelpers spawnHelpers; public SandboxStrategy( BuildRequest buildRequest, @@ -63,7 +56,7 @@ abstract class SandboxStrategy implements SandboxedSpawnActionContext { this.execRoot = blazeDirs.getExecRoot(); this.verboseFailures = verboseFailures; this.sandboxOptions = sandboxOptions; - this.spawnInputExpander = new SpawnInputExpander(/*strict=*/false); + this.spawnHelpers = new SpawnHelpers(blazeDirs.getExecRoot()); } protected void runSpawn( @@ -152,33 +145,7 @@ abstract class SandboxStrategy implements SandboxedSpawnActionContext { public Map<PathFragment, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext) throws ExecException { try { - Map<PathFragment, ActionInput> inputMap = spawnInputExpander - .getInputMapping( - spawn, - executionContext.getArtifactExpander(), - executionContext.getActionInputFileCache(), - executionContext.getExecutor().getContext(FilesetActionContext.class)); - Map<PathFragment, Path> mounts = new TreeMap<>(); - for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) { - mounts.put(e.getKey(), execRoot.getRelative(e.getValue().getExecPath())); - } - - // ActionInputHelper#expandArtifacts above expands empty TreeArtifacts into an empty list. - // However, actions that accept TreeArtifacts as inputs generally expect that the empty - // directory is created. So here we explicitly mount the directories of the TreeArtifacts as - // inputs. - for (ActionInput input : spawn.getInputFiles()) { - if (input instanceof Artifact && ((Artifact) input).isTreeArtifact()) { - List<Artifact> containedArtifacts = new ArrayList<>(); - executionContext.getArtifactExpander().expand((Artifact) input, containedArtifacts); - // Attempting to mount a non-empty directory results in ERR_DIRECTORY_NOT_EMPTY, so we - // only mount empty TreeArtifacts as directories. - if (containedArtifacts.isEmpty()) { - inputMap.put(input.getExecPath(), input); - } - } - } - return mounts; + return spawnHelpers.getMounts(spawn, executionContext); } catch (IOException e) { throw new EnvironmentalExecException("Could not prepare mounts for sandbox execution", e); } |