diff options
author | 2017-06-22 11:15:45 +0200 | |
---|---|---|
committer | 2017-06-22 12:50:45 +0200 | |
commit | fb67447f8d881a3a1ad9691e3234dd757d63a0cf (patch) | |
tree | 2db10f45de5932cce077d6fbb39d07923025d0b2 /src/main/java/com | |
parent | 65cda4f219e564ccb190b2992151658dfae99040 (diff) |
Make Metadata fields private
Adjust the interface of Metadata to match the interface of FileArtifactValue.
These classes are almost the same, but not quite, so we currently have to
create and return new objects whenever the MetadataHandler is called; by making
the interfaces identical, we can just return a FileArtifactValue instead (in a
future change).
This is in preparation for merging the ActionInputFileCache and MetadataHandler
interfaces.
PiperOrigin-RevId: 159802834
Diffstat (limited to 'src/main/java/com')
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(); } }); |