diff options
author | Rumou Duan <rduan@google.com> | 2016-04-13 21:59:21 +0000 |
---|---|---|
committer | Damien Martin-Guillerez <dmarting@google.com> | 2016-04-14 07:39:14 +0000 |
commit | a77f32c255cb210ab254a3d689e3ad7dc0fcf25c (patch) | |
tree | 2863bbdce2bf14f6282ac79307e14cedde4a49e6 /src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java | |
parent | 8bc763ce9570faa98c4dd3db3c8d261b47cad279 (diff) |
Introduce TreeFileArtifact, which represents files under TreeArtifacts.
Remove ArtifactFile, which is rendered obsolete by TreeFileArtifact.
--
MOS_MIGRATED_REVID=119789154
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java index a60ad09733..a0f2241531 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java @@ -14,13 +14,14 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Function; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.common.collect.Maps; -import com.google.devtools.build.lib.actions.ActionInputHelper; import com.google.devtools.build.lib.actions.Artifact; -import com.google.devtools.build.lib.actions.ArtifactFile; +import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact; import com.google.devtools.build.lib.actions.cache.Digest; import com.google.devtools.build.lib.actions.cache.Metadata; import com.google.devtools.build.lib.vfs.Path; @@ -36,13 +37,21 @@ import javax.annotation.Nullable; /** * Value for TreeArtifacts, which contains a digest and the {@link FileArtifactValue}s - * of its child {@link ArtifactFile}s. + * of its child {@link TreeFileArtifact}s. */ public class TreeArtifactValue extends ArtifactValue { + private static final Function<Artifact, PathFragment> PARENT_RELATIVE_PATHS = + new Function<Artifact, PathFragment>() { + @Override + public PathFragment apply(Artifact artifact) { + return artifact.getParentRelativePath(); + } + }; + private final byte[] digest; - private final Map<PathFragment, FileArtifactValue> childData; + private final Map<TreeFileArtifact, FileArtifactValue> childData; - private TreeArtifactValue(byte[] digest, Map<PathFragment, FileArtifactValue> childData) { + private TreeArtifactValue(byte[] digest, Map<TreeFileArtifact, FileArtifactValue> childData) { this.digest = digest; this.childData = ImmutableMap.copyOf(childData); } @@ -52,11 +61,13 @@ public class TreeArtifactValue extends ArtifactValue { * and their corresponding FileArtifactValues. */ @VisibleForTesting - public static TreeArtifactValue create(Map<PathFragment, FileArtifactValue> childFileValues) { + public static TreeArtifactValue create(Map<TreeFileArtifact, FileArtifactValue> childFileValues) { Map<String, Metadata> digestBuilder = Maps.newHashMapWithExpectedSize(childFileValues.size()); - for (Map.Entry<PathFragment, FileArtifactValue> e : childFileValues.entrySet()) { - digestBuilder.put(e.getKey().getPathString(), new Metadata(e.getValue().getDigest())); + for (Map.Entry<TreeFileArtifact, FileArtifactValue> e : childFileValues.entrySet()) { + digestBuilder.put( + e.getKey().getParentRelativePath().getPathString(), + new Metadata(e.getValue().getDigest())); } return new TreeArtifactValue( @@ -68,17 +79,12 @@ public class TreeArtifactValue extends ArtifactValue { return FileArtifactValue.createProxy(digest); } - /** Returns the inputs that this artifact expands to, in no particular order. */ - Iterable<ArtifactFile> getChildren(final Artifact base) { - return ActionInputHelper.asArtifactFiles(base, childData.keySet()); - } - public Metadata getMetadata() { return new Metadata(digest.clone()); } public Set<PathFragment> getChildPaths() { - return childData.keySet(); + return ImmutableSet.copyOf(Iterables.transform(childData.keySet(), PARENT_RELATIVE_PATHS)); } @Nullable @@ -86,6 +92,14 @@ public class TreeArtifactValue extends ArtifactValue { return digest.clone(); } + public Iterable<TreeFileArtifact> getChildren() { + return childData.keySet(); + } + + public FileArtifactValue getChildValue(TreeFileArtifact artifact) { + return childData.get(artifact); + } + @Override public int hashCode() { return Arrays.hashCode(digest); @@ -122,14 +136,19 @@ public class TreeArtifactValue extends ArtifactValue { * This is occasionally useful because Java's concurrent collections disallow null members. */ static final TreeArtifactValue MISSING_TREE_ARTIFACT = new TreeArtifactValue(null, - ImmutableMap.<PathFragment, FileArtifactValue>of()) { + ImmutableMap.<TreeFileArtifact, FileArtifactValue>of()) { @Override public FileArtifactValue getSelfData() { throw new UnsupportedOperationException(); } @Override - Iterable<ArtifactFile> getChildren(Artifact base) { + public Iterable<TreeFileArtifact> getChildren() { + throw new UnsupportedOperationException(); + } + + @Override + public FileArtifactValue getChildValue(TreeFileArtifact artifact) { throw new UnsupportedOperationException(); } |