Skip to content

Commit

Permalink
Introduce a separate TreeArtifactCompositeFileArtifactValue class.
Browse files Browse the repository at this point in the history
In #16283, I will add a new data member to this class, which won't be shared with other uses of FileArtifactValue#createProxy. This is a preliminary no-op CL to make the subsequent change simpler.

As noted in the PR discussion, the getType() method on the proxy object currently returns REGULAR_FILE instead of DIRECTORY. I intend to fix this in a separate CL since it's unclear whether any callers rely on this.

PiperOrigin-RevId: 481913076
Change-Id: I44f721f10230ec782f7a583cdf372972376959c0
  • Loading branch information
tjgq authored and copybara-github committed Oct 18, 2022
1 parent e01e7f5 commit 5faf917
Showing 1 changed file with 81 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.io.BaseEncoding;
import com.google.devtools.build.lib.actions.ActionInput;
import com.google.devtools.build.lib.actions.ActionInputHelper;
import com.google.devtools.build.lib.actions.Artifact.ArchivedTreeArtifact;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.actions.FileContentsProxy;
import com.google.devtools.build.lib.actions.FileStateType;
import com.google.devtools.build.lib.actions.HasDigest;
import com.google.devtools.build.lib.actions.cache.MetadataDigestUtils;
Expand Down Expand Up @@ -68,7 +70,6 @@ public class TreeArtifactValue implements HasDigest, SkyValue {
private static final ImmutableSortedMap<TreeFileArtifact, FileArtifactValue> EMPTY_MAP =
childDataBuilder().buildOrThrow();

@SuppressWarnings("unchecked")
private static ImmutableSortedMap.Builder<TreeFileArtifact, FileArtifactValue>
childDataBuilder() {
return new ImmutableSortedMap.Builder<>(EXEC_PATH_COMPARATOR);
Expand Down Expand Up @@ -192,6 +193,83 @@ public static ArchivedRepresentation create(

private final boolean entirelyRemote;

/** A FileArtifactValue used to stand in for a TreeArtifactValue. */
private static final class TreeArtifactCompositeFileArtifactValue extends FileArtifactValue {
private final byte[] digest;
private final boolean isRemote;

TreeArtifactCompositeFileArtifactValue(byte[] digest, boolean isRemote) {
this.digest = digest;
this.isRemote = isRemote;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof TreeArtifactCompositeFileArtifactValue)) {
return false;
}
TreeArtifactCompositeFileArtifactValue that = (TreeArtifactCompositeFileArtifactValue) o;
return Arrays.equals(digest, that.digest);
}

@Override
public int hashCode() {
return Arrays.hashCode(digest);
}

@Override
public FileStateType getType() {
// TODO(tjgq): Try to make this a directory to match reality. I'm not sure what might break.
return FileStateType.REGULAR_FILE;
}

@Override
public byte[] getDigest() {
return digest;
}

@Override
@Nullable
public FileContentsProxy getContentsProxy() {
return null;
}

@Override
public long getSize() {
return 0;
}

@Override
public boolean wasModifiedSinceDigest(Path path) {
return false;
}

@Override
public long getModifiedTime() {
throw new UnsupportedOperationException();
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("digest", BaseEncoding.base16().lowerCase().encode(digest))
.toString();
}

@Override
protected boolean couldBeModifiedByMetadata(FileArtifactValue o) {
return false;
}

@Override
public boolean isRemote() {
return isRemote;
}
}

private TreeArtifactValue(
byte[] digest,
ImmutableSortedMap<TreeFileArtifact, FileArtifactValue> childData,
Expand All @@ -206,7 +284,7 @@ private TreeArtifactValue(
}

public FileArtifactValue getMetadata() {
return FileArtifactValue.createProxy(digest);
return new TreeArtifactCompositeFileArtifactValue(digest, entirelyRemote);
}

ImmutableSet<PathFragment> getChildPaths() {
Expand Down Expand Up @@ -294,6 +372,7 @@ public String toString() {
return MoreObjects.toStringHelper(this)
.add("digest", digest)
.add("childData", childData)
.add("archivedRepresentation", archivedRepresentation)
.toString();
}

Expand Down

0 comments on commit 5faf917

Please sign in to comment.