diff options
author | 2015-09-02 15:35:42 +0000 | |
---|---|---|
committer | 2015-09-02 16:27:08 +0000 | |
commit | 27f7fb58334ad7bbebdbc6abfde5626e368ef2d9 (patch) | |
tree | 615bd801c267e7276e243eaa11bea99c03ff0906 /src/main/java/com/google | |
parent | fe98ecb944e49848622b9c2f97e8d3211d9d889f (diff) |
sandbox: Better parsing of runfiles manifest files, fixes #413.
--
MOS_MIGRATED_REVID=102145100
Diffstat (limited to 'src/main/java/com/google')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedStrategy.java | 33 |
1 files changed, 24 insertions, 9 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 b5dbb84a46..011ccbc249 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 @@ -332,20 +332,35 @@ public class LinuxSandboxedStrategy implements SpawnActionContext { private ImmutableSetMultimap<Path, Path> mountRunfilesFromManifests(Spawn spawn, Path sandboxPath) throws IOException { ImmutableSetMultimap.Builder<Path, Path> mounts = ImmutableSetMultimap.builder(); - FileSystem fs = blazeDirs.getFileSystem(); 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()); - for (String line : Files.readLines(new File(manifestFilePath), Charset.defaultCharset())) { - String[] fields = line.split(" "); - Preconditions.checkState( - fields.length == 2, "'" + line + "' does not split into exactly 2 parts"); - Path source = fs.getPath(fields[1]); - Path targetPath = targetDirectory.getRelative(fields[0]); - Path targetInSandbox = sandboxPath.getRelative(targetPath.asFragment().relativeTo("/")); - mounts.put(source, targetInSandbox); + + mounts.putAll(parseManifestFile(sandboxPath, targetDirectory, new File(manifestFilePath))); + } + return mounts.build(); + } + + static ImmutableSetMultimap<Path, Path> parseManifestFile( + Path sandboxPath, Path targetDirectory, File manifestFile) throws IOException { + ImmutableSetMultimap.Builder<Path, Path> mounts = ImmutableSetMultimap.builder(); + for (String line : Files.readLines(manifestFile, Charset.defaultCharset())) { + String[] fields = line.trim().split(" "); + Path source; + Path targetPath = targetDirectory.getRelative(fields[0]); + Path targetInSandbox = sandboxPath.getRelative(targetPath.asFragment().relativeTo("/")); + switch (fields.length) { + case 1: + source = sandboxPath.getFileSystem().getPath("/dev/null"); + break; + case 2: + source = sandboxPath.getFileSystem().getPath(fields[1]); + break; + default: + throw new IllegalStateException("'" + line + "' splits into more than 2 parts"); } + mounts.put(source, targetInSandbox); } return mounts.build(); } |