aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java
diff options
context:
space:
mode:
authorGravatar Philipp Wollermann <philwo@google.com>2015-10-09 13:43:41 +0000
committerGravatar Kristina Chodorow <kchodorow@google.com>2015-10-09 14:42:52 +0000
commit57df8fde8ac3d331cd325b3e490f88db282cd0c4 (patch)
treedb1767a7e6ae0d27809909718e5f939b92b3892e /src/main/java
parent6133c3f93d2664f8923ec027443041e595eadead (diff)
Add support for filesets in LinuxSandboxedStrategy.
-- MOS_MIGRATED_REVID=105052078
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java64
1 files changed, 56 insertions, 8 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
index 563a19f7f7..5bf57ec063 100644
--- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
+++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java
@@ -30,10 +30,12 @@ import com.google.devtools.build.lib.actions.Executor;
import com.google.devtools.build.lib.actions.Spawn;
import com.google.devtools.build.lib.actions.SpawnActionContext;
import com.google.devtools.build.lib.actions.UserExecException;
+import com.google.devtools.build.lib.analysis.AnalysisUtils;
import com.google.devtools.build.lib.analysis.BlazeDirectories;
import com.google.devtools.build.lib.analysis.config.RunUnder;
import com.google.devtools.build.lib.cmdline.Label;
import com.google.devtools.build.lib.rules.cpp.CppCompileAction;
+import com.google.devtools.build.lib.rules.fileset.FilesetActionContext;
import com.google.devtools.build.lib.rules.test.TestRunnerAction;
import com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy;
import com.google.devtools.build.lib.unix.FilesystemUtils;
@@ -46,7 +48,7 @@ import com.google.devtools.build.lib.vfs.SearchPath;
import java.io.File;
import java.io.IOException;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -203,13 +205,14 @@ public class LinuxSandboxedStrategy implements SpawnActionContext {
return dirs.build();
}
- private ImmutableMap<Path, Path> getMounts(
- Spawn spawn, ActionExecutionContext executionContext) throws IOException {
+ private ImmutableMap<Path, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext)
+ throws IOException, UserExecException {
MountMap mounts = new MountMap();
mounts.putAll(mountUsualUnixDirs());
mounts.putAll(withRecursedDirs(setupBlazeUtils()));
mounts.putAll(withRecursedDirs(mountRunfilesFromManifests(spawn)));
mounts.putAll(withRecursedDirs(mountRunfilesFromSuppliers(spawn)));
+ mounts.putAll(withRecursedDirs(mountFilesFromFilesetManifests(spawn, executionContext)));
mounts.putAll(withRecursedDirs(mountInputs(spawn, executionContext)));
mounts.putAll(withRecursedDirs(mountRunUnderCommand(spawn)));
return validateMounts(withResolvedSymlinks(mounts));
@@ -319,24 +322,68 @@ public class LinuxSandboxedStrategy implements SpawnActionContext {
/**
* Mount all runfiles that the spawn needs as specified in its runfiles manifests.
*/
- private MountMap mountRunfilesFromManifests(Spawn spawn) throws IOException {
+ private MountMap mountRunfilesFromManifests(Spawn spawn) throws IOException, UserExecException {
MountMap mounts = new MountMap();
for (Entry<PathFragment, Artifact> manifest : spawn.getRunfilesManifests().entrySet()) {
String manifestFilePath = manifest.getValue().getPath().getPathString();
Preconditions.checkState(!manifest.getKey().isAbsolute());
Path targetDirectory = execRoot.getRelative(manifest.getKey());
- mounts.putAll(parseManifestFile(targetDirectory, new File(manifestFilePath)));
+ mounts.putAll(parseManifestFile(targetDirectory, new File(manifestFilePath), false, ""));
}
return mounts;
}
- static MountMap parseManifestFile(Path targetDirectory, File manifestFile) throws IOException {
+ /**
+ * Mount all files that the spawn needs as specified in its fileset manifests.
+ */
+ private MountMap mountFilesFromFilesetManifests(
+ Spawn spawn, ActionExecutionContext executionContext) throws IOException, UserExecException {
+ final FilesetActionContext filesetContext =
+ executionContext.getExecutor().getContext(FilesetActionContext.class);
MountMap mounts = new MountMap();
- for (String line : Files.readLines(manifestFile, Charset.defaultCharset())) {
+ for (Artifact fileset : spawn.getFilesetManifests()) {
+ Path manifest =
+ execRoot.getRelative(AnalysisUtils.getManifestPathFromFilesetPath(fileset.getExecPath()));
+ Path targetDirectory = execRoot.getRelative(fileset.getExecPathString());
+
+ mounts.putAll(
+ parseManifestFile(
+ targetDirectory, manifest.getPathFile(), true, filesetContext.getWorkspaceName()));
+ }
+ return mounts;
+ }
+
+ static MountMap parseManifestFile(
+ Path targetDirectory, File manifestFile, boolean isFilesetManifest, String workspaceName)
+ throws IOException, UserExecException {
+ MountMap mounts = new MountMap();
+ int lineNum = 0;
+ for (String line : Files.readLines(manifestFile, StandardCharsets.UTF_8)) {
+ if (isFilesetManifest && (++lineNum % 2 == 0)) {
+ continue;
+ }
+ if (line.isEmpty()) {
+ continue;
+ }
+
String[] fields = line.trim().split(" ");
+
+ Path targetPath;
+ if (isFilesetManifest) {
+ PathFragment targetPathFragment = new PathFragment(fields[0]);
+ if (!workspaceName.isEmpty()) {
+ if (!targetPathFragment.getSegment(0).equals(workspaceName)) {
+ throw new UserExecException("Fileset manifest line must start with workspace name");
+ }
+ targetPathFragment = targetPathFragment.subFragment(1, targetPathFragment.segmentCount());
+ }
+ targetPath = targetDirectory.getRelative(targetPathFragment);
+ } else {
+ targetPath = targetDirectory.getRelative(fields[0]);
+ }
+
Path source;
- Path targetPath = targetDirectory.getRelative(fields[0]);
switch (fields.length) {
case 1:
source = targetDirectory.getFileSystem().getPath("/dev/null");
@@ -347,6 +394,7 @@ public class LinuxSandboxedStrategy implements SpawnActionContext {
default:
throw new IllegalStateException("'" + line + "' splits into more than 2 parts");
}
+
mounts.put(targetPath, source);
}
return mounts;