diff --git a/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java b/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java index f7a9e0734a44e8..23eab4188037c9 100644 --- a/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java +++ b/src/main/java/com/google/devtools/build/lib/actions/ActionInputHelper.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander; import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact; import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; +import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; import java.util.ArrayList; import java.util.Collection; @@ -218,4 +219,14 @@ public static List expandArtifacts(Iterable public static Iterable toExecPaths(Iterable artifacts) { return Iterables.transform(artifacts, EXEC_PATH_STRING_FORMATTER); } + + /** Returns the {@link Path} for an {@link ActionInput}. */ + public static Path toPath(ActionInput input, Path execRoot) { + Preconditions.checkNotNull(input, "input"); + Preconditions.checkNotNull(execRoot, "execRoot"); + + return (input instanceof Artifact) + ? ((Artifact) input).getPath() + : execRoot.getRelative(input.getExecPath()); + } } 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 683024e7a7fd6e..ee1ad40ebfb75c 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 @@ -16,7 +16,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.google.devtools.build.lib.actions.ActionInput; -import com.google.devtools.build.lib.actions.Artifact; +import com.google.devtools.build.lib.actions.ActionInputHelper; import com.google.devtools.build.lib.actions.DigestOfDirectoryException; import com.google.devtools.build.lib.actions.FileArtifactValue; import com.google.devtools.build.lib.actions.MetadataProvider; @@ -60,10 +60,7 @@ public FileArtifactValue getMetadata(ActionInput input) throws IOException { .get( input.getExecPathString(), () -> { - Path path = - (input instanceof Artifact) - ? ((Artifact) input).getPath() - : execRoot.getRelative(input.getExecPath()); + Path path = ActionInputHelper.toPath(input, execRoot); try { FileArtifactValue metadata = FileArtifactValue.create(path); if (metadata.getType().isDirectory()) { diff --git a/src/main/java/com/google/devtools/build/lib/remote/TreeNodeRepository.java b/src/main/java/com/google/devtools/build/lib/remote/TreeNodeRepository.java index f684ac5fb96309..1336a3fa47bbcc 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/TreeNodeRepository.java +++ b/src/main/java/com/google/devtools/build/lib/remote/TreeNodeRepository.java @@ -340,7 +340,7 @@ private TreeNode buildParentNode( Preconditions.checkArgument( inputsStart == inputsEnd - 1, "Encountered two inputs with the same path."); ActionInput input = inputs.get(inputsStart); - Path leafPath = execRoot.getRelative(input.getExecPathString()); + Path leafPath = ActionInputHelper.toPath(input, execRoot); if (!(input instanceof VirtualActionInput) && uploadSymlinks) { FileStatus stat = leafPath.stat(Symlinks.NOFOLLOW); if (stat.isSymbolicLink()) { @@ -405,7 +405,7 @@ private synchronized Directory getOrComputeDirectory(TreeNode node) throws IOExc if (uploadSymlinks) { // We need to stat the input to check whether it is a symlink. // getInputMetadata only gives target metadata. - Path inputPath = execRoot.getRelative(input.getExecPath()); + Path inputPath = ActionInputHelper.toPath(input, execRoot); FileStatus stat = inputPath.stat(Symlinks.NOFOLLOW); if (stat.isSymbolicLink()) { PathFragment target = inputPath.readSymbolicLink();