From a77f32c255cb210ab254a3d689e3ad7dc0fcf25c Mon Sep 17 00:00:00 2001 From: Rumou Duan Date: Wed, 13 Apr 2016 21:59:21 +0000 Subject: Introduce TreeFileArtifact, which represents files under TreeArtifacts. Remove ArtifactFile, which is rendered obsolete by TreeFileArtifact. -- MOS_MIGRATED_REVID=119789154 --- .../build/lib/skyframe/TreeArtifactValue.java | 51 +++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/TreeArtifactValue.java') 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 PARENT_RELATIVE_PATHS = + new Function() { + @Override + public PathFragment apply(Artifact artifact) { + return artifact.getParentRelativePath(); + } + }; + private final byte[] digest; - private final Map childData; + private final Map childData; - private TreeArtifactValue(byte[] digest, Map childData) { + private TreeArtifactValue(byte[] digest, Map 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 childFileValues) { + public static TreeArtifactValue create(Map childFileValues) { Map digestBuilder = Maps.newHashMapWithExpectedSize(childFileValues.size()); - for (Map.Entry e : childFileValues.entrySet()) { - digestBuilder.put(e.getKey().getPathString(), new Metadata(e.getValue().getDigest())); + for (Map.Entry 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 getChildren(final Artifact base) { - return ActionInputHelper.asArtifactFiles(base, childData.keySet()); - } - public Metadata getMetadata() { return new Metadata(digest.clone()); } public Set 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 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.of()) { + ImmutableMap.of()) { @Override public FileArtifactValue getSelfData() { throw new UnsupportedOperationException(); } @Override - Iterable getChildren(Artifact base) { + public Iterable getChildren() { + throw new UnsupportedOperationException(); + } + + @Override + public FileArtifactValue getChildValue(TreeFileArtifact artifact) { throw new UnsupportedOperationException(); } -- cgit v1.2.3