aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java11
-rw-r--r--src/main/java/com/google/devtools/build/lib/actions/cache/Metadata.java30
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java2
3 files changed, 34 insertions, 9 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java b/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
index aaf8b1d459..cae2a547af 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/DigestUtils.java
@@ -313,13 +313,12 @@ public class DigestUtils {
if (md == null) {
// Move along, nothing to see here.
- } else if (md.digest == null) {
- // Use the timestamp if the digest is not present, but not both.
- // Modifying a timestamp while keeping the contents of a file the
- // same should not cause rebuilds.
- fp.addLong(md.mtime);
+ } else if (md.isFile()) {
+ fp.addBytes(md.getDigest());
} else {
- fp.addBytes(md.digest);
+ // Use the timestamp if the digest is not present, but not both. Modifying a timestamp while
+ // keeping the contents of a file the same should not cause rebuilds.
+ fp.addLong(md.getModifiedTime());
}
return fp.digestAndReset();
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/cache/Metadata.java b/src/main/java/com/google/devtools/build/lib/actions/cache/Metadata.java
index 316fd234e5..0f5a037ac9 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/cache/Metadata.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/cache/Metadata.java
@@ -33,23 +33,49 @@ import java.util.Date;
*/
@Immutable @ThreadSafe
public final class Metadata {
- public final long mtime;
- public final byte[] digest;
+ private final long mtime;
+ private final byte[] digest;
// Convenience object for use with volatile files that we do not want checked
// (e.g. the build-changelist.txt)
public static final Metadata CONSTANT_METADATA = new Metadata(-1);
+ /**
+ * Construct an instance for a directory with the specified mtime. The {@link #isFile} method
+ * returns true if and only if a digest is set.
+ */
public Metadata(long mtime) {
this.mtime = mtime;
this.digest = null;
}
+ /**
+ * Construct an instance for a file with the specified digest. The {@link #isFile} method returns
+ * true if and only if a digest is set.
+ */
public Metadata(byte[] digest) {
this.mtime = 0L;
this.digest = Preconditions.checkNotNull(digest);
}
+ public boolean isFile() {
+ return digest != null;
+ }
+
+ /**
+ * Returns the digest for the underlying file system object.
+ *
+ * <p>The return value is owned by the cache and must not be modified.
+ */
+ public byte[] getDigest() {
+ Preconditions.checkState(digest != null);
+ return digest;
+ }
+
+ public long getModifiedTime() {
+ return mtime;
+ }
+
@Override
public int hashCode() {
int hash = 0;
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java b/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java
index 4ab7f74dcd..e153a60c41 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/ApkManifestAction.java
@@ -113,7 +113,7 @@ public final class ApkManifestAction extends AbstractFileWriteAction {
ApkManifestCreator manifestCreator = new ApkManifestCreator(new ArtifactDigester() {
@Override
public byte[] getDigest(Artifact artifact) throws IOException {
- return ctx.getMetadataHandler().getMetadata(artifact).digest;
+ return ctx.getMetadataHandler().getMetadata(artifact).getDigest();
}
});