aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/skyframe
diff options
context:
space:
mode:
authorGravatar shahan <shahan@google.com>2018-04-26 10:09:05 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-26 10:10:49 -0700
commite27b6bdd6f91efaae3d1b7b930e902b010aeefb6 (patch)
tree61123f8698d922d84528a6b689e33a535dbcb146 /src/main/java/com/google/devtools/build/lib/skyframe
parent67423ddc06a925ce80eb574adb8d7519ab39f348 (diff)
Adds support for remote files.
PiperOrigin-RevId: 194413337
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe')
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java44
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java64
2 files changed, 108 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
index c8098064aa..fe6e8afb61 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
@@ -467,6 +467,50 @@ public class ActionMetadataHandler implements MetadataHandler {
}
@Override
+ public void injectRemoteFile(
+ Artifact output, byte[] digest, long size, long modifiedTime, int locationIndex) {
+ Preconditions.checkState(
+ executionMode.get(), "Tried to inject %s outside of execution.", output);
+ Preconditions.checkArgument(
+ locationIndex != 0 || size == 0,
+ "output = %s, size = %s, locationIndex =%s",
+ output,
+ size,
+ locationIndex);
+
+ Preconditions.checkState(injectedFiles.add(output), output);
+
+ // TODO(shahan): there are a couple of things that could reduce memory usage
+ // 1. We might be able to skip creating an entry in `outputArtifactData` and only create
+ // the `FileArtifactValue`, but there are likely downstream consumers that expect it that
+ // would need to be cleaned up.
+ // 2. Instead of creating an `additionalOutputData` entry, we could add the extra
+ // `locationIndex` to `FileStateValue`.
+ FileStateValue fileStateValue =
+ new FileStateValue.RegularFileStateValue(size, digest, /*contentsProxy=*/ null);
+ RootedPath rootedPath =
+ RootedPath.toRootedPath(output.getRoot().getRoot(), output.getRootRelativePath());
+ FileValue value = FileValue.value(rootedPath, fileStateValue, rootedPath, fileStateValue);
+ FileValue oldFsValue = outputArtifactData.putIfAbsent(output, value);
+ try {
+ checkInconsistentData(output, oldFsValue, value);
+ } catch (IOException e) {
+ // Should never happen.
+ throw new IllegalStateException("Inconsistent FileValues for " + output, e);
+ }
+
+ FileArtifactValue artifactValue =
+ new FileArtifactValue.RemoteFileArtifactValue(digest, size, modifiedTime, locationIndex);
+ FileArtifactValue oldArtifactValue = additionalOutputData.putIfAbsent(output, artifactValue);
+ try {
+ checkInconsistentData(output, oldArtifactValue, artifactValue);
+ } catch (IOException e) {
+ // Should never happen.
+ throw new IllegalStateException("Inconsistent FileArtifactValues for " + output, e);
+ }
+ }
+
+ @Override
public void markOmitted(ActionInput output) {
Preconditions.checkState(executionMode.get());
if (output instanceof Artifact) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java
index 8d171873ae..fbbdca186e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java
@@ -238,6 +238,70 @@ public abstract class FileArtifactValue implements SkyValue, Metadata {
}
}
+ static final class RemoteFileArtifactValue extends FileArtifactValue {
+ private final byte[] digest;
+ private final long size;
+ private final long modifiedTime;
+ private final int locationIndex;
+
+ RemoteFileArtifactValue(byte[] digest, long size, long modifiedTime, int locationIndex) {
+ this.digest = digest;
+ this.size = size;
+ this.modifiedTime = modifiedTime;
+ this.locationIndex = locationIndex;
+ }
+
+ @Override
+ public FileStateType getType() {
+ return FileStateType.REGULAR_FILE;
+ }
+
+ @Override
+ public byte[] getDigest() {
+ return digest;
+ }
+
+ @Override
+ public long getSize() {
+ return size;
+ }
+
+ @Override
+ public long getModifiedTime() {
+ return modifiedTime;
+ }
+
+ @Override
+ public int getLocationIndex() {
+ return locationIndex;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (!(o instanceof RemoteFileArtifactValue)) {
+ return false;
+ }
+ RemoteFileArtifactValue r = (RemoteFileArtifactValue) o;
+ return Arrays.equals(digest, r.digest)
+ && size == r.size
+ && modifiedTime == r.modifiedTime
+ && locationIndex == r.locationIndex;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(Arrays.hashCode(digest), size, modifiedTime, locationIndex);
+ }
+
+ @Override
+ public boolean wasModifiedSinceDigest(Path path) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
static FileArtifactValue create(Artifact artifact, FileValue fileValue) throws IOException {
boolean isFile = fileValue.isFile();
FileContentsProxy proxy = getProxyFromFileStateValue(fileValue.realFileStateValue());