Refactor all ctor callsites of PathFragment to instead call a static 'create' method.
This paves the way for changing PathFragment to e.g. an abstract class with multiple subclasses. This way we can split out the windows-specific stuff into one of these concrete classes, making the code more readable and also saving memory (since the shallow heap size of the NonWindowsPathFragment subclass will hopefully be smaller than that of the current PathFragment).
This also lets us pursue gc churn optimizations. We can now do interning in PathFragment#create and can also get rid of unnecessary intermediate PathFragment allocations.
RELNOTES: None
PiperOrigin-RevId: 152145768
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
index 99da8b9..c682340 100644
--- a/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/TreeArtifactBuildTest.java
@@ -709,9 +709,9 @@
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child1"));
+ artifact1, PathFragment.create("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child2"));
+ artifact1, PathFragment.create("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
@@ -723,9 +723,9 @@
// We mock out the action template function to expand into two actions that just touch the
// output files.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child1"));
+ artifact2, PathFragment.create("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child2"));
+ artifact2, PathFragment.create("child2"));
Action generateOutputAction = new DummyAction(
ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
Action noGenerateOutputAction = new DummyAction(
@@ -747,9 +747,9 @@
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child1"));
+ artifact1, PathFragment.create("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child2"));
+ artifact1, PathFragment.create("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
@@ -762,9 +762,9 @@
// One Action that touches the output file.
// The other action that does not generate the output file.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child1"));
+ artifact2, PathFragment.create("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child2"));
+ artifact2, PathFragment.create("child2"));
Action generateOutputAction = new DummyAction(
ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
Action noGenerateOutputAction = new NoOpDummyAction(
@@ -792,9 +792,9 @@
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child1"));
+ artifact1, PathFragment.create("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child2"));
+ artifact1, PathFragment.create("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
@@ -807,9 +807,9 @@
// One Action that touches the output file.
// The other action that just throws when executed.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child1"));
+ artifact2, PathFragment.create("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child2"));
+ artifact2, PathFragment.create("child2"));
Action generateOutputAction = new DummyAction(
ImmutableList.<Artifact>of(treeFileArtifactA), expectedOutputTreeFileArtifact1);
Action throwingAction = new ThrowingDummyAction(
@@ -837,9 +837,9 @@
// artifact1 is a tree artifact generated by a TouchingTestAction.
Artifact artifact1 = createTreeArtifact("treeArtifact1");
TreeFileArtifact treeFileArtifactA = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child1"));
+ artifact1, PathFragment.create("child1"));
TreeFileArtifact treeFileArtifactB = ActionInputHelper.treeFileArtifact(
- artifact1, new PathFragment("child2"));
+ artifact1, PathFragment.create("child2"));
registerAction(new TouchingTestAction(treeFileArtifactA, treeFileArtifactB));
// artifact2 is a tree artifact generated by an action template.
@@ -850,9 +850,9 @@
// We mock out the action template function to expand into two actions that throw when executed.
TreeFileArtifact expectedOutputTreeFileArtifact1 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child1"));
+ artifact2, PathFragment.create("child1"));
TreeFileArtifact expectedOutputTreeFileArtifact2 = ActionInputHelper.treeFileArtifact(
- artifact2, new PathFragment("child2"));
+ artifact2, PathFragment.create("child2"));
Action throwingAction = new ThrowingDummyAction(
ImmutableList.<Artifact>of(treeFileArtifactA),
ImmutableList.<Artifact>of(expectedOutputTreeFileArtifact1));
@@ -1044,7 +1044,7 @@
void registerOutput(ActionExecutionContext context, String outputName) throws IOException {
context.getMetadataHandler().addExpandedTreeOutput(
- treeFileArtifact(getSoleOutput(), new PathFragment(outputName)));
+ treeFileArtifact(getSoleOutput(), PathFragment.create(outputName)));
}
static List<TreeFileArtifact> asTreeFileArtifacts(final Artifact parent, String... files) {
@@ -1158,7 +1158,7 @@
private Artifact createTreeArtifact(String name) {
FileSystem fs = scratch.getFileSystem();
Path execRoot = fs.getPath(TestUtils.tmpDir());
- PathFragment execPath = new PathFragment("out").getRelative(name);
+ PathFragment execPath = PathFragment.create("out").getRelative(name);
Path path = execRoot.getRelative(execPath);
return new SpecialArtifact(
path, Root.asDerivedRoot(execRoot, execRoot.getRelative("out")), execPath, ALL_OWNER,