Make the FileArtifactvalue of generated targets available via the FilesetOutputSymlink whenever available.
In this change I'm simply plumbing the FileArtifactValue we requested within RecursiveFilesystemTraversalFunction to the FilesetOutputSymlink.
This does not work when the targets are output directories (or symlink to output dirs). The main scenarios this happens is when:
1. Fileset depends on the output dir created by a genrule.
2. Fileset depends on a GoAppengineBinary which creates an output dir.
3. Fileset depends on another Fileset in the non-recommended way (Fileset.entry.files = [<another_fileset>]) instead of the recommended way (FilesetEntry.srcdir = <another_fileset>).
RELNOTES: None
PiperOrigin-RevId: 204209612
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index d91e46e..818d227 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -203,13 +203,19 @@
final FileStateValue metadata;
@Nullable final RootedPath realPath;
@Nullable final PathFragment unresolvedSymlinkTarget;
+ @Nullable final FileArtifactValue fileArtifactValue;
- FileInfo(FileType type, FileStateValue metadata, @Nullable RootedPath realPath,
- @Nullable PathFragment unresolvedSymlinkTarget) {
+ FileInfo(
+ FileType type,
+ FileStateValue metadata,
+ @Nullable RootedPath realPath,
+ @Nullable PathFragment unresolvedSymlinkTarget,
+ @Nullable FileArtifactValue fileArtifactValue) {
this.type = Preconditions.checkNotNull(type);
this.metadata = Preconditions.checkNotNull(metadata);
this.realPath = realPath;
this.unresolvedSymlinkTarget = unresolvedSymlinkTarget;
+ this.fileArtifactValue = fileArtifactValue;
}
@Override
@@ -226,7 +232,7 @@
private static FileInfo lookUpFileInfo(Environment env, TraversalRequest traversal)
throws MissingDepException, IOException, InterruptedException {
if (traversal.isRootGenerated) {
- byte[] digest = null;
+ FileArtifactValue fsVal = null;
if (traversal.root.getOutputArtifact() != null) {
Artifact artifact = traversal.root.getOutputArtifact();
SkyKey artifactKey = ArtifactSkyKey.key(artifact, true);
@@ -236,11 +242,9 @@
}
if (value instanceof FileArtifactValue) {
- FileArtifactValue fsVal = (FileArtifactValue) value;
- digest = fsVal.getDigest();
+ fsVal = (FileArtifactValue) value;
} else {
- return new FileInfo(
- FileType.NONEXISTENT, null, null, null);
+ return new FileInfo(FileType.NONEXISTENT, null, null, null, null);
}
}
@@ -269,10 +273,15 @@
path.resolveSymbolicLinks());
type = followStat.isFile() ? FileType.SYMLINK_TO_FILE : FileType.SYMLINK_TO_DIRECTORY;
}
- return new FileInfo(type,
- FileStateValue.createWithStatNoFollow(traversal.root.asRootedPath(),
- new StatWithDigest(noFollowStat, digest), null),
- realPath, unresolvedLinkTarget);
+ return new FileInfo(
+ type,
+ FileStateValue.createWithStatNoFollow(
+ traversal.root.asRootedPath(),
+ new StatWithDigest(noFollowStat, fsVal != null ? fsVal.getDigest() : null),
+ null),
+ realPath,
+ unresolvedLinkTarget,
+ fsVal);
} else {
// Stat the file.
FileValue fileValue =
@@ -292,14 +301,20 @@
} else {
type = fileValue.isDirectory() ? FileType.DIRECTORY : FileType.FILE;
}
- return new FileInfo(type, fileValue.realFileStateValue(),
- fileValue.realRootedPath(), unresolvedLinkTarget);
+ return new FileInfo(
+ type,
+ fileValue.realFileStateValue(),
+ fileValue.realRootedPath(),
+ unresolvedLinkTarget,
+ null);
} else {
// If it doesn't exist, or it's a dangling symlink, we still want to handle that gracefully.
return new FileInfo(
fileValue.isSymlink() ? FileType.DANGLING_SYMLINK : FileType.NONEXISTENT,
- fileValue.realFileStateValue(), null,
- fileValue.isSymlink() ? fileValue.getUnresolvedLinkTarget() : null);
+ fileValue.realFileStateValue(),
+ null,
+ fileValue.isSymlink() ? fileValue.getUnresolvedLinkTarget() : null,
+ null);
}
}
}
@@ -436,7 +451,8 @@
Preconditions.checkState(info.type.isSymlink() && !info.type.exists(), "{%s} {%s}", linkName,
info.type);
return RecursiveFilesystemTraversalValue.of(
- ResolvedFileFactory.danglingSymlink(linkName, info.unresolvedSymlinkTarget, info.metadata));
+ ResolvedFileFactory.danglingSymlink(
+ linkName, info.unresolvedSymlinkTarget, info.metadata, info.fileArtifactValue));
}
/**
@@ -452,10 +468,14 @@
if (info.type.isSymlink()) {
return RecursiveFilesystemTraversalValue.of(
ResolvedFileFactory.symlinkToFile(
- info.realPath, path, info.unresolvedSymlinkTarget, info.metadata));
+ info.realPath,
+ path,
+ info.unresolvedSymlinkTarget,
+ info.metadata,
+ info.fileArtifactValue));
} else {
return RecursiveFilesystemTraversalValue.of(
- ResolvedFileFactory.regularFile(path, info.metadata));
+ ResolvedFileFactory.regularFile(path, info.metadata, info.fileArtifactValue));
}
}
@@ -474,7 +494,8 @@
rootInfo.realPath,
traversal.root.asRootedPath(),
rootInfo.unresolvedSymlinkTarget,
- hashDirectorySymlink(children, rootInfo.metadata.hashCode()));
+ hashDirectorySymlink(children, rootInfo.metadata.hashCode()),
+ rootInfo.fileArtifactValue);
paths = NestedSetBuilder.<ResolvedFile>stableOrder().addTransitive(children).add(root);
} else {
root = ResolvedFileFactory.directory(rootInfo.realPath);