diff options
author | 2018-01-09 01:35:18 -0800 | |
---|---|---|
committer | 2018-01-09 01:36:41 -0800 | |
commit | 31d3bdcc0d6b6d1cd3881fdf6cf40ca3330db057 (patch) | |
tree | fdeaba38358da7ea6991d302bdc10e2b442de354 /src/main/java | |
parent | 786f31303e8a8deca4780dfaf971ba55fa391617 (diff) |
Cleanup: move some tests {ArtifactFunction,FileArtifactValue}Test
These tests don't require a full Skyframe instance, so we might as well move
them to a lighter-weight test class. Also, it turns out that we have duplicate
tests for equality and hashing - this is now explicit.
PiperOrigin-RevId: 181285144
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java | 3 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/FileArtifactValue.java | 30 |
2 files changed, 21 insertions, 12 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 4e087dbbac..a525bf236a 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 @@ -261,8 +261,7 @@ public class ActionMetadataHandler implements MetadataHandler { // metadata separately. // Use the FileValue's digest if no digest was injected, or if the file can't be digested. injectedDigest = injectedDigest != null || !isFile ? injectedDigest : data.getDigest(); - FileArtifactValue value = - FileArtifactValue.create(artifact, isFile, isFile ? data.getSize() : 0, injectedDigest); + FileArtifactValue value = FileArtifactValue.create(artifact, data, injectedDigest); FileArtifactValue oldValue = additionalOutputData.putIfAbsent(artifact, value); checkInconsistentData(artifact, oldValue, value); return metadataFromValue(value); 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 6bc9f5a1da..5a7ed29dc8 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 @@ -203,30 +203,40 @@ public abstract class FileArtifactValue implements SkyValue, Metadata { @VisibleForTesting public static FileArtifactValue create(Artifact artifact) throws IOException { - Path path = artifact.getPath(); - FileStatus stat = path.stat(); - boolean isFile = stat.isFile(); - return create(artifact, isFile, isFile ? stat.getSize() : 0, null); + return create(artifact.getPath()); } static FileArtifactValue create(Artifact artifact, FileValue fileValue) throws IOException { boolean isFile = fileValue.isFile(); - return create(artifact, isFile, isFile ? fileValue.getSize() : 0, + return create(artifact.getPath(), isFile, isFile ? fileValue.getSize() : 0, isFile ? fileValue.getDigest() : null); } - static FileArtifactValue create(Artifact artifact, boolean isFile, long size, - @Nullable byte[] digest) throws IOException { + static FileArtifactValue create( + Artifact artifact, FileValue fileValue, @Nullable byte[] injectedDigest) throws IOException { + boolean isFile = fileValue.isFile(); + return create(artifact.getPath(), isFile, isFile ? fileValue.getSize() : 0, injectedDigest); + } + + @VisibleForTesting + static FileArtifactValue create(Path path) throws IOException { + FileStatus stat = path.stat(); + boolean isFile = stat.isFile(); + return create(path, isFile, isFile ? stat.getSize() : 0, null); + } + + private static FileArtifactValue create( + Path path, boolean isFile, long size, @Nullable byte[] digest) throws IOException { if (isFile && digest == null) { - digest = DigestUtils.getDigestOrFail(artifact.getPath(), size); + digest = DigestUtils.getDigestOrFail(path, size); } if (!isFile) { // In this case, we need to store the mtime because the action cache uses mtime for // directories to determine if this artifact has changed. We want this code path to go away // somehow (maybe by implementing FileSet in Skyframe). - return new DirectoryArtifactValue(artifact.getPath().getLastModifiedTime()); + return new DirectoryArtifactValue(path.getLastModifiedTime()); } - Preconditions.checkState(digest != null, artifact); + Preconditions.checkState(digest != null, path); return createNormalFile(digest, size); } |