diff options
6 files changed, 40 insertions, 39 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java index 657b5d6e83..7e92b696db 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/DarwinSandboxedSpawnRunner.java @@ -244,7 +244,7 @@ final class DarwinSandboxedSpawnRunner extends AbstractSandboxSpawnRunner { boolean allowNetworkForThisSpawn = allowNetwork || Spawns.requiresNetwork(spawn); - Map<PathFragment, Path> inputs = SandboxHelpers.getInputFiles(spawn, context, execRoot); + Map<PathFragment, Path> inputs = SandboxHelpers.processInputFiles(spawn, context, execRoot); SandboxedSpawn sandbox; if (sandboxfsProcess != null) { diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java index 6d4fda2876..cfbfdc4859 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/DockerSandboxedSpawnRunner.java @@ -256,7 +256,7 @@ final class DockerSandboxedSpawnRunner extends AbstractSandboxSpawnRunner { sandboxExecRoot, cmdLine.build(), environment, - SandboxHelpers.getInputFiles(spawn, context, execRoot), + SandboxHelpers.processInputFiles(spawn, context, execRoot), outputs, ImmutableSet.of()); diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java index a19605b0b9..7879399463 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/LinuxSandboxedSpawnRunner.java @@ -174,7 +174,7 @@ final class LinuxSandboxedSpawnRunner extends AbstractSandboxSpawnRunner { sandboxPath, commandLineBuilder.build(), environment, - SandboxHelpers.getInputFiles(spawn, context, execRoot), + SandboxHelpers.processInputFiles(spawn, context, execRoot), outputs, ImmutableSet.of()); } else { @@ -184,7 +184,7 @@ final class LinuxSandboxedSpawnRunner extends AbstractSandboxSpawnRunner { sandboxExecRoot, commandLineBuilder.build(), environment, - SandboxHelpers.getInputFiles(spawn, context, execRoot), + SandboxHelpers.processInputFiles(spawn, context, execRoot), outputs, writableDirs); } diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java index db54f96fdc..af5444fd90 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/ProcessWrapperSandboxedSpawnRunner.java @@ -101,7 +101,7 @@ final class ProcessWrapperSandboxedSpawnRunner extends AbstractSandboxSpawnRunne sandboxExecRoot, commandLineBuilder.build(), environment, - SandboxHelpers.getInputFiles(spawn, context, execRoot), + SandboxHelpers.processInputFiles(spawn, context, execRoot), SandboxHelpers.getOutputFiles(spawn), getWritableDirs(sandboxExecRoot, environment)); diff --git a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java index 43db377e0a..29b6065a10 100644 --- a/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java +++ b/src/main/java/com/google/devtools/build/lib/sandbox/SandboxHelpers.java @@ -16,22 +16,21 @@ package com.google.devtools.build.lib.sandbox; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -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.Artifact.ArtifactExpander; +import com.google.devtools.build.lib.actions.CommandLines.ParamFileActionInput; import com.google.devtools.build.lib.actions.Spawn; import com.google.devtools.build.lib.actions.Spawns; import com.google.devtools.build.lib.actions.cache.VirtualActionInput; import com.google.devtools.build.lib.actions.cache.VirtualActionInput.EmptyActionInput; import com.google.devtools.build.lib.analysis.test.TestConfiguration; -import com.google.devtools.build.lib.exec.SpawnInputExpander; import com.google.devtools.build.lib.exec.SpawnRunner.SpawnExecutionContext; -import com.google.devtools.build.lib.rules.fileset.FilesetActionContext; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.common.options.OptionsProvider; import java.io.IOException; +import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -43,40 +42,31 @@ public final class SandboxHelpers { /** * Returns the inputs of a Spawn as a map of PathFragments relative to an execRoot to paths in the * host filesystem where the input files can be found. + * + * <p>Also writes any supported {@link VirtualActionInput}s found. + * + * @throws IOException If any files could not be written. */ - public static Map<PathFragment, Path> getInputFiles( - SpawnInputExpander spawnInputExpander, - Path execRoot, - Spawn spawn, - ActionExecutionContext executionContext) - throws IOException { - Map<PathFragment, ActionInput> inputMap = - spawnInputExpander.getInputMapping( - spawn, - executionContext.getArtifactExpander(), - executionContext.getActionInputFileCache(), - executionContext.getContext(FilesetActionContext.class)); - return postProcess(inputMap, spawn, executionContext.getArtifactExpander(), execRoot); - } - - /** - * Returns the inputs of a Spawn as a map of PathFragments relative to an execRoot to paths in the - * host filesystem where the input files can be found. - */ - public static Map<PathFragment, Path> getInputFiles( + public static Map<PathFragment, Path> processInputFiles( Spawn spawn, SpawnExecutionContext context, Path execRoot) throws IOException { - return postProcess(context.getInputMapping(), spawn, context.getArtifactExpander(), execRoot); + return processInputFiles( + context.getInputMapping(), spawn, context.getArtifactExpander(), execRoot); } /** * Returns the inputs of a Spawn as a map of PathFragments relative to an execRoot to paths in the * host filesystem where the input files can be found. + * + * <p>Also writes any supported {@link VirtualActionInput}s found. + * + * @throws IOException If any files could not be written. */ - private static Map<PathFragment, Path> postProcess( + private static Map<PathFragment, Path> processInputFiles( Map<PathFragment, ActionInput> inputMap, - Spawn spawn, + Spawn spawn, ArtifactExpander artifactExpander, - Path execRoot) { + Path execRoot) + throws IOException { // SpawnInputExpander#getInputMapping uses ArtifactExpander#expandArtifacts to expand // middlemen and tree artifacts, which expands empty tree artifacts to no entry. However, // actions that accept TreeArtifacts as inputs generally expect that the empty directory is @@ -96,15 +86,26 @@ public final class SandboxHelpers { Map<PathFragment, Path> inputFiles = new TreeMap<>(); for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) { - if (e.getValue() instanceof VirtualActionInput) { - // TODO(ulfjack): Handle all virtual inputs, e.g., by writing them to a file. - Preconditions.checkState(e.getValue() instanceof EmptyActionInput); + PathFragment pathFragment = e.getKey(); + ActionInput actionInput = e.getValue(); + if (actionInput instanceof VirtualActionInput) { + if (actionInput instanceof ParamFileActionInput) { + ParamFileActionInput paramFileInput = (ParamFileActionInput) actionInput; + Path outputPath = execRoot.getRelative(paramFileInput.getExecPath()); + outputPath.getParentDirectory().createDirectoryAndParents(); + try (OutputStream outputStream = outputPath.getOutputStream()) { + paramFileInput.writeTo(outputStream); + } + } else { + // TODO(ulfjack): Handle all virtual inputs, e.g., by writing them to a file. + Preconditions.checkState(actionInput instanceof EmptyActionInput); + } } Path inputPath = - e.getValue() instanceof EmptyActionInput + actionInput instanceof EmptyActionInput ? null - : execRoot.getRelative(e.getValue().getExecPath()); - inputFiles.put(e.getKey(), inputPath); + : execRoot.getRelative(actionInput.getExecPath()); + inputFiles.put(pathFragment, inputPath); } return inputFiles; } diff --git a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java index 122dfc7248..b9bbbe2896 100644 --- a/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java +++ b/src/main/java/com/google/devtools/build/lib/worker/WorkerSpawnRunner.java @@ -135,7 +135,7 @@ final class WorkerSpawnRunner implements SpawnRunner { HashCode workerFilesCombinedHash = WorkerFilesHash.getCombinedHash(workerFiles); - Map<PathFragment, Path> inputFiles = SandboxHelpers.getInputFiles(spawn, context, execRoot); + Map<PathFragment, Path> inputFiles = SandboxHelpers.processInputFiles(spawn, context, execRoot); Set<PathFragment> outputFiles = SandboxHelpers.getOutputFiles(spawn); WorkerKey key = |