Skip to content

Commit 8868a9a

Browse files
tjgqcopybara-github
authored andcommitted
Always include a TreeArtifactValue in the ActionInputMap if at least one of its TreeFileArtifacts is an action input.
Removes an edge case from AbstractActionInputPrefetcher. PiperOrigin-RevId: 762350969 Change-Id: I9cbd4ac10aac19a1e997643da27632e83fb694fc
1 parent 1afba07 commit 8868a9a

File tree

2 files changed

+20
-33
lines changed

2 files changed

+20
-33
lines changed

src/main/java/com/google/devtools/build/lib/remote/AbstractActionInputPrefetcher.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ private ListenableFuture<Void> prefetchFile(
378378

379379
PathFragment execPath = input.getExecPath();
380380

381-
// Metadata may legitimately be missing, e.g. if this is an optional test output.
382381
FileArtifactValue metadata = metadataSupplier.getMetadata(input);
383382
if (metadata == null || !canDownloadFile(execRoot.getRelative(execPath), metadata)) {
383+
// Metadata may legitimately be missing, e.g. if this is an optional spawn output.
384384
return immediateVoidFuture();
385385
}
386386

@@ -441,19 +441,12 @@ private PathFragment maybeGetTreeRoot(ActionInput input, MetadataSupplier metada
441441
}
442442
SpecialArtifact treeArtifact = treeFile.getParent();
443443
FileArtifactValue treeMetadata = metadataSupplier.getMetadata(treeArtifact);
444-
if (treeMetadata == null) {
445-
// There are two cases where tree metadata is legitimately not available:
446-
// (1) If the file is the output of an action expanded from an action template. In this
447-
// case, the symlink optimization is intentionally not supported.
448-
// (2) If the file is part of an input fileset. In this case, a symlink has already been
449-
// created, but we're currently unable to prefetch the file(s) it points to.
450-
// TODO: b/401575099 - Treating fileset more like runfiles could make the tree metadata
451-
// available for case (2).
452-
return null;
453-
}
454-
PathFragment resolvedPath = treeMetadata.getResolvedPath();
455-
if (resolvedPath != null) {
456-
return resolvedPath.relativeTo(execRoot.asFragment());
444+
// Metadata may legitimately be missing, e.g. if this is an optional spawn output.
445+
if (treeMetadata != null) {
446+
PathFragment resolvedPath = treeMetadata.getResolvedPath();
447+
if (resolvedPath != null) {
448+
return resolvedPath.relativeTo(execRoot.asFragment());
449+
}
457450
}
458451
return treeArtifact.getExecPath();
459452
}
@@ -468,24 +461,15 @@ private PathFragment maybeGetTreeRoot(ActionInput input, MetadataSupplier metada
468461
*/
469462
@Nullable
470463
private Symlink maybeGetSymlink(
471-
ActionInput input,
472-
FileArtifactValue metadata,
473-
MetadataSupplier metadataSupplier)
464+
ActionInput input, FileArtifactValue metadata, MetadataSupplier metadataSupplier)
474465
throws IOException, InterruptedException {
475466
if (input instanceof TreeFileArtifact treeFile) {
476467
SpecialArtifact treeArtifact = treeFile.getParent();
477468
FileArtifactValue treeMetadata = metadataSupplier.getMetadata(treeArtifact);
478-
if (treeMetadata == null) {
479-
// There are two cases where tree metadata is legitimately not available:
480-
// (1) If the file is the output of an action expanded from an action template. In this
481-
// case, the symlink optimization is intentionally not supported.
482-
// (2) If the file is part of an input fileset. In this case, a symlink has already been
483-
// created, but we're currently unable to prefetch the file(s) it points to.
484-
// TODO: b/401575099 - Treating fileset more like runfiles could make the tree metadata
485-
// available for case (2).
486-
return null;
469+
// Metadata may legitimately be missing, e.g. if this is an optional spawn output.
470+
if (treeMetadata != null) {
471+
return maybeGetSymlink(treeArtifact, treeMetadata, metadataSupplier);
487472
}
488-
return maybeGetSymlink(treeArtifact, treeMetadata, metadataSupplier);
489473
}
490474
PathFragment execPath = input.getExecPath();
491475
PathFragment resolvedExecPath = execPath;

src/main/java/com/google/devtools/build/lib/skyframe/ActionInputMapHelper.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.google.devtools.build.lib.actions.ActionInputMap;
1717
import com.google.devtools.build.lib.actions.Artifact;
1818
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
19+
import com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact;
1920
import com.google.devtools.build.lib.actions.FileArtifactValue;
2021
import com.google.devtools.build.lib.actions.FilesetOutputTree;
2122
import com.google.devtools.build.lib.actions.RunfilesArtifactValue;
@@ -42,12 +43,14 @@ static void addToMap(
4243
consumer.accumulate(treeArtifactValue);
4344
}
4445
case ActionExecutionValue actionExecutionValue -> {
45-
// Actions resulting from the expansion of an ActionTemplate consume only one of the files
46-
// in a tree artifact. However, the input prefetcher and the Linux sandbox require access to
47-
// the tree metadata to determine the prefetch location of a tree artifact materialized as a
48-
// symlink to another (cf. TreeArtifactValue#getResolvedPath()).
49-
if (key.isChildOfDeclaredDirectory()) {
50-
SpecialArtifact treeArtifact = key.getParent();
46+
if (key instanceof TreeFileArtifact treeFileArtifact) {
47+
// Since input expansion hasn't yet occurred, it must be the case that the current action
48+
// was generated by an action template (as otherwise it would only be allowed to depend
49+
// on a tree artifact in its entirety). In this case insert the full tree metadata into
50+
// the map, as some components need it to operate properly (for example, if the tree
51+
// artifact must be materialized as a symlink to another artifact, the prefetcher needs it
52+
// to materialize the artifact correctly).
53+
SpecialArtifact treeArtifact = treeFileArtifact.getParent();
5154
TreeArtifactValue treeArtifactValue =
5255
actionExecutionValue.getTreeArtifactValue(treeArtifact);
5356
expandTreeArtifactAndPopulateArtifactData(

0 commit comments

Comments
 (0)