diff options
5 files changed, 41 insertions, 32 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionInputFileCache.java b/src/main/java/com/google/devtools/build/lib/actions/ActionInputFileCache.java index b45e9cd65a..79c8785e92 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionInputFileCache.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionInputFileCache.java @@ -13,9 +13,9 @@ // limitations under the License. package com.google.devtools.build.lib.actions; +import com.google.devtools.build.lib.vfs.Path; import com.google.protobuf.ByteString; -import java.io.File; import java.io.IOException; import javax.annotation.Nullable; @@ -70,8 +70,16 @@ public interface ActionInputFileCache { * based on files previously seen as inputs. * * @param digest the digest. - * @return a File path. + * @return an ActionInput corresponding to the given digest. */ @Nullable - File getFileFromDigest(ByteString digest) throws IOException; + ActionInput getInputFromDigest(ByteString digest) throws IOException; + + /** + * The absolute path that this input is located at. The usual {@link ActionInput} implementation + * is {@link Artifact}, which currently embeds its full path, so implementations should just + * return this path if {@code input} is an {@link Artifact}. Otherwise, implementations should + * resolve the relative path into an absolute one and return that. + */ + Path getInputPath(ActionInput input); } diff --git a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java index 8ec1e51583..64df5c166b 100644 --- a/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java +++ b/src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java @@ -99,9 +99,13 @@ public class SingleBuildFileCache implements ActionInputFileCache { @Nullable @Override - public File getFileFromDigest(ByteString digest) { - ActionInput relPath = digestToPath.get(digest); - return relPath == null ? null : new File(fullPath(relPath)); + public ActionInput getInputFromDigest(ByteString digest) { + return digestToPath.get(digest); + } + + @Override + public Path getInputPath(ActionInput input) { + return fs.getPath(fullPath(input)); } @Override diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java index cf153439f3..d0ac469dda 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java @@ -295,8 +295,7 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver } // This may be recreated if we discover inputs. - PerActionFileCache perActionFileCache = - new PerActionFileCache(state.inputArtifactData, skyframeActionExecutor.getExecRoot()); + PerActionFileCache perActionFileCache = new PerActionFileCache(state.inputArtifactData); ActionExecutionContext actionExecutionContext = skyframeActionExecutor.constructActionExecutionContext(perActionFileCache, metadataHandler, state.expandedMiddlemen); @@ -323,8 +322,7 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver return null; } state.inputArtifactData = inputArtifactData; - perActionFileCache = - new PerActionFileCache(state.inputArtifactData, skyframeActionExecutor.getExecRoot()); + perActionFileCache = new PerActionFileCache(state.inputArtifactData); metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm); actionExecutionContext = diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PerActionFileCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/PerActionFileCache.java index 5dde5a5346..b375facd60 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PerActionFileCache.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PerActionFileCache.java @@ -20,9 +20,9 @@ import com.google.common.io.BaseEncoding; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionInputFileCache; import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.vfs.Path; import com.google.protobuf.ByteString; -import java.io.File; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.Map; @@ -39,7 +39,6 @@ import javax.annotation.Nullable; */ class PerActionFileCache implements ActionInputFileCache { private final Map<Artifact, FileArtifactValue> inputArtifactData; - private final File execRoot; // Populated lazily, on calls to #getDigest. private final Map<ByteString, Artifact> reverseMap = new ConcurrentHashMap<>(); @@ -47,13 +46,9 @@ class PerActionFileCache implements ActionInputFileCache { /** * @param inputArtifactData Map from artifact to metadata, used to return metadata upon request. - * @param execRoot Path to the execution root, used to convert Artifacts' relative paths into - * absolute ones in the execution root. */ - PerActionFileCache(Map<Artifact, FileArtifactValue> inputArtifactData, - File execRoot) { + PerActionFileCache(Map<Artifact, FileArtifactValue> inputArtifactData) { this.inputArtifactData = Preconditions.checkNotNull(inputArtifactData); - this.execRoot = Preconditions.checkNotNull(execRoot); } @Nullable @@ -75,13 +70,13 @@ class PerActionFileCache implements ActionInputFileCache { @Nullable @Override - public File getFileFromDigest(ByteString digest) throws IOException { - Artifact artifact = reverseMap.get(digest); - if (artifact != null) { - String relPath = artifact.getExecPathString(); - return new File(execRoot, relPath); - } - return null; + public Artifact getInputFromDigest(ByteString digest) throws IOException { + return reverseMap.get(digest); + } + + @Override + public Path getInputPath(ActionInput input) { + return ((Artifact) input).getPath(); } @Nullable diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java index e76990c04a..616e06229e 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java @@ -67,7 +67,6 @@ import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.Symlinks; import com.google.protobuf.ByteString; -import java.io.File; import java.io.IOException; import java.util.Collection; import java.util.HashSet; @@ -353,10 +352,6 @@ public final class SkyframeActionExecutor { this.executorEngine = null; } - File getExecRoot() { - return executorEngine.getExecRoot().getPathFile(); - } - boolean probeActionExecution(Action action) { return buildActionMap.containsKey(action.getPrimaryOutput()); } @@ -1061,9 +1056,18 @@ public final class SkyframeActionExecutor { @Nullable @Override - public File getFileFromDigest(ByteString digest) throws IOException { - File file = perActionCache.getFileFromDigest(digest); - return file != null ? file : perBuildFileCache.getFileFromDigest(digest); + public ActionInput getInputFromDigest(ByteString digest) throws IOException { + ActionInput file = perActionCache.getInputFromDigest(digest); + return file != null ? file : perBuildFileCache.getInputFromDigest(digest); + } + + @Override + public Path getInputPath(ActionInput input) { + if (input instanceof Artifact) { + return perActionCache.getInputPath(input); + } else { + return perBuildFileCache.getInputPath(input); + } } } } |