aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Janak Ramakrishnan <janakr@google.com>2015-03-16 16:27:31 +0000
committerGravatar Han-Wen Nienhuys <hanwen@google.com>2015-03-16 17:35:19 +0000
commit0e1b962154e9dd90b4504a035e2fcd7ecac75846 (patch)
treeb0ee7e159fc25d0f6a35283b6d3a4056ee413022 /src
parent756ef572e042d629d12d756f100380e3ccf66746 (diff)
Return ActionInput objects from the ActionInputFileCache when given a digest to do a reverse lookup so that metadata can be more easily retrieved.
-- MOS_MIGRATED_REVID=88733565
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/ActionInputFileCache.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/exec/SingleBuildFileCache.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/FileAndMetadataCache.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/SkyframeActionExecutor.java17
4 files changed, 44 insertions, 21 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..ddbe12a14a 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
@@ -23,6 +23,7 @@ import com.google.common.collect.Maps;
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.actions.DigestOfDirectoryException;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.vfs.FileSystem;
@@ -99,9 +100,16 @@ 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) {
+ if (input instanceof Artifact) {
+ return ((Artifact) input).getPath();
+ }
+ return fs.getPath(fullPath(input));
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileAndMetadataCache.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileAndMetadataCache.java
index 5014c0f5f4..69fb15ebab 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/FileAndMetadataCache.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileAndMetadataCache.java
@@ -38,7 +38,6 @@ import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.skyframe.SkyFunction;
import com.google.protobuf.ByteString;
-import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
@@ -72,7 +71,7 @@ public class FileAndMetadataCache implements ActionInputFileCache, MetadataHandl
/** This should never be read directly. Use {@link #getInputFileArtifactValue} instead. */
private final Map<Artifact, FileArtifactValue> inputArtifactData;
private final Map<Artifact, Collection<Artifact>> expandedInputMiddlemen;
- private final File execRoot;
+ private final Path execRoot;
private final Map<ByteString, Artifact> reverseMap = new ConcurrentHashMap<>();
private final ConcurrentMap<Artifact, FileValue> outputArtifactData =
new ConcurrentHashMap<>();
@@ -88,7 +87,7 @@ public class FileAndMetadataCache implements ActionInputFileCache, MetadataHandl
private static final Interner<ByteString> BYTE_INTERNER = Interners.newWeakInterner();
public FileAndMetadataCache(Map<Artifact, FileArtifactValue> inputArtifactData,
- Map<Artifact, Collection<Artifact>> expandedInputMiddlemen, File execRoot,
+ Map<Artifact, Collection<Artifact>> expandedInputMiddlemen, Path execRoot,
Iterable<Artifact> outputs, @Nullable SkyFunction.Environment env,
TimestampGranularityMonitor tsgm) {
this.inputArtifactData = Preconditions.checkNotNull(inputArtifactData);
@@ -410,13 +409,16 @@ public class FileAndMetadataCache implements ActionInputFileCache, MetadataHandl
@Nullable
@Override
- public File getFileFromDigest(ByteString digest) throws IOException {
- Artifact artifact = reverseMap.get(digest);
- if (artifact != null) {
- String relPath = artifact.getExecPathString();
- return relPath.startsWith("/") ? new File(relPath) : new File(execRoot, relPath);
+ public Artifact getInputFromDigest(ByteString digest) throws IOException {
+ return reverseMap.get(digest);
+ }
+
+ @Override
+ public Path getInputPath(ActionInput input) {
+ if (input instanceof Artifact) {
+ return ((Artifact) input).getPath();
}
- return null;
+ return execRoot.getRelative(input.getExecPathString());
}
@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 7b71fba451..d7d713ba09 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
@@ -71,7 +71,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;
@@ -455,8 +454,8 @@ public final class SkyframeActionExecutor {
this.executorEngine = null;
}
- File getExecRoot() {
- return executorEngine.getExecRoot().getPathFile();
+ Path getExecRoot() {
+ return executorEngine.getExecRoot();
}
boolean probeActionExecution(Action action) {
@@ -1161,9 +1160,15 @@ 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) {
+ // Resolving an input only requires the execRoot, which the per-action cache has.
+ return perActionCache.getInputPath(input);
}
}
}