Always create TreeArtifactValue through a builder.
Ensures that no unnecessary (unsorted) temporary maps are created prior to the ImmutableSortedMap being created for the final TreeArtifactValue.
MetadataInjector becomes aware of TreeArtifactValue now that the dependency cycle is broken after work in b/161911915, so it can take the TreeArtifactValue instead of a map of its children. The method is renamed to injectTree.
RELNOTES: None.
PiperOrigin-RevId: 323080321
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
index b4753f4..06c5861 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTest.java
@@ -51,7 +51,6 @@
import com.google.devtools.build.lib.vfs.FileStatus;
import com.google.devtools.build.lib.vfs.FileStatusWithDigestAdapter;
import com.google.devtools.build.lib.vfs.FileSystem;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.PathFragment;
import com.google.devtools.build.lib.vfs.Root;
@@ -324,10 +323,10 @@
Path path = treeFileArtifact.getPath();
path.getParentDirectory().createDirectoryAndParents();
writeFile(path, "contents");
- TreeArtifactValue treeArtifactValue =
- TreeArtifactValue.create(
- ImmutableMap.of(
- treeFileArtifact, FileArtifactValue.createForTesting(treeFileArtifact)));
+ TreeArtifactValue tree =
+ TreeArtifactValue.newBuilder(treeArtifact)
+ .putChild(treeFileArtifact, FileArtifactValue.createForTesting(treeFileArtifact))
+ .build();
DerivedArtifact artifact3 = createDerivedArtifact("three");
FilesetOutputSymlink filesetOutputSymlink =
FilesetOutputSymlink.createForTesting(
@@ -335,7 +334,7 @@
ActionExecutionValue actionExecutionValue =
ActionExecutionValue.create(
ImmutableMap.of(artifact1, metadata1, artifact3, FileArtifactValue.DEFAULT_MIDDLEMAN),
- ImmutableMap.of(treeArtifact, treeArtifactValue),
+ ImmutableMap.of(treeArtifact, tree),
ImmutableList.of(filesetOutputSymlink),
null,
true);
@@ -349,7 +348,7 @@
}
private static void file(Path path, String contents) throws Exception {
- FileSystemUtils.createDirectoryAndParents(path.getParentDirectory());
+ path.getParentDirectory().createDirectoryAndParents();
writeFile(path, contents);
}
@@ -493,16 +492,19 @@
Preconditions.checkState(!output.isTreeArtifact(), "Cannot omit %s", output);
artifactData.put(output, FileArtifactValue.OMITTED_FILE_MARKER);
} else if (output.isTreeArtifact()) {
+ SpecialArtifact parent = (SpecialArtifact) output;
TreeFileArtifact treeFileArtifact1 =
TreeFileArtifact.createTreeOutput((SpecialArtifact) output, "child1");
TreeFileArtifact treeFileArtifact2 =
TreeFileArtifact.createTreeOutput((SpecialArtifact) output, "child2");
- TreeArtifactValue treeArtifactValue =
- TreeArtifactValue.create(
- ImmutableMap.of(
- treeFileArtifact1, FileArtifactValue.createForTesting(treeFileArtifact1),
- treeFileArtifact2, FileArtifactValue.createForTesting(treeFileArtifact2)));
- treeArtifactData.put(output, treeArtifactValue);
+ TreeArtifactValue tree =
+ TreeArtifactValue.newBuilder(parent)
+ .putChild(
+ treeFileArtifact1, FileArtifactValue.createForTesting(treeFileArtifact1))
+ .putChild(
+ treeFileArtifact2, FileArtifactValue.createForTesting(treeFileArtifact2))
+ .build();
+ treeArtifactData.put(output, tree);
} else if (action.getActionType() == MiddlemanType.NORMAL) {
Path path = output.getPath();
FileArtifactValue noDigest =