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/exec/SpawnInputExpanderTest.java b/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
index fdfa655..5b6db72 100644
--- a/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/exec/SpawnInputExpanderTest.java
@@ -74,14 +74,14 @@
Artifact artifact =
new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
+ .containsEntry(PathFragment.create("runfiles/workspace/dir/file"), artifact);
}
@Test
@@ -89,7 +89,7 @@
Artifact artifact =
new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
@@ -106,7 +106,7 @@
Artifact artifact =
new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(false);
@@ -114,7 +114,7 @@
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact);
+ .containsEntry(PathFragment.create("runfiles/workspace/dir/file"), artifact);
}
@Test
@@ -127,7 +127,7 @@
.addArtifact(artifact1)
.addArtifact(artifact2)
.build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact1)).thenReturn(true);
Mockito.when(mockCache.isFile(artifact2)).thenReturn(true);
@@ -135,9 +135,9 @@
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(2);
assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/file"), artifact1);
+ .containsEntry(PathFragment.create("runfiles/workspace/dir/file"), artifact1);
assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/dir/baz"), artifact2);
+ .containsEntry(PathFragment.create("runfiles/workspace/dir/baz"), artifact2);
}
@Test
@@ -145,15 +145,15 @@
Artifact artifact =
new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace")
- .addSymlink(new PathFragment("symlink"), artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ .addSymlink(PathFragment.create("symlink"), artifact).build();
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings)
- .containsEntry(new PathFragment("runfiles/workspace/symlink"), artifact);
+ .containsEntry(PathFragment.create("runfiles/workspace/symlink"), artifact);
}
@Test
@@ -161,19 +161,19 @@
Artifact artifact =
new Artifact(fs.getPath("/root/dir/file"), Root.asSourceRoot(fs.getPath("/root")));
Runfiles runfiles = new Runfiles.Builder("workspace")
- .addRootSymlink(new PathFragment("symlink"), artifact).build();
- RunfilesSupplier supplier = new RunfilesSupplierImpl(new PathFragment("runfiles"), runfiles);
+ .addRootSymlink(PathFragment.create("symlink"), artifact).build();
+ RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles);
ActionInputFileCache mockCache = Mockito.mock(ActionInputFileCache.class);
Mockito.when(mockCache.isFile(artifact)).thenReturn(true);
expander.addRunfilesToInputs(inputMappings, supplier, mockCache);
assertThat(inputMappings).hasSize(2);
- assertThat(inputMappings).containsEntry(new PathFragment("runfiles/symlink"), artifact);
+ assertThat(inputMappings).containsEntry(PathFragment.create("runfiles/symlink"), artifact);
// If there's no other entry, Runfiles adds an empty file in the workspace to make sure the
// directory gets created.
assertThat(inputMappings)
.containsEntry(
- new PathFragment("runfiles/workspace/.runfile"), SpawnInputExpander.EMPTY_FILE);
+ PathFragment.create("runfiles/workspace/.runfile"), SpawnInputExpander.EMPTY_FILE);
}
@Test
@@ -200,7 +200,7 @@
expander.parseFilesetManifest(inputMappings, artifact, "workspace");
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
+ .containsEntry(PathFragment.create("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
}
@Test
@@ -218,9 +218,9 @@
expander.parseFilesetManifest(inputMappings, artifact, "workspace");
assertThat(inputMappings).hasSize(2);
assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
+ .containsEntry(PathFragment.create("foo/bar"), ActionInputHelper.fromPath("/dir/file"));
assertThat(inputMappings)
- .containsEntry(new PathFragment("foo/baz"), ActionInputHelper.fromPath("/dir/file"));
+ .containsEntry(PathFragment.create("foo/baz"), ActionInputHelper.fromPath("/dir/file"));
}
@Test
@@ -237,6 +237,6 @@
assertThat(inputMappings).hasSize(1);
assertThat(inputMappings)
.containsEntry(
- new PathFragment("foo/bar"), ActionInputHelper.fromPath("/some"));
+ PathFragment.create("foo/bar"), ActionInputHelper.fromPath("/some"));
}
}