diff options
author | ulfjack <ulfjack@google.com> | 2017-07-12 12:10:11 +0200 |
---|---|---|
committer | László Csomor <laszlocsomor@google.com> | 2017-07-12 16:02:39 +0200 |
commit | 264f40fb42ce1390f9ee420f923b77ef3a82327f (patch) | |
tree | 11e16746189e6ee28b57c9294f8570715e4edb87 /src/main/java/com/google/devtools/build/lib/worker | |
parent | 423a46a11acd109467573c3344a4dd49f211aea6 (diff) |
Rewrite all the sandbox strategy implementations
- Make use of existing abstractions like SpawnRunner and SpawnExecutionPolicy.
- Instead of having the *Strategy create a *Runner, and then call back into
SandboxStrategy, create a single SandboxContainer which contains the full
command line, environment, and everything needed to create and delete the
sandbox directory.
- Do all the work in SandboxStrategy, including creation and deletion of the
sandbox directory.
- Use SpawnResult instead of throwing, catching, and rethrowing.
- Simplify the control flow a bit.
PiperOrigin-RevId: 161644979
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/worker')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/worker/SandboxedWorker.java | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/worker/SandboxedWorker.java b/src/main/java/com/google/devtools/build/lib/worker/SandboxedWorker.java index 7192c3e029..a06ddc0114 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/SandboxedWorker.java +++ b/src/main/java/com/google/devtools/build/lib/worker/SandboxedWorker.java @@ -14,8 +14,10 @@ package com.google.devtools.build.lib.worker; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import com.google.devtools.build.lib.sandbox.SymlinkedExecRoot; +import com.google.devtools.build.lib.sandbox.SymlinkedSandboxedSpawn; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; import java.io.IOException; @@ -23,30 +25,46 @@ import java.io.IOException; /** A {@link Worker} that runs inside a sandboxed execution root. */ final class SandboxedWorker extends Worker { private final Path workDir; - private final SymlinkedExecRoot symlinkedExecRoot; SandboxedWorker(WorkerKey workerKey, int workerId, Path workDir, Path logFile) { super(workerKey, workerId, workDir, logFile); this.workDir = workDir; - this.symlinkedExecRoot = new SymlinkedExecRoot(workDir); } @Override void destroy() throws IOException { super.destroy(); - if (symlinkedExecRoot != null) { - FileSystemUtils.deleteTree(workDir); - } + FileSystemUtils.deleteTree(workDir); } @Override public void prepareExecution(WorkerKey key) throws IOException { - symlinkedExecRoot.createFileSystem( - key.getInputFiles(), key.getOutputFiles(), ImmutableSet.<Path>of()); + // Note: the key passed in here may be different from the key passed to the constructor for + // subsequent invocations of the same worker. + // TODO(ulfjack): Remove WorkerKey.getInputFiles and WorkerKey.getOutputFiles; they are only + // used to pass information to this method and the method below. Instead, don't pass the + // WorkerKey to this method but only the input and output files. + new SymlinkedSandboxedSpawn( + workDir, + workDir, + ImmutableList.of("/does_not_exist"), + ImmutableMap.<String, String>of(), + key.getInputFiles(), + key.getOutputFiles(), + ImmutableSet.<Path>of()).createFileSystem(); } @Override public void finishExecution(WorkerKey key) throws IOException { - symlinkedExecRoot.copyOutputs(key.getExecRoot(), key.getOutputFiles()); + // Note: the key passed in here may be different from the key passed to the constructor for + // subsequent invocations of the same worker. + new SymlinkedSandboxedSpawn( + workDir, + workDir, + ImmutableList.of("/does_not_exist"), + ImmutableMap.<String, String>of(), + key.getInputFiles(), + key.getOutputFiles(), + ImmutableSet.<Path>of()).copyOutputs(key.getExecRoot()); } } |