diff options
Diffstat (limited to 'src/test/java')
75 files changed, 568 insertions, 345 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD index f3e0f829a4..d650c9fe23 100644 --- a/src/test/java/com/google/devtools/build/lib/BUILD +++ b/src/test/java/com/google/devtools/build/lib/BUILD @@ -1369,6 +1369,7 @@ java_test( "//src/main/java/com/google/devtools/build/lib:events", "//src/main/java/com/google/devtools/build/lib:io", "//src/main/java/com/google/devtools/build/lib:packages-internal", + "//src/main/java/com/google/devtools/build/lib/vfs", "//src/main/java/com/google/devtools/build/skyframe", "//src/main/java/com/google/devtools/build/skyframe:skyframe-objects", "//third_party:auto_value", diff --git a/src/test/java/com/google/devtools/build/lib/actions/ActionCacheCheckerTest.java b/src/test/java/com/google/devtools/build/lib/actions/ActionCacheCheckerTest.java index 8892fcf38d..15f6bd78b1 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ActionCacheCheckerTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ActionCacheCheckerTest.java @@ -38,6 +38,7 @@ import com.google.devtools.build.lib.testutil.Scratch; 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.Root; import java.io.IOException; import java.util.HashMap; import java.util.HashSet; @@ -280,7 +281,7 @@ public class ActionCacheCheckerTest { public synchronized Iterable<Artifact> getInputs() { FileSystem fileSystem = getPrimaryOutput().getPath().getFileSystem(); Path path = fileSystem.getPath("/input"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(fileSystem.getPath("/")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(fileSystem.getPath("/"))); return ImmutableList.of(new Artifact(path, root)); } }; diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java index 94b1a0ffc4..ab2afc9e3c 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactFactoryTest.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -73,9 +74,9 @@ public class ArtifactFactoryTest { @Before public final void createFiles() throws Exception { execRoot = scratch.dir("/output/workspace"); - clientRoot = ArtifactRoot.asSourceRoot(scratch.dir("/client/workspace")); - clientRoRoot = ArtifactRoot.asSourceRoot(scratch.dir("/client/RO/workspace")); - alienRoot = ArtifactRoot.asSourceRoot(scratch.dir("/client/workspace")); + clientRoot = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/client/workspace"))); + clientRoRoot = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/client/RO/workspace"))); + alienRoot = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/client/workspace"))); outRoot = ArtifactRoot.asDerivedRoot(execRoot, execRoot.getRelative("out-root/x/bin")); fooPath = PathFragment.create("foo"); @@ -135,11 +136,11 @@ public class ArtifactFactoryTest { public void testResolveArtifact_noDerived_derivedRoot() throws Exception { assertThat( artifactFactory.resolveSourceArtifact( - outRoot.getPath().getRelative(fooRelative).relativeTo(execRoot), MAIN)) + outRoot.getRoot().getRelative(fooRelative).relativeTo(execRoot), MAIN)) .isNull(); assertThat( artifactFactory.resolveSourceArtifact( - outRoot.getPath().getRelative(barRelative).relativeTo(execRoot), MAIN)) + outRoot.getRoot().getRelative(barRelative).relativeTo(execRoot), MAIN)) .isNull(); } @@ -159,8 +160,7 @@ public class ArtifactFactoryTest { ImmutableMap.of(PackageIdentifier.createInMainRepo(PathFragment.create("")), clientRoot); artifactFactory.setPackageRoots(packageRoots::get); PathFragment outsideWorkspace = PathFragment.create("../foo"); - PathFragment insideWorkspace = - PathFragment.create("../" + clientRoot.getPath().getBaseName() + "/foo"); + PathFragment insideWorkspace = PathFragment.create("../workspace/foo"); assertThat(artifactFactory.resolveSourceArtifact(outsideWorkspace, MAIN)).isNull(); assertWithMessage( "Up-level-containing paths that descend into the right workspace aren't allowed") diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java index dfe4e0789a..5d369344ae 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactRootTest.java @@ -20,6 +20,7 @@ import com.google.common.testing.EqualsTester; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.io.IOException; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,10 +34,10 @@ public class ArtifactRootTest { @Test public void testAsSourceRoot() throws IOException { Path sourceDir = scratch.dir("/source"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(sourceDir); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(sourceDir)); assertThat(root.isSourceRoot()).isTrue(); assertThat(root.getExecPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); - assertThat(root.getPath()).isEqualTo(sourceDir); + assertThat(root.getRoot()).isEqualTo(Root.fromPath(sourceDir)); assertThat(root.toString()).isEqualTo("/source[source]"); } @@ -56,7 +57,7 @@ public class ArtifactRootTest { ArtifactRoot root = ArtifactRoot.asDerivedRoot(execRoot, rootDir); assertThat(root.isSourceRoot()).isFalse(); assertThat(root.getExecPath()).isEqualTo(PathFragment.create("root")); - assertThat(root.getPath()).isEqualTo(rootDir); + assertThat(root.getRoot()).isEqualTo(Root.fromPath(rootDir)); assertThat(root.toString()).isEqualTo("/exec/root[derived]"); } @@ -109,8 +110,8 @@ public class ArtifactRootTest { Path sourceDir = scratch.dir("/source"); ArtifactRoot rootA = ArtifactRoot.asDerivedRoot(execRoot, rootDir); assertEqualsAndHashCode(true, rootA, ArtifactRoot.asDerivedRoot(execRoot, rootDir)); - assertEqualsAndHashCode(false, rootA, ArtifactRoot.asSourceRoot(sourceDir)); - assertEqualsAndHashCode(false, rootA, ArtifactRoot.asSourceRoot(rootDir)); + assertEqualsAndHashCode(false, rootA, ArtifactRoot.asSourceRoot(Root.fromPath(sourceDir))); + assertEqualsAndHashCode(false, rootA, ArtifactRoot.asSourceRoot(Root.fromPath(rootDir))); assertEqualsAndHashCode(false, rootA, ArtifactRoot.asDerivedRoot(otherRootDir, rootDir)); } diff --git a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java index 681b2a30a8..cd47c41b81 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ArtifactTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.rules.java.JavaSemantics; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -97,7 +98,8 @@ public class ArtifactTest { @Test public void testRootPrefixedExecPath_noRoot() throws IOException { Path f1 = scratch.file("/exec/dir/file.ext"); - Artifact a1 = new Artifact(f1.relativeTo(execDir), ArtifactRoot.asSourceRoot(execDir)); + Artifact a1 = + new Artifact(f1.relativeTo(execDir), ArtifactRoot.asSourceRoot(Root.fromPath(execDir))); assertThat(Artifact.asRootPrefixedExecPath(a1)).isEqualTo(":dir/file.ext"); } @@ -128,7 +130,7 @@ public class ArtifactTest { @Test public void testGetFilename() throws Exception { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.dir("/foo")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/foo"))); Artifact javaFile = new Artifact(scratch.file("/foo/Bar.java"), root); Artifact generatedHeader = new Artifact(scratch.file("/foo/bar.proto.h"), root); Artifact generatedCc = new Artifact(scratch.file("/foo/bar.proto.cc"), root); @@ -141,7 +143,7 @@ public class ArtifactTest { @Test public void testGetExtension() throws Exception { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.dir("/foo")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/foo"))); Artifact javaFile = new Artifact(scratch.file("/foo/Bar.java"), root); assertThat(javaFile.getExtension()).isEqualTo("java"); } @@ -154,7 +156,7 @@ public class ArtifactTest { private List<Artifact> getFooBarArtifacts(MutableActionGraph actionGraph, boolean collapsedList) throws Exception { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.dir("/foo")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/foo"))); Artifact aHeader1 = new Artifact(scratch.file("/foo/bar1.h"), root); Artifact aHeader2 = new Artifact(scratch.file("/foo/bar2.h"), root); Artifact aHeader3 = new Artifact(scratch.file("/foo/bar3.h"), root); @@ -272,7 +274,7 @@ public class ArtifactTest { @Test public void testRootRelativePathIsSameAsExecPath() throws Exception { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.dir("/foo")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/foo"))); Artifact a = new Artifact(scratch.file("/foo/bar1.h"), root); assertThat(a.getRootRelativePath()).isSameAs(a.getExecPath()); } @@ -346,7 +348,9 @@ public class ArtifactTest { @Test public void testDirnameInExecutionDir() throws Exception { Artifact artifact = - new Artifact(scratch.file("/foo/bar.txt"), ArtifactRoot.asSourceRoot(scratch.dir("/foo"))); + new Artifact( + scratch.file("/foo/bar.txt"), + ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/foo")))); assertThat(artifact.getDirname()).isEqualTo("."); } @@ -365,7 +369,7 @@ public class ArtifactTest { assertThat( new Artifact( scratch.file("/src/foo.cc"), - ArtifactRoot.asSourceRoot(scratch.dir("/")), + ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/"))), PathFragment.create("src/foo.cc")) .isSourceArtifact()) .isTrue(); @@ -387,6 +391,7 @@ public class ArtifactTest { private Artifact createDirNameArtifact() throws Exception { return new Artifact( - scratch.file("/aaa/bbb/ccc/ddd"), ArtifactRoot.asSourceRoot(scratch.dir("/"))); + scratch.file("/aaa/bbb/ccc/ddd"), + ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/")))); } } diff --git a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java index 5227dba353..911f690588 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/CustomCommandLineTest.java @@ -31,6 +31,7 @@ import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.util.LazyString; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.util.Arrays; import org.junit.Before; import org.junit.Test; @@ -51,7 +52,7 @@ public class CustomCommandLineTest { @Before public void createArtifacts() throws Exception { scratch = new Scratch(); - rootDir = ArtifactRoot.asSourceRoot(scratch.dir("/exec/root")); + rootDir = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/exec/root"))); artifact1 = new Artifact(scratch.file("/exec/root/dir/file1.txt"), rootDir); artifact2 = new Artifact(scratch.file("/exec/root/dir/file2.txt"), rootDir); } @@ -920,7 +921,7 @@ public class CustomCommandLineTest { private Artifact createTreeArtifact(String rootRelativePath) { PathFragment relpath = PathFragment.create(rootRelativePath); return new SpecialArtifact( - rootDir.getPath().getRelative(relpath), + rootDir.getRoot().getRelative(relpath), rootDir, rootDir.getExecPath().getRelative(relpath), ArtifactOwner.NULL_OWNER, diff --git a/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java index 28da727027..b1e63b6039 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/actions/ExecutableSymlinkActionTest.java @@ -66,8 +66,8 @@ public class ExecutableSymlinkActionTest { @Test public void testSimple() throws Exception { - Path inputFile = inputRoot.getPath().getChild("some-file"); - Path outputFile = outputRoot.getPath().getChild("some-output"); + Path inputFile = inputRoot.getRoot().getRelative("some-file"); + Path outputFile = outputRoot.getRoot().getRelative("some-output"); FileSystemUtils.createEmptyFile(inputFile); inputFile.setExecutable(/*executable=*/true); Artifact input = new Artifact(inputFile, inputRoot); @@ -80,10 +80,10 @@ public class ExecutableSymlinkActionTest { @Test public void testFailIfInputIsNotAFile() throws Exception { - Path dir = inputRoot.getPath().getChild("some-dir"); + Path dir = inputRoot.getRoot().getRelative("some-dir"); FileSystemUtils.createDirectoryAndParents(dir); Artifact input = new Artifact(dir, inputRoot); - Artifact output = new Artifact(outputRoot.getPath().getChild("some-output"), outputRoot); + Artifact output = new Artifact(outputRoot.getRoot().getRelative("some-output"), outputRoot); ExecutableSymlinkAction action = new ExecutableSymlinkAction(NULL_ACTION_OWNER, input, output); try { action.execute(createContext()); @@ -95,11 +95,11 @@ public class ExecutableSymlinkActionTest { @Test public void testFailIfInputIsNotExecutable() throws Exception { - Path file = inputRoot.getPath().getChild("some-file"); + Path file = inputRoot.getRoot().getRelative("some-file"); FileSystemUtils.createEmptyFile(file); file.setExecutable(/*executable=*/false); Artifact input = new Artifact(file, inputRoot); - Artifact output = new Artifact(outputRoot.getPath().getChild("some-output"), outputRoot); + Artifact output = new Artifact(outputRoot.getRoot().getRelative("some-output"), outputRoot); ExecutableSymlinkAction action = new ExecutableSymlinkAction(NULL_ACTION_OWNER, input, output); try { action.execute(createContext()); diff --git a/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java b/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java index c3f8e0f135..dd756cafc3 100644 --- a/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java +++ b/src/test/java/com/google/devtools/build/lib/actions/util/ActionsTestUtil.java @@ -68,6 +68,7 @@ import com.google.devtools.build.lib.util.io.FileOutErr; import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.AbstractSkyFunctionEnvironment; import com.google.devtools.build.skyframe.BuildDriver; @@ -246,7 +247,7 @@ public final class ActionsTestUtil { public static final Artifact DUMMY_ARTIFACT = new Artifact( PathFragment.create("dummy"), - ArtifactRoot.asSourceRoot(new InMemoryFileSystem().getRootDirectory())); + ArtifactRoot.asSourceRoot(Root.fromFileSystemRoot(new InMemoryFileSystem()))); public static final ActionOwner NULL_ACTION_OWNER = ActionOwner.create( diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java index d39547a1f8..2e0eae4d23 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java @@ -47,6 +47,7 @@ import com.google.devtools.build.lib.packages.NativeAspectClass; import com.google.devtools.build.lib.skyframe.AspectValue; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.vfs.ModifiedFileSet; +import com.google.devtools.build.lib.vfs.Root; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; @@ -216,8 +217,8 @@ public class AspectTest extends AnalysisTestCase { .add("bind(name='b', actual='//a:b')") .build()); - skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + skyframeExecutor.invalidateFilesUnderPathForTesting( + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); ConfiguredTarget a = getConfiguredTarget("//a:a"); assertThat(a.getProvider(RuleInfo.class).getData()) diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java index f1de38e6c4..491d54e1d7 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/LocationFunctionTest.java @@ -23,6 +23,7 @@ import com.google.devtools.build.lib.actions.ArtifactRoot; import com.google.devtools.build.lib.analysis.LocationExpander.LocationFunction; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.vfs.FileSystem; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.util.Arrays; import java.util.Collection; @@ -50,7 +51,8 @@ public class LocationFunctionTest { fs.getPath(path), ArtifactRoot.asDerivedRoot(fs.getPath("/exec"), fs.getPath("/exec/out"))); } else { - return new Artifact(fs.getPath(path), ArtifactRoot.asSourceRoot(fs.getPath("/exec"))); + return new Artifact( + fs.getPath(path), ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/exec")))); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java index ec184e83e2..e31d516f2d 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java @@ -26,6 +26,7 @@ import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.events.EventKind; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -51,7 +52,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadObscurer() throws Exception { Map<PathFragment, Artifact> obscuringMap = new HashMap<>(); PathFragment pathA = PathFragment.create("a"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a"), root); obscuringMap.put(pathA, artifactA); obscuringMap.put(PathFragment.create("a/b"), new Artifact(PathFragment.create("c/b"), @@ -65,7 +66,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadGrandParentObscurer() throws Exception { Map<PathFragment, Artifact> obscuringMap = new HashMap<>(); PathFragment pathA = PathFragment.create("a"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a"), root); obscuringMap.put(pathA, artifactA); @@ -80,7 +81,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksCatchesBadObscurerNoListener() throws Exception { Map<PathFragment, Artifact> obscuringMap = new HashMap<>(); PathFragment pathA = PathFragment.create("a"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a"), root); obscuringMap.put(pathA, artifactA); @@ -94,7 +95,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksIgnoresOkObscurer() throws Exception { Map<PathFragment, Artifact> obscuringMap = new HashMap<>(); PathFragment pathA = PathFragment.create("a"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a"), root); obscuringMap.put(pathA, artifactA); @@ -110,7 +111,7 @@ public class RunfilesTest extends FoundationTestCase { public void testFilterListForObscuringSymlinksNoObscurers() throws Exception { Map<PathFragment, Artifact> obscuringMap = new HashMap<>(); PathFragment pathA = PathFragment.create("a"); - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a"), root); obscuringMap.put(pathA, artifactA); @@ -142,7 +143,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutCatchesConflict() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Artifact artifactC = new Artifact(PathFragment.create("c"), root); @@ -159,7 +160,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutReportsError() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Artifact artifactC = new Artifact(PathFragment.create("c"), root); @@ -177,7 +178,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutCatchesConflictBetweenNullAndNotNull() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Map<PathFragment, Artifact> map = new LinkedHashMap<>(); @@ -192,7 +193,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutCatchesConflictBetweenNotNullAndNull() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Map<PathFragment, Artifact> map = new LinkedHashMap<>(); @@ -208,7 +209,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutIgnoresConflict() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Artifact artifactC = new Artifact(PathFragment.create("c"), root); @@ -224,7 +225,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutIgnoresConflictNoListener() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Artifact artifactC = new Artifact(PathFragment.create("c"), root); @@ -240,7 +241,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutIgnoresSameArtifact() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); Artifact artifactB = new Artifact(PathFragment.create("b"), root); Artifact artifactB2 = new Artifact(PathFragment.create("b"), root); @@ -271,7 +272,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testPutNoConflicts() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathA = PathFragment.create("a"); PathFragment pathB = PathFragment.create("b"); PathFragment pathC = PathFragment.create("c"); @@ -325,7 +326,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testLegacyRunfilesStructure() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment workspaceName = PathFragment.create("wsname"); PathFragment pathB = PathFragment.create("external/repo/b"); Artifact artifactB = new Artifact(pathB, root); @@ -346,7 +347,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testRunfileAdded() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment workspaceName = PathFragment.create("wsname"); PathFragment pathB = PathFragment.create("external/repo/b"); Artifact artifactB = new Artifact(pathB, root); @@ -369,7 +370,7 @@ public class RunfilesTest extends FoundationTestCase { // TODO(kchodorow): remove this once the default workspace name is always set. @Test public void testConflictWithExternal() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); PathFragment pathB = PathFragment.create("repo/b"); PathFragment externalPathB = Label.EXTERNAL_PACKAGE_NAME.getRelative(pathB); Artifact artifactB = new Artifact(pathB, root); @@ -393,7 +394,7 @@ public class RunfilesTest extends FoundationTestCase { @Test public void testMergeWithSymlinks() { - ArtifactRoot root = ArtifactRoot.asSourceRoot(scratch.resolve("/workspace")); + ArtifactRoot root = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.resolve("/workspace"))); Artifact artifactA = new Artifact(PathFragment.create("a/target"), root); Artifact artifactB = new Artifact(PathFragment.create("b/target"), root); PathFragment sympathA = PathFragment.create("a/symlink"); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java index ed382c4c6c..eca896acd1 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/ParamFileWriteActionTest.java @@ -111,7 +111,7 @@ public class ParamFileWriteActionTest extends BuildViewTestCase { private Artifact createTreeArtifact(String rootRelativePath) { PathFragment relpath = PathFragment.create(rootRelativePath); return new SpecialArtifact( - rootDir.getPath().getRelative(relpath), + rootDir.getRoot().getRelative(relpath), rootDir, rootDir.getExecPath().getRelative(relpath), ArtifactOwner.NULL_OWNER, diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java index 5a54a9e02c..94ac8a8cf3 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/PopulateTreeArtifactActionTest.java @@ -346,7 +346,7 @@ public class PopulateTreeArtifactActionTest extends BuildViewTestCase { private Artifact createTreeArtifact(String rootRelativePath) { PathFragment relpath = PathFragment.create(rootRelativePath); return new SpecialArtifact( - root.getPath().getRelative(relpath), + root.getRoot().getRelative(relpath), root, root.getExecPath().getRelative(relpath), ArtifactOwner.NULL_OWNER, diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplateTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplateTest.java index a13091db41..5bfb86f2e2 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplateTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTemplateTest.java @@ -321,7 +321,7 @@ public class SpawnActionTemplateTest { private Artifact createTreeArtifact(String rootRelativePath) { PathFragment relpath = PathFragment.create(rootRelativePath); return new SpecialArtifact( - root.getPath().getRelative(relpath), + root.getRoot().getRelative(relpath), root, root.getExecPath().getRelative(relpath), ArtifactOwner.NULL_OWNER, diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java index 3f6e62dca7..e8d2af4501 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.util.io.FileOutErr; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import java.nio.charset.StandardCharsets; import java.util.List; import org.junit.Before; @@ -77,7 +78,7 @@ public class TemplateExpansionActionTest extends FoundationTestCase { } private void createArtifacts(String template) throws Exception { - ArtifactRoot workspace = ArtifactRoot.asSourceRoot(scratch.dir("/workspace")); + ArtifactRoot workspace = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/workspace"))); outputRoot = ArtifactRoot.asDerivedRoot(scratch.dir("/workspace"), scratch.dir("/workspace/out")); Path input = scratch.overwriteFile("/workspace/input.txt", StandardCharsets.UTF_8, template); diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java index edd31896e4..8501af640c 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/config/BuildConfigurationTest.java @@ -53,13 +53,13 @@ public class BuildConfigurationTest extends ConfigurationTestCase { String outputDirPrefix = outputBase + "/execroot/" + config.getMainRepositoryName() + "/blaze-out/.*piii-fastbuild"; - assertThat(config.getOutputDirectory(RepositoryName.MAIN).getPath().toString()) + assertThat(config.getOutputDirectory(RepositoryName.MAIN).getRoot().toString()) .matches(outputDirPrefix); - assertThat(config.getBinDirectory(RepositoryName.MAIN).getPath().toString()) + assertThat(config.getBinDirectory(RepositoryName.MAIN).getRoot().toString()) .matches(outputDirPrefix + "/bin"); - assertThat(config.getIncludeDirectory(RepositoryName.MAIN).getPath().toString()) + assertThat(config.getIncludeDirectory(RepositoryName.MAIN).getRoot().toString()) .matches(outputDirPrefix + "/include"); - assertThat(config.getTestLogsDirectory(RepositoryName.MAIN).getPath().toString()) + assertThat(config.getTestLogsDirectory(RepositoryName.MAIN).getRoot().toString()) .matches(outputDirPrefix + "/testlogs"); } @@ -70,7 +70,7 @@ public class BuildConfigurationTest extends ConfigurationTestCase { } BuildConfiguration config = create("--platform_suffix=-test"); - assertThat(config.getOutputDirectory(RepositoryName.MAIN).getPath().toString()) + assertThat(config.getOutputDirectory(RepositoryName.MAIN).getRoot().toString()) .matches( outputBase + "/execroot/" diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java index fdddbee9e2..519807fa77 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestCase.java @@ -70,6 +70,7 @@ import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.common.options.InvocationPolicyEnforcer; import com.google.devtools.common.options.Options; @@ -148,7 +149,7 @@ public abstract class AnalysisTestCase extends FoundationTestCase { pkgLocator = new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); directories = new BlazeDirectories( @@ -335,8 +336,8 @@ public abstract class AnalysisTestCase extends FoundationTestCase { ImmutableMap.<String, String>of(), ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance())); - skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + skyframeExecutor.invalidateFilesUnderPathForTesting( + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); LoadingResult loadingResult = loadingPhaseRunner.execute( diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestUtil.java b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestUtil.java index 1a5c6ea467..eb91237e0f 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestUtil.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/AnalysisTestUtil.java @@ -426,26 +426,23 @@ public final class AnalysisTestUtil { BuildConfiguration targetConfiguration = Iterables.getOnlyElement(configurations.getTargetConfigurations()); rootMap.put( - targetConfiguration.getBinDirectory(RepositoryName.MAIN).getPath().toString(), - "bin"); + targetConfiguration.getBinDirectory(RepositoryName.MAIN).getRoot().toString(), "bin"); // In preparation for merging genfiles/ and bin/, we don't differentiate them in tests anymore rootMap.put( - targetConfiguration.getGenfilesDirectory(RepositoryName.MAIN).getPath().toString(), - "bin"); + targetConfiguration.getGenfilesDirectory(RepositoryName.MAIN).getRoot().toString(), "bin"); rootMap.put( - targetConfiguration.getMiddlemanDirectory(RepositoryName.MAIN).getPath().toString(), + targetConfiguration.getMiddlemanDirectory(RepositoryName.MAIN).getRoot().toString(), "internal"); BuildConfiguration hostConfiguration = configurations.getHostConfiguration(); rootMap.put( - hostConfiguration.getBinDirectory(RepositoryName.MAIN).getPath().toString(), - "bin(host)"); + hostConfiguration.getBinDirectory(RepositoryName.MAIN).getRoot().toString(), "bin(host)"); // In preparation for merging genfiles/ and bin/, we don't differentiate them in tests anymore rootMap.put( - hostConfiguration.getGenfilesDirectory(RepositoryName.MAIN).getPath().toString(), + hostConfiguration.getGenfilesDirectory(RepositoryName.MAIN).getRoot().toString(), "bin(host)"); rootMap.put( - hostConfiguration.getMiddlemanDirectory(RepositoryName.MAIN).getPath().toString(), + hostConfiguration.getMiddlemanDirectory(RepositoryName.MAIN).getRoot().toString(), "internal(host)"); // The output paths that bin, genfiles, etc. refer to may or may not include the C++-contributed @@ -466,10 +463,7 @@ public final class AnalysisTestUtil { if (root.isSourceRoot()) { files.add("src " + artifact.getRootRelativePath()); } else { - String name = rootMap.get(root.getPath().toString()); - if (name == null) { - name = "/"; - } + String name = rootMap.getOrDefault(root.getRoot().toString(), "/"); files.add(name + " " + artifact.getRootRelativePath()); } } diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java index e3587cc962..d25fb6a301 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/BuildViewTestCase.java @@ -142,6 +142,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.MemoizingEvaluator; import com.google.devtools.build.skyframe.SkyFunction; @@ -257,7 +258,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { skyframeExecutor.preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, skylarkSemanticsOptions, @@ -428,8 +429,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase { * @throws InterruptedException */ protected void invalidatePackages(boolean alsoConfigs) throws InterruptedException { - skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + skyframeExecutor.invalidateFilesUnderPathForTesting( + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); if (alsoConfigs) { try { // Also invalidate all configurations. This is important: by invalidating all files we @@ -494,7 +495,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { view = new BuildView(directories, ruleClassProvider, skyframeExecutor, null); view.setConfigurationsForTesting(masterConfig); - view.setArtifactRoots(new PackageRootsNoSymlinkCreation(rootDirectory)); + view.setArtifactRoots(new PackageRootsNoSymlinkCreation(Root.fromPath(rootDirectory))); } protected CachingAnalysisEnvironment getTestAnalysisEnvironment() { @@ -823,7 +824,7 @@ public abstract class BuildViewTestCase extends FoundationTestCase { skyframeExecutor.invalidateFilesUnderPathForTesting( reporter, new ModifiedFileSet.Builder().modify(PathFragment.create(buildFilePathString)).build(), - rootDirectory); + Root.fromPath(rootDirectory)); return (Rule) getTarget("//" + packageName + ":" + ruleName); } @@ -976,7 +977,8 @@ public abstract class BuildViewTestCase extends FoundationTestCase { } protected Artifact getSourceArtifact(String name) { - return getSourceArtifact(PathFragment.create(name), ArtifactRoot.asSourceRoot(rootDirectory)); + return getSourceArtifact( + PathFragment.create(name), ArtifactRoot.asSourceRoot(Root.fromPath(rootDirectory))); } /** diff --git a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java index 7953c33e71..b7dd9ba6e4 100644 --- a/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/analysis/util/ConfigurationTestCase.java @@ -48,6 +48,7 @@ import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.common.options.Converters; import com.google.devtools.common.options.InvocationPolicyEnforcer; import com.google.devtools.common.options.Option; @@ -100,7 +101,7 @@ public abstract class ConfigurationTestCase extends FoundationTestCase { PathPackageLocator pkgLocator = new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); final PackageFactory pkgFactory; BlazeDirectories directories = diff --git a/src/test/java/com/google/devtools/build/lib/buildtool/SymlinkForestTest.java b/src/test/java/com/google/devtools/build/lib/buildtool/SymlinkForestTest.java index 853873386b..ab550a072d 100644 --- a/src/test/java/com/google/devtools/build/lib/buildtool/SymlinkForestTest.java +++ b/src/test/java/com/google/devtools/build/lib/buildtool/SymlinkForestTest.java @@ -29,6 +29,7 @@ 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; import com.google.devtools.build.lib.vfs.Symlinks; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.io.IOException; @@ -131,7 +132,7 @@ public class SymlinkForestTest { assertThat(aDir.exists()).isFalse(); } - private PackageIdentifier createPkg(Path rootA, Path rootB, String pkg) throws IOException { + private PackageIdentifier createPkg(Root rootA, Root rootB, String pkg) throws IOException { if (rootA != null) { createDirectoryAndParents(rootA.getRelative(pkg)); FileSystemUtils.createEmptyFile(rootA.getRelative(pkg).getChild("file")); @@ -143,7 +144,7 @@ public class SymlinkForestTest { return PackageIdentifier.createInMainRepo(pkg); } - private PackageIdentifier createPkg(Path root, String repo, String pkg) + private PackageIdentifier createPkg(Root root, String repo, String pkg) throws IOException, LabelSyntaxException { if (root != null) { Path repoRoot = root.getRelative(Label.EXTERNAL_PACKAGE_NAME).getRelative(repo); @@ -153,7 +154,7 @@ public class SymlinkForestTest { return PackageIdentifier.create(RepositoryName.create("@" + repo), PathFragment.create(pkg)); } - private void assertLinksTo(Path fromRoot, Path toRoot, String relpart) throws IOException { + private void assertLinksTo(Path fromRoot, Root toRoot, String relpart) throws IOException { assertLinksTo(fromRoot.getRelative(relpart), toRoot.getRelative(relpart)); } @@ -168,11 +169,11 @@ public class SymlinkForestTest { @Test public void testPlantLinkForest() throws IOException { - Path rootA = fileSystem.getPath("/A"); - Path rootB = fileSystem.getPath("/B"); + Root rootA = Root.fromPath(fileSystem.getPath("/A")); + Root rootB = Root.fromPath(fileSystem.getPath("/B")); - ImmutableMap<PackageIdentifier, Path> packageRootMap = - ImmutableMap.<PackageIdentifier, Path>builder() + ImmutableMap<PackageIdentifier, Root> packageRootMap = + ImmutableMap.<PackageIdentifier, Root>builder() .put(createPkg(rootA, rootB, "pkgA"), rootA) .put(createPkg(rootA, rootB, "dir1/pkgA"), rootA) .put(createPkg(rootA, rootB, "dir1/pkgB"), rootB) @@ -207,10 +208,10 @@ public class SymlinkForestTest { @Test public void testTopLevelPackage() throws Exception { - Path rootX = fileSystem.getPath("/X"); - Path rootY = fileSystem.getPath("/Y"); - ImmutableMap<PackageIdentifier, Path> packageRootMap = - ImmutableMap.<PackageIdentifier, Path>builder() + Root rootX = Root.fromPath(fileSystem.getPath("/X")); + Root rootY = Root.fromPath(fileSystem.getPath("/Y")); + ImmutableMap<PackageIdentifier, Root> packageRootMap = + ImmutableMap.<PackageIdentifier, Root>builder() .put(createPkg(rootX, rootY, ""), rootX) .put(createPkg(rootX, rootY, "foo"), rootX) .build(); @@ -222,15 +223,15 @@ public class SymlinkForestTest { @Test public void testRemotePackage() throws Exception { - Path outputBase = fileSystem.getPath("/ob"); - Path rootY = outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("y"); - Path rootZ = outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("z"); - Path rootW = outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("w"); - createDirectoryAndParents(rootY); + Root outputBase = Root.fromPath(fileSystem.getPath("/ob")); + Root rootY = Root.fromPath(outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("y")); + Root rootZ = Root.fromPath(outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("z")); + Root rootW = Root.fromPath(outputBase.getRelative(Label.EXTERNAL_PATH_PREFIX).getRelative("w")); + createDirectoryAndParents(rootY.asPath()); FileSystemUtils.createEmptyFile(rootY.getRelative("file")); - ImmutableMap<PackageIdentifier, Path> packageRootMap = - ImmutableMap.<PackageIdentifier, Path>builder() + ImmutableMap<PackageIdentifier, Root> packageRootMap = + ImmutableMap.<PackageIdentifier, Root>builder() // Remote repo without top-level package. .put(createPkg(outputBase, "y", "w"), outputBase) // Remote repo with and without top-level package. @@ -256,9 +257,9 @@ public class SymlinkForestTest { @Test public void testExternalPackage() throws Exception { - Path root = fileSystem.getPath("/src"); - ImmutableMap<PackageIdentifier, Path> packageRootMap = - ImmutableMap.<PackageIdentifier, Path>builder() + Root root = Root.fromPath(fileSystem.getPath("/src")); + ImmutableMap<PackageIdentifier, Root> packageRootMap = + ImmutableMap.<PackageIdentifier, Root>builder() // Virtual root, shouldn't actually be linked in. .put(Label.EXTERNAL_PACKAGE_IDENTIFIER, root) .build(); @@ -270,9 +271,9 @@ public class SymlinkForestTest { @Test public void testWorkspaceName() throws Exception { - Path root = fileSystem.getPath("/src"); - ImmutableMap<PackageIdentifier, Path> packageRootMap = - ImmutableMap.<PackageIdentifier, Path>builder() + Root root = Root.fromPath(fileSystem.getPath("/src")); + ImmutableMap<PackageIdentifier, Root> packageRootMap = + ImmutableMap.<PackageIdentifier, Root>builder() // Remote repo without top-level package. .put(createPkg(root, "y", "w"), root) .build(); @@ -284,7 +285,7 @@ public class SymlinkForestTest { @Test public void testExecrootVersionChanges() throws Exception { - ImmutableMap<PackageIdentifier, Path> packageRootMap = ImmutableMap.of(); + ImmutableMap<PackageIdentifier, Root> packageRootMap = ImmutableMap.of(); linkRoot.getRelative("wsname").createDirectory(); new SymlinkForest(packageRootMap, linkRoot, TestConstants.PRODUCT_NAME, "wsname") .plantSymlinkForest(); diff --git a/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java b/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java index a71ba03182..73a4a3b226 100644 --- a/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java +++ b/src/test/java/com/google/devtools/build/lib/exec/FilesetManifestTest.java @@ -25,6 +25,7 @@ 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; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -58,7 +59,8 @@ public class FilesetManifestTest { // See AnalysisUtils for the mapping from "foo" to "_foo/MANIFEST". scratchFile("/root/_foo/MANIFEST"); - Artifact artifact = new Artifact(fs.getPath("/root/foo"), ArtifactRoot.asSourceRoot(execRoot)); + Artifact artifact = + new Artifact(fs.getPath("/root/foo"), ArtifactRoot.asSourceRoot(Root.fromPath(execRoot))); FilesetManifest manifest = FilesetManifest.parseManifestFile(artifact, execRoot, "workspace", IGNORE); assertThat(manifest.getEntries()).isEmpty(); 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 9e14facdb3..f875251370 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 @@ -31,6 +31,7 @@ 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; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -76,7 +77,9 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesSingleFile() throws Exception { Artifact artifact = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build(); RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles); FakeActionInputFileCache mockCache = new FakeActionInputFileCache(); @@ -91,7 +94,9 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesDirectoryStrict() throws Exception { Artifact artifact = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build(); RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles); FakeActionInputFileCache mockCache = new FakeActionInputFileCache(); @@ -108,7 +113,9 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesDirectoryNonStrict() throws Exception { Artifact artifact = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace").addArtifact(artifact).build(); RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles); FakeActionInputFileCache mockCache = new FakeActionInputFileCache(); @@ -124,9 +131,13 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesTwoFiles() throws Exception { Artifact artifact1 = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Artifact artifact2 = - new Artifact(fs.getPath("/root/dir/baz"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/baz"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace") .addArtifact(artifact1) .addArtifact(artifact2) @@ -147,7 +158,9 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesSymlink() throws Exception { Artifact artifact = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace") .addSymlink(PathFragment.create("symlink"), artifact).build(); RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles); @@ -163,7 +176,9 @@ public class SpawnInputExpanderTest { @Test public void testRunfilesRootSymlink() throws Exception { Artifact artifact = - new Artifact(fs.getPath("/root/dir/file"), ArtifactRoot.asSourceRoot(fs.getPath("/root"))); + new Artifact( + fs.getPath("/root/dir/file"), + ArtifactRoot.asSourceRoot(Root.fromPath(fs.getPath("/root")))); Runfiles runfiles = new Runfiles.Builder("workspace") .addRootSymlink(PathFragment.create("symlink"), artifact).build(); RunfilesSupplier supplier = new RunfilesSupplierImpl(PathFragment.create("runfiles"), runfiles); diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java index af481f8db7..eb35dd61bc 100644 --- a/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/packages/util/PackageLoadingTestCase.java @@ -46,6 +46,7 @@ import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.ModifiedFileSet; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; import com.google.devtools.common.options.Options; @@ -141,7 +142,7 @@ public abstract class PackageLoadingTestCase extends FoundationTestCase { skyframeExecutor.preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), @@ -307,6 +308,6 @@ public abstract class PackageLoadingTestCase extends FoundationTestCase { */ protected void invalidatePackages() throws InterruptedException { skyframeExecutor.invalidateFilesUnderPathForTesting( - reporter, ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); } } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java index 7ebb3c2cb1..aaf0c5f9b3 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/BuildFileModificationTest.java @@ -40,6 +40,7 @@ import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.common.options.OptionsParser; import java.nio.charset.StandardCharsets; @@ -137,7 +138,7 @@ public class BuildFileModificationTest extends FoundationTestCase { private void invalidatePackages() throws InterruptedException { skyframeExecutor.invalidateFilesUnderPathForTesting( - reporter, ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); } private Package getPackage(String packageName) diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java index 184f22201b..40324ad625 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IOExceptionsTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; @@ -75,7 +76,7 @@ public class IOExceptionsTest extends PackageLoadingTestCase { protected void syncPackages() throws Exception { skyframeExecutor.invalidateFilesUnderPathForTesting( - reporter, ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); } @Override diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java index 6e83bbedca..d4373b4f5e 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/IncrementalLoadingTest.java @@ -51,6 +51,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -439,8 +440,8 @@ public class IncrementalLoadingTest { private class ManualDiffAwarenessFactory implements DiffAwareness.Factory { @Nullable @Override - public DiffAwareness maybeCreate(Path pathEntry) { - return pathEntry == workspace ? new ManualDiffAwareness() : null; + public DiffAwareness maybeCreate(Root pathEntry) { + return pathEntry.asPath().equals(workspace) ? new ManualDiffAwareness() : null; } } @@ -494,7 +495,7 @@ public class IncrementalLoadingTest { skyframeExecutor.preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(workspace), + ImmutableList.of(Root.fromPath(workspace)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), @@ -585,7 +586,7 @@ public class IncrementalLoadingTest { skyframeExecutor.preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(workspace), + ImmutableList.of(Root.fromPath(workspace)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), @@ -595,7 +596,7 @@ public class IncrementalLoadingTest { ImmutableMap.<String, String>of(), new TimestampGranularityMonitor(BlazeClock.instance())); skyframeExecutor.invalidateFilesUnderPathForTesting( - new Reporter(new EventBus()), modifiedFileSet, workspace); + new Reporter(new EventBus()), modifiedFileSet, Root.fromPath(workspace)); ((SequencedSkyframeExecutor) skyframeExecutor).handleDiffs(new Reporter(new EventBus())); changes.clear(); diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java index 3a4943a8c9..c2180ef14f 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunnerTest.java @@ -55,6 +55,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.common.options.Options; import com.google.devtools.common.options.OptionsParser; @@ -749,7 +750,8 @@ public class LoadingPhaseRunnerTest { builder.modify(workspacePath); } ModifiedFileSet modified = builder.build(); - skyframeExecutor.invalidateFilesUnderPathForTesting(storedErrors, modified, workspace); + skyframeExecutor.invalidateFilesUnderPathForTesting( + storedErrors, modified, Root.fromPath(workspace)); changes.clear(); } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java index 8fd9d55c8e..9134e4df79 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PackageCacheTest.java @@ -48,6 +48,7 @@ import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.common.options.InvocationPolicyEnforcer; import com.google.devtools.common.options.OptionsParser; import com.google.devtools.common.options.OptionsParsingException; @@ -170,7 +171,7 @@ public class PackageCacheTest extends FoundationTestCase { private void invalidatePackages() throws InterruptedException { skyframeExecutor.invalidateFilesUnderPathForTesting( - reporter, ModifiedFileSet.EVERYTHING_MODIFIED, rootDirectory); + reporter, ModifiedFileSet.EVERYTHING_MODIFIED, Root.fromPath(rootDirectory)); } private Package getPackage(String packageName) @@ -336,7 +337,7 @@ public class PackageCacheTest extends FoundationTestCase { Package oldPkg = getPackage("pkg"); assertThat(getPackage("pkg")).isSameAs(oldPkg); // change not yet visible assertThat(oldPkg.getFilename()).isEqualTo(buildFile1); - assertThat(oldPkg.getSourceRoot()).isEqualTo(rootDirectory); + assertThat(oldPkg.getSourceRoot()).isEqualTo(Root.fromPath(rootDirectory)); buildFile1.delete(); invalidatePackages(); @@ -344,7 +345,7 @@ public class PackageCacheTest extends FoundationTestCase { Package newPkg = getPackage("pkg"); assertThat(newPkg).isNotSameAs(oldPkg); assertThat(newPkg.getFilename()).isEqualTo(buildFile2); - assertThat(newPkg.getSourceRoot()).isEqualTo(scratch.dir("/otherroot")); + assertThat(newPkg.getSourceRoot()).isEqualTo(Root.fromPath(scratch.dir("/otherroot"))); // TODO(bazel-team): (2009) test BUILD file moves in the other direction too. } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java index 13faa5fd77..1cac35349c 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/PathPackageLocatorTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.skyframe.BazelSkyframeExecutorConstants; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.UnixGlob; import java.io.IOException; import java.util.Arrays; @@ -159,12 +160,12 @@ public class PathPackageLocatorTest extends FoundationTestCase { locator = new PathPackageLocator( outputBase, - ImmutableList.of(rootDir1, rootDir2), + ImmutableList.of(Root.fromPath(rootDir1), Root.fromPath(rootDir2)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); locatorWithSymlinks = new PathPackageLocator( outputBase, - ImmutableList.of(rootDir3), + ImmutableList.of(Root.fromPath(rootDir3)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); } @@ -308,10 +309,10 @@ public class PathPackageLocatorTest extends FoundationTestCase { BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY) .getPathEntries()) .containsExactly( - belowClient, - clientPath, - workspace.getRelative("somewhere"), - clientPath.getRelative("below")) + Root.fromPath(belowClient), + Root.fromPath(clientPath), + Root.fromPath(workspace.getRelative("somewhere")), + Root.fromPath(clientPath.getRelative("below"))) .inOrder(); } diff --git a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java index fb8a3cb622..f6ec361cd6 100644 --- a/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/pkgcache/TargetPatternEvaluatorTest.java @@ -32,6 +32,7 @@ import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.util.Arrays; import java.util.Set; import org.junit.Before; @@ -136,12 +137,15 @@ public class TargetPatternEvaluatorTest extends AbstractTargetPatternEvaluatorTe } private void invalidate(String file) throws InterruptedException { - skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.builder().modify(PathFragment.create(file)).build(), rootDirectory); + skyframeExecutor.invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create(file)).build(), + Root.fromPath(rootDirectory)); } private void invalidate(ModifiedFileSet modifiedFileSet) throws InterruptedException { - skyframeExecutor.invalidateFilesUnderPathForTesting(reporter, modifiedFileSet, rootDirectory); + skyframeExecutor.invalidateFilesUnderPathForTesting( + reporter, modifiedFileSet, Root.fromPath(rootDirectory)); } private void setDeletedPackages(Set<PackageIdentifier> deletedPackages) { diff --git a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java index 48953ce2f9..e03f85d390 100644 --- a/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java +++ b/src/test/java/com/google/devtools/build/lib/remote/TreeNodeRepositoryTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.testutil.Scratch; import com.google.devtools.build.lib.vfs.FileSystem.HashFunction; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.remoteexecution.v1test.Digest; import com.google.devtools.remoteexecution.v1test.Directory; @@ -53,7 +54,7 @@ public class TreeNodeRepositoryTest { digestUtil = new DigestUtil(HashFunction.SHA256); scratch = new Scratch(new InMemoryFileSystem(BlazeClock.instance(), HashFunction.SHA256)); execRoot = scratch.getFileSystem().getPath("/exec/root"); - rootDir = ArtifactRoot.asSourceRoot(scratch.dir("/exec/root")); + rootDir = ArtifactRoot.asSourceRoot(Root.fromPath(scratch.dir("/exec/root"))); } private TreeNodeRepository createTestTreeNodeRepository() { diff --git a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java index 9d1607e36b..ef89884049 100644 --- a/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java +++ b/src/test/java/com/google/devtools/build/lib/repository/ExternalPackageUtilTest.java @@ -50,6 +50,7 @@ import com.google.devtools.build.lib.skyframe.WorkspaceASTFunction; import com.google.devtools.build.lib.skyframe.WorkspaceFileFunction; import com.google.devtools.build.lib.syntax.SkylarkSemantics; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.LegacySkyKey; @@ -85,7 +86,7 @@ public class ExternalPackageUtilTest extends BuildViewTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); AtomicReference<ImmutableSet<PackageIdentifier>> deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java index 37bcf0d2db..18c5bb460d 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/ResourceTestBase.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.packages.AbstractRuleErrorConsumer; import com.google.devtools.build.lib.packages.RuleErrorConsumer; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import java.util.ArrayList; import java.util.Collection; @@ -162,7 +163,7 @@ public abstract class ResourceTestBase { public void setup() { errorConsumer = new FakeRuleErrorConsumer(); fileSystem = new InMemoryFileSystem(); - root = ArtifactRoot.asSourceRoot(fileSystem.getRootDirectory()); + root = ArtifactRoot.asSourceRoot(Root.fromFileSystemRoot(fileSystem)); } @After @@ -182,6 +183,6 @@ public abstract class ResourceTestBase { public Artifact getResource(String pathString) { Path path = fileSystem.getPath("/" + RESOURCE_ROOT + "/" + pathString); return new Artifact( - path, root, root.getExecPath().getRelative(path.relativeTo(root.getPath())), OWNER); + path, root, root.getExecPath().getRelative(root.getRoot().relativize(path)), OWNER); } } diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java index b70d273067..ac3c2c863a 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CcCommonTest.java @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.util.OsUtils; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig; import com.google.devtools.common.options.InvocationPolicyEnforcer; import java.util.Arrays; @@ -551,7 +552,7 @@ public class CcCommonTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, new ModifiedFileSet.Builder().modify(PathFragment.create("WORKSPACE")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); FileSystemUtils.createDirectoryAndParents(scratch.resolve("/foo/bar")); scratch.file("/foo/WORKSPACE", "workspace(name = 'pkg')"); scratch.file( diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java index 703c3ffb73..3819117c7c 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CppLinkActionTest.java @@ -524,7 +524,9 @@ public class CppLinkActionTest extends BuildViewTestCase { public Artifact getOutputArtifact(String relpath) { return new Artifact( - getTargetConfiguration().getBinDirectory(RepositoryName.MAIN).getPath() + getTargetConfiguration() + .getBinDirectory(RepositoryName.MAIN) + .getRoot() .getRelative(relpath), getTargetConfiguration().getBinDirectory(RepositoryName.MAIN), getTargetConfiguration().getBinFragment().getRelative(relpath)); diff --git a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java index 273d986133..6c4a74f289 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/cpp/CreateIncSymlinkActionTest.java @@ -39,52 +39,55 @@ public class CreateIncSymlinkActionTest extends FoundationTestCase { @Test public void testDifferentOrderSameActionKey() throws Exception { - ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, rootDirectory.getRelative("out")); + Path includePath = rootDirectory.getRelative("out"); + ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, includePath); Artifact a = new Artifact(PathFragment.create("a"), root); Artifact b = new Artifact(PathFragment.create("b"), root); Artifact c = new Artifact(PathFragment.create("c"), root); Artifact d = new Artifact(PathFragment.create("d"), root); - CreateIncSymlinkAction action1 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(a, b, c, d), root.getPath()); + CreateIncSymlinkAction action1 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b, c, d), includePath); // Can't reuse the artifacts here; that would lead to DuplicateArtifactException. a = new Artifact(PathFragment.create("a"), root); b = new Artifact(PathFragment.create("b"), root); c = new Artifact(PathFragment.create("c"), root); d = new Artifact(PathFragment.create("d"), root); - CreateIncSymlinkAction action2 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(c, d, a, b), root.getPath()); + CreateIncSymlinkAction action2 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(c, d, a, b), includePath); assertThat(action2.computeKey(actionKeyContext)) .isEqualTo(action1.computeKey(actionKeyContext)); } @Test public void testDifferentTargetsDifferentActionKey() throws Exception { - ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, rootDirectory.getRelative("out")); + Path includePath = rootDirectory.getRelative("out"); + ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, includePath); Artifact a = new Artifact(PathFragment.create("a"), root); Artifact b = new Artifact(PathFragment.create("b"), root); - CreateIncSymlinkAction action1 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(a, b), root.getPath()); + CreateIncSymlinkAction action1 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), includePath); // Can't reuse the artifacts here; that would lead to DuplicateArtifactException. a = new Artifact(PathFragment.create("a"), root); b = new Artifact(PathFragment.create("c"), root); - CreateIncSymlinkAction action2 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(a, b), root.getPath()); + CreateIncSymlinkAction action2 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), includePath); assertThat(action2.computeKey(actionKeyContext)) .isNotEqualTo(action1.computeKey(actionKeyContext)); } @Test public void testDifferentSymlinksDifferentActionKey() throws Exception { - ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, rootDirectory.getRelative("out")); + Path includePath = rootDirectory.getRelative("out"); + ArtifactRoot root = ArtifactRoot.asDerivedRoot(rootDirectory, includePath); Artifact a = new Artifact(PathFragment.create("a"), root); Artifact b = new Artifact(PathFragment.create("b"), root); - CreateIncSymlinkAction action1 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(a, b), root.getPath()); + CreateIncSymlinkAction action1 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), includePath); // Can't reuse the artifacts here; that would lead to DuplicateArtifactException. a = new Artifact(PathFragment.create("c"), root); b = new Artifact(PathFragment.create("b"), root); - CreateIncSymlinkAction action2 = new CreateIncSymlinkAction(NULL_ACTION_OWNER, - ImmutableMap.of(a, b), root.getPath()); + CreateIncSymlinkAction action2 = + new CreateIncSymlinkAction(NULL_ACTION_OWNER, ImmutableMap.of(a, b), includePath); assertThat(action2.computeKey(actionKeyContext)) .isNotEqualTo(action1.computeKey(actionKeyContext)); } diff --git a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java index 08d6f9c9f6..d21acf1839 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/proto/ProtoCompileActionBuilderTest.java @@ -34,6 +34,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; import com.google.devtools.build.lib.collect.nestedset.Order; import com.google.devtools.build.lib.rules.proto.ProtoCompileActionBuilder.ToolchainInvocation; import com.google.devtools.build.lib.util.LazyString; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import javax.annotation.Nullable; import org.junit.Ignore; @@ -45,7 +46,8 @@ import org.junit.runners.JUnit4; public class ProtoCompileActionBuilderTest { private static final InMemoryFileSystem FILE_SYSTEM = new InMemoryFileSystem(); - private final ArtifactRoot root = ArtifactRoot.asSourceRoot(FILE_SYSTEM.getPath("/")); + private final ArtifactRoot root = + ArtifactRoot.asSourceRoot(Root.fromPath(FILE_SYSTEM.getPath("/"))); private final ArtifactRoot derivedRoot = ArtifactRoot.asDerivedRoot(FILE_SYSTEM.getPath("/"), FILE_SYSTEM.getPath("/out")); @@ -345,7 +347,7 @@ public class ProtoCompileActionBuilderTest { private Artifact artifact(String ownerLabel, String path) { return new Artifact( - root.getPath().getRelative(path), + root.getRoot().getRelative(path), root, root.getExecPath().getRelative(path), new LabelArtifactOwner(Label.parseAbsoluteUnchecked(ownerLabel))); @@ -354,7 +356,7 @@ public class ProtoCompileActionBuilderTest { /** Creates a dummy artifact with the given path, that actually resides in /out/<path>. */ private Artifact derivedArtifact(String ownerLabel, String path) { return new Artifact( - derivedRoot.getPath().getRelative(path), + derivedRoot.getRoot().getRelative(path), derivedRoot, derivedRoot.getExecPath().getRelative(path), new LabelArtifactOwner(Label.parseAbsoluteUnchecked(ownerLabel))); diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java index 49d292a66b..4cc07e2513 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorTest.java @@ -44,6 +44,7 @@ import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.MemoizingEvaluator; @@ -82,7 +83,7 @@ public class RepositoryDelegatorTest extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( root, - ImmutableList.of(root), + ImmutableList.of(Root.fromPath(root)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper( pkgLocator, diff --git a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryFunctionTest.java b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryFunctionTest.java index 929531ed43..c767d51599 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/repository/RepositoryFunctionTest.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.skyframe.FileValue.RegularFileValue; 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; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; @@ -122,7 +123,8 @@ public class RepositoryFunctionTest extends BuildViewTestCase { @Test public void testFileValueToMarkerValue() throws Exception { - RootedPath path = RootedPath.toRootedPath(rootDirectory, scratch.file("foo", "bar")); + RootedPath path = + RootedPath.toRootedPath(Root.fromPath(rootDirectory), scratch.file("foo", "bar")); // Digest should be returned if the FileStateValue has it. FileStateValue fsv = new RegularFileStateValue(3, new byte[] {1, 2, 3, 4}, null); diff --git a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java index b5227056fe..023ce8475a 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/BuildEventStreamerTest.java @@ -55,6 +55,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetView; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -520,7 +521,7 @@ public class BuildEventStreamerTest extends FoundationTestCase { private Artifact makeArtifact(String pathString) { Path path = outputBase.getRelative(PathFragment.create(pathString)); - return new Artifact(path, ArtifactRoot.asSourceRoot(outputBase)); + return new Artifact(path, ArtifactRoot.asSourceRoot(Root.fromPath(outputBase))); } @Test diff --git a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java index b7db0b3a8b..64244a5787 100644 --- a/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java +++ b/src/test/java/com/google/devtools/build/lib/runtime/ExperimentalStateTrackerTest.java @@ -51,6 +51,7 @@ import com.google.devtools.build.lib.util.Pair; import com.google.devtools.build.lib.util.io.LoggingTerminalWriter; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.view.test.TestStatus.BlazeTestStatus; import java.io.IOException; import java.net.URL; @@ -68,7 +69,7 @@ public class ExperimentalStateTrackerTest extends FoundationTestCase { private Action mockAction(String progressMessage, String primaryOutput) { Path path = outputBase.getRelative(PathFragment.create(primaryOutput)); - Artifact artifact = new Artifact(path, ArtifactRoot.asSourceRoot(outputBase)); + Artifact artifact = new Artifact(path, ArtifactRoot.asSourceRoot(Root.fromPath(outputBase))); Action action = Mockito.mock(Action.class); when(action.getProgressMessage()).thenReturn(progressMessage); @@ -473,7 +474,7 @@ public class ExperimentalStateTrackerTest extends FoundationTestCase { ManualClock clock = new ManualClock(); Path path = outputBase.getRelative(PathFragment.create(primaryOutput)); - Artifact artifact = new Artifact(path, ArtifactRoot.asSourceRoot(outputBase)); + Artifact artifact = new Artifact(path, ArtifactRoot.asSourceRoot(Root.fromPath(outputBase))); ActionExecutionMetadata actionMetadata = Mockito.mock(ActionExecutionMetadata.class); when(actionMetadata.getOwner()).thenReturn(Mockito.mock(ActionOwner.class)); when(actionMetadata.getPrimaryOutput()).thenReturn(artifact); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java index f122174101..9b2e73d3a8 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionTemplateExpansionFunctionTest.java @@ -42,6 +42,7 @@ import com.google.devtools.build.lib.skyframe.ArtifactSkyKey.OwnedArtifact; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.MemoizingEvaluator; @@ -75,7 +76,7 @@ public final class ActionTemplateExpansionFunctionTest extends FoundationTestCas new AtomicReference<>( new PathPackageLocator( rootDirectory.getFileSystem().getPath("/outputbase"), - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); RecordingDifferencer differencer = new SequencedRecordingDifferencer(); MemoizingEvaluator evaluator = 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 339ad4e7ec..c5abc9e663 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 @@ -41,6 +41,7 @@ import com.google.devtools.build.lib.vfs.FileStatus; 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; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyKey; @@ -245,7 +246,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { } private Artifact createSourceArtifact(String path) { - return new Artifact(PathFragment.create(path), ArtifactRoot.asSourceRoot(root)); + return new Artifact(PathFragment.create(path), ArtifactRoot.asSourceRoot(Root.fromPath(root))); } private Artifact createDerivedArtifact(String path) { @@ -264,7 +265,7 @@ public class ArtifactFunctionTest extends ArtifactFunctionTestCase { private Artifact createMiddlemanArtifact(String path) { ArtifactRoot middlemanRoot = ArtifactRoot.middlemanRoot(middlemanPath, middlemanPath.getRelative("out")); - Path fullPath = middlemanRoot.getPath().getRelative(path); + Path fullPath = middlemanRoot.getRoot().getRelative(path); return new Artifact( fullPath, middlemanRoot, fullPath.relativeTo(middlemanRoot.getExecRoot()), ALL_OWNER); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java index 375c715750..202050604b 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ArtifactFunctionTestCase.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.testutil.TestUtils; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.MemoizingEvaluator; @@ -73,7 +74,7 @@ abstract class ArtifactFunctionTestCase { new AtomicReference<>( new PathPackageLocator( root.getFileSystem().getPath("/outputbase"), - ImmutableList.of(root), + ImmutableList.of(Root.fromPath(root)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); BlazeDirectories directories = new BlazeDirectories(new ServerDirectories(root, root), root, TestConstants.PRODUCT_NAME); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java index 0728c5425e..fe2b28c74a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupFunctionTest.java @@ -40,6 +40,7 @@ import com.google.devtools.build.lib.syntax.SkylarkSemantics; import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; import com.google.devtools.build.skyframe.MemoizingEvaluator; import com.google.devtools.build.skyframe.RecordingDifferencer; @@ -77,7 +78,7 @@ public class ContainingPackageLookupFunctionTest extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); BlazeDirectories directories = @@ -178,7 +179,7 @@ public class ContainingPackageLookupFunctionTest extends FoundationTestCase { ContainingPackageLookupValue value = lookupContainingPackage("a/b"); assertThat(value.hasContainingPackage()).isTrue(); assertThat(value.getContainingPackageName()).isEqualTo(PackageIdentifier.createInMainRepo("a")); - assertThat(value.getContainingPackageRoot()).isEqualTo(rootDirectory); + assertThat(value.getContainingPackageRoot()).isEqualTo(Root.fromPath(rootDirectory)); } @Test @@ -188,7 +189,7 @@ public class ContainingPackageLookupFunctionTest extends FoundationTestCase { assertThat(value.hasContainingPackage()).isTrue(); assertThat(value.getContainingPackageName()) .isEqualTo(PackageIdentifier.createInMainRepo("a/b")); - assertThat(value.getContainingPackageRoot()).isEqualTo(rootDirectory); + assertThat(value.getContainingPackageRoot()).isEqualTo(Root.fromPath(rootDirectory)); } @Test @@ -227,18 +228,18 @@ public class ContainingPackageLookupFunctionTest extends FoundationTestCase { ContainingPackageLookupValue valueA2 = ContainingPackageLookupValue.NONE; ContainingPackageLookupValue valueB1 = ContainingPackageLookupValue.withContainingPackage( - PackageIdentifier.createInMainRepo("b"), rootDirectory); + PackageIdentifier.createInMainRepo("b"), Root.fromPath(rootDirectory)); ContainingPackageLookupValue valueB2 = ContainingPackageLookupValue.withContainingPackage( - PackageIdentifier.createInMainRepo("b"), rootDirectory); + PackageIdentifier.createInMainRepo("b"), Root.fromPath(rootDirectory)); PackageIdentifier cFrag = PackageIdentifier.createInMainRepo("c"); ContainingPackageLookupValue valueC1 = - ContainingPackageLookupValue.withContainingPackage(cFrag, rootDirectory); + ContainingPackageLookupValue.withContainingPackage(cFrag, Root.fromPath(rootDirectory)); ContainingPackageLookupValue valueC2 = - ContainingPackageLookupValue.withContainingPackage(cFrag, rootDirectory); + ContainingPackageLookupValue.withContainingPackage(cFrag, Root.fromPath(rootDirectory)); ContainingPackageLookupValue valueCOther = ContainingPackageLookupValue.withContainingPackage( - cFrag, rootDirectory.getRelative("other_root")); + cFrag, Root.fromPath(rootDirectory.getRelative("other_root"))); new EqualsTester() .addEqualityGroup(valueA1, valueA2) .addEqualityGroup(valueB1, valueB2) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java index dee4a46db6..5dbbaba462 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManagerTest.java @@ -23,8 +23,8 @@ import com.google.devtools.build.lib.events.util.EventCollectionApparatus; import com.google.devtools.build.lib.skyframe.DiffAwarenessManager.ProcessableModifiedFileSet; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.ModifiedFileSet; -import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.common.options.OptionsClassProvider; import java.util.List; @@ -57,7 +57,7 @@ public class DiffAwarenessManagerTest { @Test public void testEverythingModifiedIfNoDiffAwareness() throws Exception { - Path pathEntry = fs.getPath("/pathEntry"); + Root pathEntry = Root.fromPath(fs.getPath("/pathEntry")); DiffAwarenessFactoryStub factory = new DiffAwarenessFactoryStub(); DiffAwarenessManager manager = new DiffAwarenessManager(ImmutableList.of(factory)); assertWithMessage("Expected EVERYTHING_MODIFIED since there are no factories") @@ -71,7 +71,7 @@ public class DiffAwarenessManagerTest { @Test public void testResetAndSetPathEntriesCallClose() throws Exception { - Path pathEntry = fs.getPath("/pathEntry"); + Root pathEntry = Root.fromPath(fs.getPath("/pathEntry")); ModifiedFileSet diff = ModifiedFileSet.NOTHING_MODIFIED; DiffAwarenessStub diffAwareness1 = new DiffAwarenessStub(ImmutableList.of(diff)); DiffAwarenessStub diffAwareness2 = new DiffAwarenessStub(ImmutableList.of(diff)); @@ -96,7 +96,7 @@ public class DiffAwarenessManagerTest { @Test public void testHandlesUnprocessedDiffs() throws Exception { - Path pathEntry = fs.getPath("/pathEntry"); + Root pathEntry = Root.fromPath(fs.getPath("/pathEntry")); ModifiedFileSet diff1 = ModifiedFileSet.builder().modify(PathFragment.create("file1")).build(); ModifiedFileSet diff2 = ModifiedFileSet.builder().modify(PathFragment.create("file2")).build(); ModifiedFileSet diff3 = ModifiedFileSet.builder().modify(PathFragment.create("file3")).build(); @@ -132,7 +132,7 @@ public class DiffAwarenessManagerTest { @Test public void testHandlesBrokenDiffs() throws Exception { - Path pathEntry = fs.getPath("/pathEntry"); + Root pathEntry = Root.fromPath(fs.getPath("/pathEntry")); DiffAwarenessFactoryStub factory1 = new DiffAwarenessFactoryStub(); DiffAwarenessStub diffAwareness1 = new DiffAwarenessStub(ImmutableList.<ModifiedFileSet>of(), 1); @@ -196,19 +196,19 @@ public class DiffAwarenessManagerTest { private static class DiffAwarenessFactoryStub implements DiffAwareness.Factory { - private Map<Path, DiffAwareness> diffAwarenesses = Maps.newHashMap(); + private final Map<Root, DiffAwareness> diffAwarenesses = Maps.newHashMap(); - public void inject(Path pathEntry, DiffAwareness diffAwareness) { + public void inject(Root pathEntry, DiffAwareness diffAwareness) { diffAwarenesses.put(pathEntry, diffAwareness); } - public void remove(Path pathEntry) { + public void remove(Root pathEntry) { diffAwarenesses.remove(pathEntry); } @Override @Nullable - public DiffAwareness maybeCreate(Path pathEntry) { + public DiffAwareness maybeCreate(Root pathEntry) { return diffAwarenesses.get(pathEntry); } } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java index 0a0b460cd4..d0e33b537b 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileFunctionTest.java @@ -54,6 +54,7 @@ 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; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.lib.vfs.util.FileSystems; @@ -94,7 +95,7 @@ import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class FileFunctionTest { private CustomInMemoryFs fs; - private Path pkgRoot; + private Root pkgRoot; private Path outputBase; private PathPackageLocator pkgLocator; private boolean fastDigest; @@ -110,14 +111,14 @@ public class FileFunctionTest { private void createFsAndRoot(CustomInMemoryFs fs) throws IOException { this.fs = fs; - pkgRoot = fs.getPath("/root"); + pkgRoot = Root.fromPath(fs.getPath("/root")); outputBase = fs.getPath("/output_base"); pkgLocator = new PathPackageLocator( outputBase, ImmutableList.of(pkgRoot), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); - FileSystemUtils.createDirectoryAndParents(pkgRoot); + FileSystemUtils.createDirectoryAndParents(pkgRoot.asPath()); } private SequentialBuildDriver makeDriver() { @@ -128,7 +129,9 @@ public class FileFunctionTest { AtomicReference<PathPackageLocator> pkgLocatorRef = new AtomicReference<>(pkgLocator); BlazeDirectories directories = new BlazeDirectories( - new ServerDirectories(pkgRoot, outputBase), pkgRoot, TestConstants.PRODUCT_NAME); + new ServerDirectories(pkgRoot.asPath(), outputBase), + pkgRoot.asPath(), + TestConstants.PRODUCT_NAME); ExternalFilesHelper externalFilesHelper = new ExternalFilesHelper(pkgLocatorRef, externalFileAction, directories); differencer = new SequencedRecordingDifferencer(); @@ -183,11 +186,11 @@ public class FileFunctionTest { } private FileValue valueForPathOutsidePkgRoot(Path path) throws InterruptedException { - return valueForPathHelper(fs.getRootDirectory(), path); + return valueForPathHelper(Root.fromFileSystemRoot(fs), path); } - private FileValue valueForPathHelper(Path root, Path path) throws InterruptedException { - PathFragment pathFragment = path.relativeTo(root); + private FileValue valueForPathHelper(Root root, Path path) throws InterruptedException { + PathFragment pathFragment = root.relativize(path); RootedPath rootedPath = RootedPath.toRootedPath(root, pathFragment); SequentialBuildDriver driver = makeDriver(); SkyKey key = FileValue.key(rootedPath); @@ -312,8 +315,8 @@ public class FileFunctionTest { .containsExactly( rootedPath("a"), rootedPath(""), - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.EMPTY_FRAGMENT), - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("outside"))); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.EMPTY_FRAGMENT), + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("outside"))); } @Test @@ -329,8 +332,8 @@ public class FileFunctionTest { .containsExactly( rootedPath("a"), rootedPath(""), - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.EMPTY_FRAGMENT), - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("absolute"))); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.EMPTY_FRAGMENT), + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("absolute"))); } @Test @@ -344,7 +347,7 @@ public class FileFunctionTest { seenFiles.addAll(getFilesSeenAndAssertValueChangesIfContentsOfFileChanges("b", false, "a")); seenFiles.addAll( getFilesSeenAndAssertValueChangesIfContentsOfFileChanges(externalPath, true, "a")); - Path root = fs.getRootDirectory(); + Root root = Root.fromFileSystemRoot(fs); assertThat(seenFiles) .containsExactly( rootedPath("WORKSPACE"), @@ -626,7 +629,7 @@ public class FileFunctionTest { pkgLocator = new PathPackageLocator( outputBase, - ImmutableList.of(pkgRoot, otherPkgRoot), + ImmutableList.of(pkgRoot, Root.fromPath(otherPkgRoot)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY); symlink("a", "/other_root/b"); assertValueChangesIfContentsOfFileChanges("/other_root/b", true, "a"); @@ -823,7 +826,7 @@ public class FileFunctionTest { return super.getDigest(path, hf); } }; - pkgRoot = fs.getPath("/root"); + pkgRoot = Root.fromPath(fs.getPath("/root")); Path file = file("file"); FileSystemUtils.writeContentAsLatin1(file, Strings.repeat("a", 20)); byte[] digest = file.getDigest(); @@ -1108,7 +1111,7 @@ public class FileFunctionTest { // InMemoryFS is not supported for serialization. FileSystem fs = FileSystems.getJavaIoFileSystem(); Path.setFileSystemForSerialization(fs); - pkgRoot = fs.getRootDirectory(); + pkgRoot = Root.fromFileSystemRoot(fs); FileValue a = valueForPath(fs.getPath("/")); @@ -1175,24 +1178,24 @@ public class FileFunctionTest { @Test public void testSymlinkToPackagePathBoundary() throws Exception { Path path = path("this/is/a/path"); - FileSystemUtils.ensureSymbolicLink(path, pkgRoot); + FileSystemUtils.ensureSymbolicLink(path, pkgRoot.asPath()); assertError("this/is/a/path"); } private void runTestInfiniteSymlinkExpansion(boolean symlinkToAncestor, boolean absoluteSymlink) throws Exception { Path otherPath = path("other"); - RootedPath otherRootedPath = RootedPath.toRootedPath(pkgRoot, otherPath.relativeTo(pkgRoot)); + RootedPath otherRootedPath = RootedPath.toRootedPath(pkgRoot, pkgRoot.relativize(otherPath)); Path ancestorPath = path("a"); RootedPath ancestorRootedPath = - RootedPath.toRootedPath(pkgRoot, ancestorPath.relativeTo(pkgRoot)); + RootedPath.toRootedPath(pkgRoot, pkgRoot.relativize(ancestorPath)); FileSystemUtils.ensureSymbolicLink(otherPath, ancestorPath); Path intermediatePath = path("inter"); RootedPath intermediateRootedPath = - RootedPath.toRootedPath(pkgRoot, intermediatePath.relativeTo(pkgRoot)); + RootedPath.toRootedPath(pkgRoot, pkgRoot.relativize(intermediatePath)); Path descendantPath = path("a/b/c/d/e"); RootedPath descendantRootedPath = - RootedPath.toRootedPath(pkgRoot, descendantPath.relativeTo(pkgRoot)); + RootedPath.toRootedPath(pkgRoot, pkgRoot.relativize(descendantPath)); if (symlinkToAncestor) { FileSystemUtils.ensureSymbolicLink(descendantPath, intermediatePath); if (absoluteSymlink) { @@ -1312,7 +1315,7 @@ public class FileFunctionTest { private void checkRealPath(String pathString) throws Exception { Path realPath = pkgRoot.getRelative(pathString).resolveSymbolicLinks(); - assertRealPath(pathString, realPath.relativeTo(pkgRoot).toString()); + assertRealPath(pathString, pkgRoot.relativize(realPath).toString()); } private void assertRealPath(String pathString, String expectedRealPathString) throws Exception { @@ -1646,12 +1649,12 @@ public class FileFunctionTest { private RootedPath rootedPath(String pathString) { Path path = path(pathString); - for (Path root : pkgLocator.getPathEntries()) { - if (path.startsWith(root)) { + for (Root root : pkgLocator.getPathEntries()) { + if (root.contains(path)) { return RootedPath.toRootedPath(root, path); } } - return RootedPath.toRootedPath(fs.getRootDirectory(), path); + return RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), path); } private SkyKey skyKey(String pathString) { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java index 811afd134d..38bffd74c5 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FileSymlinkCycleUniquenessFunctionTest.java @@ -15,8 +15,8 @@ package com.google.devtools.build.lib.skyframe; import com.google.common.collect.ImmutableList; import com.google.common.testing.EqualsTester; -import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import org.junit.Test; @@ -28,7 +28,7 @@ public class FileSymlinkCycleUniquenessFunctionTest { @Test public void testHashCodeAndEqualsContract() throws Exception { - Path root = new InMemoryFileSystem().getPath("/root"); + Root root = Root.fromPath(new InMemoryFileSystem().getPath("/root")); RootedPath p1 = RootedPath.toRootedPath(root, PathFragment.create("p1")); RootedPath p2 = RootedPath.toRootedPath(root, PathFragment.create("p2")); RootedPath p3 = RootedPath.toRootedPath(root, PathFragment.create("p3")); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java index 26712266f3..20fadeef1e 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesetEntryFunctionTest.java @@ -45,6 +45,7 @@ import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; @@ -84,7 +85,7 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); AtomicReference<ImmutableSet<PackageIdentifier>> deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); @@ -129,7 +130,8 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { } private Artifact getSourceArtifact(String path) throws Exception { - return new Artifact(PathFragment.create(path), ArtifactRoot.asSourceRoot(rootDirectory)); + return new Artifact( + PathFragment.create(path), ArtifactRoot.asSourceRoot(Root.fromPath(rootDirectory))); } private Artifact createSourceArtifact(String path) throws Exception { @@ -139,18 +141,18 @@ public final class FilesetEntryFunctionTest extends FoundationTestCase { } private static RootedPath rootedPath(Artifact artifact) { - return RootedPath.toRootedPath(artifact.getRoot().getPath(), artifact.getRootRelativePath()); + return RootedPath.toRootedPath(artifact.getRoot().getRoot(), artifact.getRootRelativePath()); } private static RootedPath childOf(Artifact artifact, String relative) { return RootedPath.toRootedPath( - artifact.getRoot().getPath(), artifact.getRootRelativePath().getRelative(relative)); + artifact.getRoot().getRoot(), artifact.getRootRelativePath().getRelative(relative)); } private static RootedPath siblingOf(Artifact artifact, String relative) { PathFragment parent = Preconditions.checkNotNull(artifact.getRootRelativePath().getParentDirectory()); - return RootedPath.toRootedPath(artifact.getRoot().getPath(), parent.getRelative(relative)); + return RootedPath.toRootedPath(artifact.getRoot().getRoot(), parent.getRelative(relative)); } private void createFile(Path path, String... contents) throws Exception { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java index 01ed4fd6c1..851b7a8351 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/FilesystemValueCheckerTest.java @@ -50,6 +50,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.Symlinks; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -104,7 +105,7 @@ public class FilesystemValueCheckerTest { new AtomicReference<>( new PathPackageLocator( fs.getPath("/output_base"), - ImmutableList.of(pkgRoot), + ImmutableList.of(Root.fromPath(pkgRoot)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); BlazeDirectories directories = new BlazeDirectories( @@ -157,8 +158,9 @@ public class FilesystemValueCheckerTest { FileSystemUtils.createEmptyFile(path); assertEmptyDiff(getDirtyFilesystemKeys(evaluator, checker)); - SkyKey skyKey = FileStateValue.key( - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("foo"))); + SkyKey skyKey = + FileStateValue.key( + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo"))); EvaluationResult<SkyValue> result = driver.evaluate( ImmutableList.of(skyKey), @@ -209,13 +211,14 @@ public class FilesystemValueCheckerTest { FileSystemUtils.ensureSymbolicLink(sym1, path); FileSystemUtils.ensureSymbolicLink(sym2, path); SkyKey fooKey = - FileValue.key(RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("foo"))); + FileValue.key( + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo"))); RootedPath symlinkRootedPath = - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("bar")); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("bar")); SkyKey symlinkKey = FileValue.key(symlinkRootedPath); SkyKey symlinkFileStateKey = FileStateValue.key(symlinkRootedPath); RootedPath sym1RootedPath = - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("sym1")); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("sym1")); SkyKey sym1FileStateKey = FileStateValue.key(sym1RootedPath); Iterable<SkyKey> allKeys = ImmutableList.of(symlinkKey, fooKey); @@ -277,10 +280,10 @@ public class FilesystemValueCheckerTest { SkyKey key1 = FileStateValue.key( - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("foo1"))); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo1"))); SkyKey key2 = FileStateValue.key( - RootedPath.toRootedPath(fs.getRootDirectory(), PathFragment.create("foo2"))); + RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), PathFragment.create("foo2"))); Iterable<SkyKey> skyKeys = ImmutableList.of(key1, key2); EvaluationResult<SkyValue> result = driver.evaluate( @@ -310,8 +313,9 @@ public class FilesystemValueCheckerTest { path.createSymbolicLink(PathFragment.create("bar")); fs.readlinkThrowsIoException = true; - SkyKey fileKey = FileStateValue.key( - RootedPath.toRootedPath(pkgRoot, PathFragment.create("foo"))); + SkyKey fileKey = + FileStateValue.key( + RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo"))); EvaluationResult<SkyValue> result = driver.evaluate( ImmutableList.of(fileKey), @@ -335,7 +339,7 @@ public class FilesystemValueCheckerTest { FileSystemUtils.ensureSymbolicLink(path1, path2); FileSystemUtils.ensureSymbolicLink(path2, path3); FileSystemUtils.ensureSymbolicLink(path3, path1); - SkyKey fileKey1 = FileValue.key(RootedPath.toRootedPath(pkgRoot, path1)); + SkyKey fileKey1 = FileValue.key(RootedPath.toRootedPath(Root.fromPath(pkgRoot), path1)); EvaluationResult<SkyValue> result = driver.evaluate( @@ -616,9 +620,12 @@ public class FilesystemValueCheckerTest { Path outputPath = outputDir.getRelative(relPath); outputDir.createDirectory(); ArtifactRoot derivedRoot = ArtifactRoot.asDerivedRoot(fs.getPath("/"), outputDir); - return new SpecialArtifact(outputPath, derivedRoot, - derivedRoot.getExecPath().getRelative(outputPath.relativeTo(derivedRoot.getPath())), - ArtifactOwner.NULL_OWNER, SpecialArtifactType.TREE); + return new SpecialArtifact( + outputPath, + derivedRoot, + derivedRoot.getExecPath().getRelative(derivedRoot.getRoot().relativize(outputPath)), + ArtifactOwner.NULL_OWNER, + SpecialArtifactType.TREE); } @Test @@ -767,8 +774,10 @@ public class FilesystemValueCheckerTest { @Test public void testPropagatesRuntimeExceptions() throws Exception { - Collection<SkyKey> values = ImmutableList.of( - FileValue.key(RootedPath.toRootedPath(pkgRoot, PathFragment.create("foo")))); + Collection<SkyKey> values = + ImmutableList.of( + FileValue.key( + RootedPath.toRootedPath(Root.fromPath(pkgRoot), PathFragment.create("foo")))); driver.evaluate( values, false, SkyframeExecutor.DEFAULT_THREAD_COUNT, NullEventHandler.INSTANCE); FilesystemValueChecker checker = new FilesystemValueChecker(null, null); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java index 3601eaa0b0..e9605e328a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobDescriptorTest.java @@ -21,6 +21,7 @@ import com.google.devtools.build.lib.skyframe.serialization.testutils.FsUtils; import com.google.devtools.build.lib.skyframe.serialization.testutils.ObjectCodecTester; import com.google.devtools.build.lib.vfs.PathCodec; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -31,33 +32,34 @@ public class GlobDescriptorTest { @Test public void testSerialization() throws Exception { - ObjectCodecTester.newBuilder(GlobDescriptor.getCodec(new PathCodec(FsUtils.TEST_FILESYSTEM))) + ObjectCodecTester.newBuilder( + GlobDescriptor.getCodec(Root.getCodec(new PathCodec(FsUtils.TEST_FILESYSTEM)))) .addSubjects( GlobDescriptor.create( PackageIdentifier.create("@foo", PathFragment.create("//bar")), - FsUtils.TEST_FILESYSTEM.getPath("/packageRoot"), + Root.fromPath(FsUtils.TEST_FILESYSTEM.getPath("/packageRoot")), PathFragment.create("subdir"), "pattern", /*excludeDirs=*/ false), GlobDescriptor.create( PackageIdentifier.create("@bar", PathFragment.create("//foo")), - FsUtils.TEST_FILESYSTEM.getPath("/anotherPackageRoot"), + Root.fromPath(FsUtils.TEST_FILESYSTEM.getPath("/anotherPackageRoot")), PathFragment.create("anotherSubdir"), "pattern", /*excludeDirs=*/ true)) - .verificationFunction( - (orig, deserialized) -> assertThat(deserialized).isSameAs(orig)) + .verificationFunction((orig, deserialized) -> assertThat(deserialized).isSameAs(orig)) .buildAndRunTests(); } @Test public void testCreateReturnsInternedInstances() throws LabelSyntaxException { - GlobDescriptor original = GlobDescriptor.create( - PackageIdentifier.create("@foo", PathFragment.create("//bar")), - FsUtils.TEST_FILESYSTEM.getPath("/packageRoot"), - PathFragment.create("subdir"), - "pattern", - /*excludeDirs=*/ false); + GlobDescriptor original = + GlobDescriptor.create( + PackageIdentifier.create("@foo", PathFragment.create("//bar")), + Root.fromPath(FsUtils.TEST_FILESYSTEM.getPath("/packageRoot")), + PathFragment.create("subdir"), + "pattern", + /*excludeDirs=*/ false); GlobDescriptor sameCopy = GlobDescriptor.create( original.getPackageId(), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java index 51cf1cf265..ed8a74d761 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/GlobFunctionTest.java @@ -45,6 +45,7 @@ import com.google.devtools.build.lib.vfs.FileStatus; 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; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.UnixGlob; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; @@ -114,7 +115,7 @@ public abstract class GlobFunctionTest { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(writableRoot, root), + ImmutableList.of(Root.fromPath(writableRoot), Root.fromPath(root)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); differencer = new SequencedRecordingDifferencer(); @@ -411,7 +412,9 @@ public abstract class GlobFunctionTest { } private GlobValue runGlob(boolean excludeDirs, String pattern) throws Exception { - SkyKey skyKey = GlobValue.key(PKG_ID, root, pattern, excludeDirs, PathFragment.EMPTY_FRAGMENT); + SkyKey skyKey = + GlobValue.key( + PKG_ID, Root.fromPath(root), pattern, excludeDirs, PathFragment.EMPTY_FRAGMENT); EvaluationResult<SkyValue> result = driver.evaluate( ImmutableList.of(skyKey), @@ -438,28 +441,32 @@ public abstract class GlobFunctionTest { differencer.invalidate( ImmutableList.of( FileStateValue.key( - RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz/file"))))); + RootedPath.toRootedPath( + Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz/file"))))); // The result should not rely on the FileStateValue, so it's still a cache hit. assertGlobMatches(pattern, "foo/bar/wiz/file"); differencer.invalidate( ImmutableList.of( DirectoryListingStateValue.key( - RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz"))))); + RootedPath.toRootedPath( + Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz"))))); // This should have invalidated the glob result. assertGlobMatches(pattern /* => nothing */); } else { differencer.invalidate( ImmutableList.of( DirectoryListingStateValue.key( - RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz"))))); + RootedPath.toRootedPath( + Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz"))))); // The result should not rely on the DirectoryListingValue, so it's still a cache hit. assertGlobMatches(pattern, "foo/bar/wiz/file"); differencer.invalidate( ImmutableList.of( FileStateValue.key( - RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz/file"))))); + RootedPath.toRootedPath( + Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz/file"))))); // This should have invalidated the glob result. assertGlobMatches(pattern /* => nothing */); } @@ -492,7 +499,7 @@ public abstract class GlobFunctionTest { private void assertIllegalPattern(String pattern) { try { - GlobValue.key(PKG_ID, root, pattern, false, PathFragment.EMPTY_FRAGMENT); + GlobValue.key(PKG_ID, Root.fromPath(root), pattern, false, PathFragment.EMPTY_FRAGMENT); fail("invalid pattern not detected: " + pattern); } catch (InvalidGlobPatternException e) { // Expected. @@ -630,13 +637,14 @@ public abstract class GlobFunctionTest { public void testResilienceToFilesystemInconsistencies_DirectoryExistence() throws Exception { // Our custom filesystem says "pkgPath/BUILD" exists but "pkgPath" does not exist. fs.stubStat(pkgPath, null); - RootedPath pkgRootedPath = RootedPath.toRootedPath(root, pkgPath); + RootedPath pkgRootedPath = RootedPath.toRootedPath(Root.fromPath(root), pkgPath); FileStateValue pkgDirFileStateValue = FileStateValue.create(pkgRootedPath, null); FileValue pkgDirValue = FileValue.value(pkgRootedPath, pkgDirFileStateValue, pkgRootedPath, pkgDirFileStateValue); differencer.inject(ImmutableMap.of(FileValue.key(pkgRootedPath), pkgDirValue)); String expectedMessage = "/root/workspace/pkg is no longer an existing directory"; - SkyKey skyKey = GlobValue.key(PKG_ID, root, "*/foo", false, PathFragment.EMPTY_FRAGMENT); + SkyKey skyKey = + GlobValue.key(PKG_ID, Root.fromPath(root), "*/foo", false, PathFragment.EMPTY_FRAGMENT); EvaluationResult<GlobValue> result = driver.evaluate( ImmutableList.of(skyKey), @@ -655,7 +663,7 @@ public abstract class GlobFunctionTest { // direct stat on "pkgPath/foo/bar/wiz" says it does not exist. Path fooBarDir = pkgPath.getRelative("foo/bar"); fs.stubStat(fooBarDir.getRelative("wiz"), null); - RootedPath fooBarDirRootedPath = RootedPath.toRootedPath(root, fooBarDir); + RootedPath fooBarDirRootedPath = RootedPath.toRootedPath(Root.fromPath(root), fooBarDir); SkyValue fooBarDirListingValue = DirectoryListingStateValue.create( ImmutableList.of(new Dirent("wiz", Dirent.Type.DIRECTORY))); @@ -663,7 +671,8 @@ public abstract class GlobFunctionTest { ImmutableMap.of( DirectoryListingStateValue.key(fooBarDirRootedPath), fooBarDirListingValue)); String expectedMessage = "/root/workspace/pkg/foo/bar/wiz is no longer an existing directory."; - SkyKey skyKey = GlobValue.key(PKG_ID, root, "**/wiz", false, PathFragment.EMPTY_FRAGMENT); + SkyKey skyKey = + GlobValue.key(PKG_ID, Root.fromPath(root), "**/wiz", false, PathFragment.EMPTY_FRAGMENT); EvaluationResult<GlobValue> result = driver.evaluate( ImmutableList.of(skyKey), @@ -678,9 +687,10 @@ public abstract class GlobFunctionTest { @Test public void testResilienceToFilesystemInconsistencies_SymlinkType() throws Exception { - RootedPath wizRootedPath = RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz")); + RootedPath wizRootedPath = + RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz")); RootedPath fileRootedPath = - RootedPath.toRootedPath(root, pkgPath.getRelative("foo/bar/wiz/file")); + RootedPath.toRootedPath(Root.fromPath(root), pkgPath.getRelative("foo/bar/wiz/file")); final FileStatus realStat = fileRootedPath.asPath().stat(); fs.stubStat( fileRootedPath.asPath(), @@ -735,8 +745,9 @@ public abstract class GlobFunctionTest { ImmutableMap.of(DirectoryListingStateValue.key(wizRootedPath), wizDirListingValue)); String expectedMessage = "readdir and stat disagree about whether " + fileRootedPath.asPath() + " is a symlink"; - SkyKey skyKey = GlobValue.key(PKG_ID, root, "foo/bar/wiz/*", false, - PathFragment.EMPTY_FRAGMENT); + SkyKey skyKey = + GlobValue.key( + PKG_ID, Root.fromPath(root), "foo/bar/wiz/*", false, PathFragment.EMPTY_FRAGMENT); EvaluationResult<GlobValue> result = driver.evaluate( ImmutableList.of(skyKey), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java index a854d2ef34..244505872a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; 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; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; @@ -69,7 +70,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); BlazeDirectories directories = @@ -143,7 +144,8 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { @Test public void testNoPath() throws Exception { LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.EMPTY_FRAGMENT)); + lookupDirectory( + RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.EMPTY_FRAGMENT)); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); @@ -154,7 +156,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("some/path/BUILD"); LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("some/path"))); + lookupDirectory( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("some/path"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); @@ -167,7 +171,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("local/repo/BUILD"); LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); + lookupDirectory( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); @@ -182,7 +188,8 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory( RootedPath.toRootedPath( - rootDirectory.getRelative("/abs"), PathFragment.create("local/repo"))); + Root.fromPath(rootDirectory.getRelative("/abs")), + PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("/abs/local/repo")); @@ -195,7 +202,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("local/repo/BUILD"); LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); + lookupDirectory( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); @@ -210,7 +219,8 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory( RootedPath.toRootedPath( - rootDirectory.getRelative("/abs"), PathFragment.create("local/repo"))); + Root.fromPath(rootDirectory.getRelative("/abs")), + PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("/abs/local/repo")); @@ -225,7 +235,8 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { LocalRepositoryLookupValue repositoryLookupValue = lookupDirectory( - RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo/sub/package"))); + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo/sub/package"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); @@ -238,7 +249,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("local/repo/BUILD"); LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); + lookupDirectory( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); @@ -256,7 +269,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("local/repo/BUILD"); SkyKey localRepositoryKey = - createKey(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); + createKey( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo"))); EvaluationResult<LocalRepositoryLookupValue> result = lookupDirectory(localRepositoryKey); assertThatEvaluationResult(result) @@ -276,7 +291,9 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { scratch.file("local/repo/BUILD"); LocalRepositoryLookupValue repositoryLookupValue = - lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); + lookupDirectory( + RootedPath.toRootedPath( + Root.fromPath(rootDirectory), PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); // In this case, the repository should be MAIN as we can't find any local_repository rules. assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java index 8773d54825..07c7062462 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageFunctionTest.java @@ -42,6 +42,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.ErrorInfo; @@ -53,6 +54,7 @@ import com.google.devtools.common.options.Options; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -81,7 +83,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.copyOf(roots), + Arrays.stream(roots).map(Root::fromPath).collect(ImmutableList.toImmutableList()), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), @@ -118,7 +120,7 @@ public class PackageFunctionTest extends BuildViewTestCase { public void testPropagatesFilesystemInconsistencies() throws Exception { reporter.removeHandler(failFastHandler); RecordingDifferencer differencer = getSkyframeExecutor().getDifferencerForTesting(); - Path pkgRoot = getSkyframeExecutor().getPathEntries().get(0); + Root pkgRoot = getSkyframeExecutor().getPathEntries().get(0); Path fooBuildFile = scratch.file("foo/BUILD"); Path fooDir = fooBuildFile.getParentDirectory(); @@ -184,7 +186,7 @@ public class PackageFunctionTest extends BuildViewTestCase { public void testPropagatesFilesystemInconsistencies_Globbing() throws Exception { reporter.removeHandler(failFastHandler); RecordingDifferencer differencer = getSkyframeExecutor().getDifferencerForTesting(); - Path pkgRoot = getSkyframeExecutor().getPathEntries().get(0); + Root pkgRoot = getSkyframeExecutor().getPathEntries().get(0); scratch.file("foo/BUILD", "subinclude('//a:a')", "sh_library(name = 'foo', srcs = glob(['bar/**/baz.sh']))"); @@ -264,7 +266,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/d.txt")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); value = validPackage(skyKey); assertThat( (Iterable<Label>) @@ -295,7 +297,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); assertSrcs(validPackage(skyKey), "foo", "//foo:a.config", "//foo:b.txt"); scratch.overwriteFile( "foo/BUILD", "sh_library(name = 'foo', srcs = glob(['*.txt', '*.config'])) # comment"); @@ -303,7 +305,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); assertSrcs(validPackage(skyKey), "foo", "//foo:a.config", "//foo:b.txt"); getSkyframeExecutor().resetEvaluator(); PackageCacheOptions packageCacheOptions = Options.getDefaults(PackageCacheOptions.class); @@ -314,7 +316,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.<Path>of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), @@ -361,7 +363,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); PackageValue fooValue2 = validPackage(fooKey); assertThat(fooValue2).isNotEqualTo(fooValue); assertSrcs(fooValue2, "foo", "//foo:link.sh", "//foo:ordinary.sh"); @@ -403,7 +405,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/irrelevant")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); assertThat(validPackage(skyKey)).isSameAs(value); } @@ -421,7 +423,7 @@ public class PackageFunctionTest extends BuildViewTestCase { .invalidateFilesUnderPathForTesting( reporter, ModifiedFileSet.builder().modify(PathFragment.create("foo/irrelevant")).build(), - rootDirectory); + Root.fromPath(rootDirectory)); assertThat(validPackage(skyKey)).isSameAs(value); } @@ -450,10 +452,11 @@ public class PackageFunctionTest extends BuildViewTestCase { scratch.overwriteFile("bar/ext.bzl", "load('//qux:ext.bzl', 'c')", "a = c"); - getSkyframeExecutor().invalidateFilesUnderPathForTesting( - reporter, - ModifiedFileSet.builder().modify(PathFragment.create("bar/ext.bzl")).build(), - rootDirectory); + getSkyframeExecutor() + .invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create("bar/ext.bzl")).build(), + Root.fromPath(rootDirectory)); value = validPackage(skyKey); assertThat(value.getPackage().getSkylarkFileDependencies()).containsExactly( @@ -569,7 +572,7 @@ public class PackageFunctionTest extends BuildViewTestCase { Predicates.equalTo( com.google.devtools.build.lib.skyframe.FileStateValue.key( RootedPath.toRootedPath( - workspacePath.getParentDirectory(), + Root.fromPath(workspacePath.getParentDirectory()), PathFragment.create(workspacePath.getBaseName()))))); reporter.removeHandler(failFastHandler); @@ -605,8 +608,11 @@ public class PackageFunctionTest extends BuildViewTestCase { "exports_files(glob(['*.txt']))", "#some-irrelevant-comment"); - getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), rootDirectory); + getSkyframeExecutor() + .invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), + Root.fromPath(rootDirectory)); value = validPackage(skyKey); assertThat(value.getPackage().containsErrors()).isFalse(); @@ -621,8 +627,11 @@ public class PackageFunctionTest extends BuildViewTestCase { } scratch.file("foo/nope"); - getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.builder().modify(PathFragment.create("foo/nope")).build(), rootDirectory); + getSkyframeExecutor() + .invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create("foo/nope")).build(), + Root.fromPath(rootDirectory)); PackageValue newValue = validPackage(skyKey); assertThat(newValue.getPackage().containsErrors()).isFalse(); @@ -657,8 +666,11 @@ public class PackageFunctionTest extends BuildViewTestCase { scratch.overwriteFile("foo/BUILD", "[sh_library(name = x + '-matched') for x in glob(['**'], exclude_directories = 0)]", "#some-irrelevant-comment"); - getSkyframeExecutor().invalidateFilesUnderPathForTesting(reporter, - ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), rootDirectory); + getSkyframeExecutor() + .invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create("foo/BUILD")).build(), + Root.fromPath(rootDirectory)); value = validPackage(skyKey); assertThat(value.getPackage().containsErrors()).isFalse(); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java index d9a3f5a701..6f34ab6fdb 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PackageLookupFunctionTest.java @@ -48,6 +48,7 @@ import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; 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; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; @@ -94,7 +95,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(emptyPackagePath, rootDirectory), + ImmutableList.of(Root.fromPath(emptyPackagePath), Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); BlazeDirectories directories = @@ -228,9 +229,10 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.overwriteFile( ADDITIONAL_BLACKLISTED_PACKAGE_PREFIXES_FILE_PATH_STRING, "not_blacklisted"); - RootedPath rootedBlacklist = RootedPath.toRootedPath( - blacklist.getParentDirectory().getParentDirectory(), - PathFragment.create("config/blacklisted.txt")); + RootedPath rootedBlacklist = + RootedPath.toRootedPath( + Root.fromPath(blacklist.getParentDirectory().getParentDirectory()), + PathFragment.create("config/blacklisted.txt")); differencer.invalidate(ImmutableSet.of(FileStateValue.key(rootedBlacklist))); for (String pkg : pkgs) { PackageLookupValue packageLookupValue = lookupPackage(pkg); @@ -261,7 +263,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.file("parentpackage/everythinggood/BUILD"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(rootDirectory)); assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @@ -270,7 +272,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.file("parentpackage/everythinggood/BUILD.bazel"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(rootDirectory)); assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD_DOT_BAZEL); } @@ -280,7 +282,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.file("parentpackage/everythinggood/BUILD.bazel"); PackageLookupValue packageLookupValue = lookupPackage("parentpackage/everythinggood"); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(rootDirectory)); assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD_DOT_BAZEL); } @@ -292,7 +294,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { // BUILD file in the first package path should be preferred to BUILD.bazel in the second. PackageLookupValue packageLookupValue = lookupPackage("foo"); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(emptyPackagePath); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(emptyPackagePath)); assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @@ -301,7 +303,7 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { scratch.file("BUILD"); PackageLookupValue packageLookupValue = lookupPackage(""); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(rootDirectory)); assertThat(packageLookupValue.getBuildFileName()).isEqualTo(BuildFileName.BUILD); } @@ -311,13 +313,13 @@ public abstract class PackageLookupFunctionTest extends FoundationTestCase { PackageLookupValue packageLookupValue = lookupPackage( PackageIdentifier.createInMainRepo("external")); assertThat(packageLookupValue.packageExists()).isTrue(); - assertThat(packageLookupValue.getRoot()).isEqualTo(rootDirectory); + assertThat(packageLookupValue.getRoot()).isEqualTo(Root.fromPath(rootDirectory)); } @Test public void testPackageLookupValueHashCodeAndEqualsContract() throws Exception { - Path root1 = rootDirectory.getRelative("root1"); - Path root2 = rootDirectory.getRelative("root2"); + Root root1 = Root.fromPath(rootDirectory.getRelative("root1")); + Root root2 = Root.fromPath(rootDirectory.getRelative("root2")); // Our (seeming) duplication of parameters here is intentional. Some of the subclasses of // PackageLookupValue are supposed to have reference equality semantics, and some are supposed // to have logical equality semantics. diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java index 2f43b7c083..fa745c6320 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternsFunctionSmartNegationTest.java @@ -36,6 +36,7 @@ import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.testutil.TestConstants; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.build.skyframe.SkyValue; @@ -91,7 +92,7 @@ public class PrepareDepsOfPatternsFunctionSmartNegationTest extends FoundationTe skyframeExecutor.preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), Options.getDefaults(PackageCacheOptions.class), Options.getDefaults(SkylarkSemanticsOptions.class), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java index be3b163596..49d502b900 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfTargetsUnderDirectoryFunctionTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.pkgcache.FilteringPolicies; import com.google.devtools.build.lib.pkgcache.FilteringPolicy; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.BuildDriver; import com.google.devtools.build.skyframe.EvaluationResult; @@ -54,7 +55,7 @@ public class PrepareDepsOfTargetsUnderDirectoryFunctionTest extends BuildViewTes private SkyKey createCollectPackagesKey( Path root, PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) { - RootedPath rootedPath = RootedPath.toRootedPath(root, rootRelativePath); + RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), rootRelativePath); return CollectPackagesUnderDirectoryValue.key( RepositoryName.MAIN, rootedPath, excludedPaths); } @@ -65,14 +66,14 @@ public class PrepareDepsOfTargetsUnderDirectoryFunctionTest extends BuildViewTes private SkyKey createPrepDepsKey(Path root, PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) { - RootedPath rootedPath = RootedPath.toRootedPath(root, rootRelativePath); + RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), rootRelativePath); return PrepareDepsOfTargetsUnderDirectoryValue.key( RepositoryName.MAIN, rootedPath, excludedPaths); } private SkyKey createPrepDepsKey(Path root, PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths, FilteringPolicy filteringPolicy) { - RootedPath rootedPath = RootedPath.toRootedPath(root, rootRelativePath); + RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), rootRelativePath); return PrepareDepsOfTargetsUnderDirectoryValue.key( RepositoryName.MAIN, rootedPath, excludedPaths, filteringPolicy); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java index 1779162f01..96fa7e48ed 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunctionTest.java @@ -46,6 +46,7 @@ import com.google.devtools.build.lib.testutil.FoundationTestCase; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.EvaluationProgressReceiver; @@ -89,7 +90,7 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); AtomicReference<ImmutableSet<PackageIdentifier>> deletedPackages = new AtomicReference<>(ImmutableSet.<PackageIdentifier>of()); @@ -150,13 +151,14 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe } private Artifact sourceArtifact(String path) { - return new Artifact(PathFragment.create(path), ArtifactRoot.asSourceRoot(rootDirectory)); + return new Artifact( + PathFragment.create(path), ArtifactRoot.asSourceRoot(Root.fromPath(rootDirectory))); } private Artifact sourceArtifactUnderPackagePath(String path, String packagePath) { return new Artifact( PathFragment.create(path), - ArtifactRoot.asSourceRoot(rootDirectory.getRelative(packagePath))); + ArtifactRoot.asSourceRoot(Root.fromPath(rootDirectory.getRelative(packagePath)))); } private Artifact derivedArtifact(String path) { @@ -171,17 +173,17 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe } private static RootedPath rootedPath(Artifact artifact) { - return RootedPath.toRootedPath(artifact.getRoot().getPath(), artifact.getRootRelativePath()); + return RootedPath.toRootedPath(artifact.getRoot().getRoot(), artifact.getRootRelativePath()); } private RootedPath rootedPath(String path, String packagePath) { return RootedPath.toRootedPath( - rootDirectory.getRelative(packagePath), PathFragment.create(path)); + Root.fromPath(rootDirectory.getRelative(packagePath)), PathFragment.create(path)); } private static RootedPath childOf(Artifact artifact, String relative) { return RootedPath.toRootedPath( - artifact.getRoot().getPath(), artifact.getRootRelativePath().getRelative(relative)); + artifact.getRoot().getRoot(), artifact.getRootRelativePath().getRelative(relative)); } private static RootedPath childOf(RootedPath path, String relative) { @@ -201,7 +203,7 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe private static RootedPath siblingOf(Artifact artifact, String relative) { PathFragment parent = Preconditions.checkNotNull(artifact.getRootRelativePath().getParentDirectory()); - return RootedPath.toRootedPath(artifact.getRoot().getPath(), parent.getRelative(relative)); + return RootedPath.toRootedPath(artifact.getRoot().getRoot(), parent.getRelative(relative)); } private void createFile(Path path, String... contents) throws Exception { @@ -702,7 +704,9 @@ public final class RecursiveFilesystemTraversalFunctionTest extends FoundationTe pkgLocator.set( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory.getRelative("pp1"), rootDirectory.getRelative("pp2")), + ImmutableList.of( + Root.fromPath(rootDirectory.getRelative("pp1")), + Root.fromPath(rootDirectory.getRelative("pp2"))), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); PrecomputedValue.PATH_PACKAGE_LOCATOR.set(differencer, pkgLocator.get()); diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java index f07b6ab93d..ac45a7e371 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgFunctionTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.BuildDriver; import com.google.devtools.build.skyframe.EvaluationResult; @@ -55,7 +56,7 @@ public class RecursivePkgFunctionTest extends BuildViewTestCase { private SkyKey buildRecursivePkgKey( Path root, PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) { - RootedPath rootedPath = RootedPath.toRootedPath(root, rootRelativePath); + RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), rootRelativePath); return RecursivePkgValue.key( RepositoryName.MAIN, rootedPath, excludedPaths); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java index e205cabf1c..b6bd39494b 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/RecursivePkgKeyTest.java @@ -20,9 +20,9 @@ import com.google.devtools.build.lib.analysis.util.BuildViewTestCase; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.skyframe.RecursivePkgValue.RecursivePkgKey; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyKey; - import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -35,7 +35,7 @@ public class RecursivePkgKeyTest extends BuildViewTestCase { RepositoryName repository, PathFragment rootRelativePath, ImmutableSet<PathFragment> excludedPaths) { - RootedPath rootedPath = RootedPath.toRootedPath(rootDirectory, rootRelativePath); + RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(rootDirectory), rootRelativePath); return RecursivePkgValue.key(repository, rootedPath, excludedPaths); } diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java index e497ab7d85..10e9674146 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeAwareActionTest.java @@ -35,6 +35,7 @@ import com.google.devtools.build.lib.actions.util.DummyExecutor; import com.google.devtools.build.lib.util.Fingerprint; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.EvaluationProgressReceiver; import com.google.devtools.build.skyframe.EvaluationProgressReceiver.EvaluationState; @@ -352,7 +353,7 @@ public class SkyframeAwareActionTest extends TimestampBuilderTestCase { differencer.invalidate( ImmutableList.of( FileStateValue.key( - RootedPath.toRootedPath(file.getRoot().getPath(), file.getRootRelativePath())))); + RootedPath.toRootedPath(file.getRoot().getRoot(), file.getRootRelativePath())))); } private void assertActionExecutions( @@ -445,7 +446,7 @@ public class SkyframeAwareActionTest extends TimestampBuilderTestCase { private RootedPath createSkyframeDepOfAction() throws Exception { scratch.file(rootDirectory.getRelative("action.dep").getPathString(), "blah"); - return RootedPath.toRootedPath(rootDirectory, PathFragment.create("action.dep")); + return RootedPath.toRootedPath(Root.fromPath(rootDirectory), PathFragment.create("action.dep")); } private void appendToFile(Path path) throws Exception { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java index 63e900f344..b13b87910b 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTest.java @@ -34,6 +34,7 @@ import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.common.options.Options; import java.io.IOException; import java.util.Collection; @@ -407,7 +408,7 @@ public class SkyframeLabelVisitorTest extends SkyframeLabelVisitorTestCase { .preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java index f20cea8a51..90843718d7 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkyframeLabelVisitorTestCase.java @@ -38,6 +38,7 @@ import com.google.devtools.build.lib.vfs.FileStatus; import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.DelegatingWalkableGraph; import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator; @@ -219,7 +220,8 @@ abstract public class SkyframeLabelVisitorTestCase extends PackageLoadingTestCas protected void syncPackages(ModifiedFileSet modifiedFileSet) throws InterruptedException { getSkyframeExecutor() - .invalidateFilesUnderPathForTesting(reporter, modifiedFileSet, rootDirectory); + .invalidateFilesUnderPathForTesting( + reporter, modifiedFileSet, Root.fromPath(rootDirectory)); } protected Set<Target> asTargetSet(Iterable<String> strLabels) diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java index bbf34899b6..172ec3964a 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkFileContentHashTests.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.pkgcache.PackageCacheOptions; import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; import com.google.devtools.common.options.Options; @@ -165,7 +166,7 @@ public class SkylarkFileContentHashTests extends BuildViewTestCase { .preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java index 9d73fc810f..03ec708273 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/SkylarkImportLookupFunctionTest.java @@ -28,6 +28,7 @@ import com.google.devtools.build.lib.pkgcache.PathPackageLocator; import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; import com.google.devtools.build.lib.util.io.TimestampGranularityMonitor; import com.google.devtools.build.lib.vfs.Path; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; @@ -55,7 +56,7 @@ public class SkylarkImportLookupFunctionTest extends BuildViewTestCase { .preparePackageLoading( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory, alternativeRoot), + ImmutableList.of(Root.fromPath(rootDirectory), Root.fromPath(alternativeRoot)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY), packageCacheOptions, Options.getDefaults(SkylarkSemanticsOptions.class), diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java index 1e944d22cb..75a4888cc1 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TargetMarkerFunctionTest.java @@ -29,6 +29,7 @@ import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.EvaluationResult; @@ -90,7 +91,7 @@ public class TargetMarkerFunctionTest extends BuildViewTestCase { ModifiedFileSet subpackageBuildFile = ModifiedFileSet.builder().modify(PathFragment.create("a/b/BUILD")).build(); skyframeExecutor.invalidateFilesUnderPathForTesting( - reporter, subpackageBuildFile, rootDirectory); + reporter, subpackageBuildFile, Root.fromPath(rootDirectory)); NoSuchTargetException exn = (NoSuchTargetException) getErrorFromTargetValue(labelName); // In the presence of b/12545745, the error message is different and comes from the diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java index 8595811ec5..27e95b58bb 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/TimestampBuilderTestCase.java @@ -75,6 +75,7 @@ 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; import com.google.devtools.build.skyframe.CycleInfo; import com.google.devtools.build.skyframe.ErrorInfo; import com.google.devtools.build.skyframe.EvaluationProgressReceiver; @@ -160,7 +161,7 @@ public abstract class TimestampBuilderTestCase extends FoundationTestCase { new AtomicReference<>( new PathPackageLocator( outputBase, - ImmutableList.of(rootDirectory), + ImmutableList.of(Root.fromPath(rootDirectory)), BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY)); AtomicReference<TimestampGranularityMonitor> tsgmRef = new AtomicReference<>(tsgm); BlazeDirectories directories = @@ -324,7 +325,7 @@ public abstract class TimestampBuilderTestCase extends FoundationTestCase { Artifact createSourceArtifact(FileSystem fs, String name) { Path root = fs.getPath(TestUtils.tmpDir()); - return new Artifact(PathFragment.create(name), ArtifactRoot.asSourceRoot(root)); + return new Artifact(PathFragment.create(name), ArtifactRoot.asSourceRoot(Root.fromPath(root))); } protected Artifact createDerivedArtifact(String name) { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunctionTest.java index 95e1a6218a..ece3f59aed 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceASTFunctionTest.java @@ -24,6 +24,7 @@ import com.google.devtools.build.lib.syntax.BuildFileAST; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionException; @@ -60,7 +61,8 @@ public class WorkspaceASTFunctionTest extends BuildViewTestCase { Path workspacePath = scratch.overwriteFile("WORKSPACE", contents); fakeWorkspaceFileValue.setSize(workspacePath.getFileSize()); return RootedPath.toRootedPath( - workspacePath.getParentDirectory(), PathFragment.create(workspacePath.getBaseName())); + Root.fromPath(workspacePath.getParentDirectory()), + PathFragment.create(workspacePath.getBaseName())); } private SkyFunction.Environment getEnv() throws InterruptedException { diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java index d5e37ce5e6..95e9e880fa 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceFileFunctionTest.java @@ -30,6 +30,7 @@ import com.google.devtools.build.lib.testutil.MoreAsserts; import com.google.devtools.build.lib.testutil.TestRuleClassProvider; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.SkyFunction; import com.google.devtools.build.skyframe.SkyFunctionName; @@ -123,7 +124,8 @@ public class WorkspaceFileFunctionTest extends BuildViewTestCase { Path workspacePath = scratch.overwriteFile("WORKSPACE", contents); fakeWorkspaceFileValue.setSize(workspacePath.getFileSize()); return RootedPath.toRootedPath( - workspacePath.getParentDirectory(), PathFragment.create(workspacePath.getBaseName())); + Root.fromPath(workspacePath.getParentDirectory()), + PathFragment.create(workspacePath.getBaseName())); } // Dummy harmcrest matcher that match the function name of a skykey diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java index 63483f5de5..ec173772b6 100644 --- a/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java +++ b/src/test/java/com/google/devtools/build/lib/skyframe/WorkspaceNameFunctionTest.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.skyframe.util.SkyframeExecutorTestUtils; import com.google.devtools.build.lib.vfs.FileSystemUtils; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.EvaluationResult; import com.google.devtools.build.skyframe.SkyKey; import org.junit.Test; @@ -34,10 +35,11 @@ public class WorkspaceNameFunctionTest extends BuildViewTestCase { private final SkyKey key = WorkspaceNameValue.key(); private EvaluationResult<WorkspaceNameValue> eval() throws InterruptedException { - getSkyframeExecutor().invalidateFilesUnderPathForTesting( - reporter, - ModifiedFileSet.builder().modify(PathFragment.create("WORKSPACE")).build(), - rootDirectory); + getSkyframeExecutor() + .invalidateFilesUnderPathForTesting( + reporter, + ModifiedFileSet.builder().modify(PathFragment.create("WORKSPACE")).build(), + Root.fromPath(rootDirectory)); return SkyframeExecutorTestUtils.evaluate( getSkyframeExecutor(), key, /*keepGoing=*/ false, reporter); } diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java index 72f657df91..be3c0ae8a3 100644 --- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java +++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkStringRepresentationsTest.java @@ -20,6 +20,7 @@ import com.google.devtools.build.lib.analysis.ConfiguredTarget; import com.google.devtools.build.lib.skylark.util.SkylarkTestCase; import com.google.devtools.build.lib.vfs.ModifiedFileSet; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -57,7 +58,7 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase { .modify(PathFragment.create("eval/BUILD")) .modify(PathFragment.create("eval/eval.bzl")) .build(), - rootDirectory); + Root.fromPath(rootDirectory)); ConfiguredTarget target = getConfiguredTarget("//eval"); return target.get("result"); @@ -83,7 +84,7 @@ public class SkylarkStringRepresentationsTest extends SkylarkTestCase { .modify(PathFragment.create("eval/BUILD")) .modify(PathFragment.create("eval/eval.bzl")) .build(), - rootDirectory); + Root.fromPath(rootDirectory)); ConfiguredTarget target = getConfiguredTarget("//eval"); return target.get("result"); diff --git a/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java b/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java new file mode 100644 index 0000000000..c007f4b35d --- /dev/null +++ b/src/test/java/com/google/devtools/build/lib/vfs/RootTest.java @@ -0,0 +1,75 @@ +// Copyright 2018 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +package com.google.devtools.build.lib.vfs; + +import static com.google.common.truth.Truth.assertThat; + +import com.google.common.testing.EqualsTester; +import com.google.devtools.build.lib.clock.BlazeClock; +import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec; +import com.google.devtools.build.lib.skyframe.serialization.testutils.ObjectCodecTester; +import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests for {@link RootTest}. */ +@RunWith(JUnit4.class) +public class RootTest { + private FileSystem fs; + + @Before + public final void initializeFileSystem() throws Exception { + fs = new InMemoryFileSystem(BlazeClock.instance()); + } + + @Test + public void testEqualsAndHashCodeContract() throws Exception { + new EqualsTester() + .addEqualityGroup(Root.fromFileSystemRoot(fs), Root.fromFileSystemRoot(fs)) + .addEqualityGroup(Root.fromPath(fs.getPath("/foo")), Root.fromPath(fs.getPath("/foo"))) + .testEquals(); + } + + @Test + public void testPathRoot() throws Exception { + Root root = Root.fromPath(fs.getPath("/foo")); + assertThat(root.asPath()).isEqualTo(fs.getPath("/foo")); + assertThat(root.contains(fs.getPath("/foo/bar"))).isTrue(); + assertThat(root.contains(fs.getPath("/boo/bar"))).isFalse(); + assertThat(root.getRelative(PathFragment.create("bar"))).isEqualTo(fs.getPath("/foo/bar")); + assertThat(root.getRelative("bar")).isEqualTo(fs.getPath("/foo/bar")); + assertThat(root.relativize(fs.getPath("/foo/bar"))).isEqualTo(PathFragment.create("bar")); + } + + @Test + public void testFileSystemRootPath() throws Exception { + Root root = Root.fromFileSystemRoot(fs); + assertThat(root.asPath()).isEqualTo(fs.getPath("/")); + assertThat(root.contains(fs.getPath("/foo"))).isTrue(); + assertThat(root.getRelative(PathFragment.create("foo"))).isEqualTo(fs.getPath("/foo")); + assertThat(root.getRelative("foo")).isEqualTo(fs.getPath("/foo")); + assertThat(root.relativize(fs.getPath("/foo"))).isEqualTo(PathFragment.create("foo")); + } + + @Test + public void testSerialization() throws Exception { + ObjectCodec<Root> codec = Root.getCodec(new PathCodec(fs)); + ObjectCodecTester.newBuilder(codec) + .verificationFunction((a, b) -> a.equals(b)) + .addSubjects(Root.fromFileSystemRoot(fs), Root.fromPath(fs.getPath("/foo"))) + .buildAndRunTests(); + } +} diff --git a/src/test/java/com/google/devtools/build/lib/vfs/RootedPathTest.java b/src/test/java/com/google/devtools/build/lib/vfs/RootedPathTest.java index d84d8b73b1..6f452c2fcb 100644 --- a/src/test/java/com/google/devtools/build/lib/vfs/RootedPathTest.java +++ b/src/test/java/com/google/devtools/build/lib/vfs/RootedPathTest.java @@ -32,21 +32,25 @@ public class RootedPathTest { @Before public final void initializeFileSystem() throws Exception { filesystem = new InMemoryFileSystem(BlazeClock.instance()); - root = filesystem.getRootDirectory(); + root = filesystem.getPath("/"); } @Test public void testEqualsAndHashCodeContract() throws Exception { Path pkgRoot1 = root.getRelative("pkgroot1"); Path pkgRoot2 = root.getRelative("pkgroot2"); - RootedPath rootedPathA1 = RootedPath.toRootedPath(pkgRoot1, PathFragment.create("foo/bar")); - RootedPath rootedPathA2 = RootedPath.toRootedPath(pkgRoot1, PathFragment.create("foo/bar")); + RootedPath rootedPathA1 = + RootedPath.toRootedPath(Root.fromPath(pkgRoot1), PathFragment.create("foo/bar")); + RootedPath rootedPathA2 = + RootedPath.toRootedPath(Root.fromPath(pkgRoot1), PathFragment.create("foo/bar")); RootedPath absolutePath1 = - RootedPath.toRootedPath(root, PathFragment.create("pkgroot1/foo/bar")); - RootedPath rootedPathB1 = RootedPath.toRootedPath(pkgRoot2, PathFragment.create("foo/bar")); - RootedPath rootedPathB2 = RootedPath.toRootedPath(pkgRoot2, PathFragment.create("foo/bar")); + RootedPath.toRootedPath(Root.fromPath(root), PathFragment.create("pkgroot1/foo/bar")); + RootedPath rootedPathB1 = + RootedPath.toRootedPath(Root.fromPath(pkgRoot2), PathFragment.create("foo/bar")); + RootedPath rootedPathB2 = + RootedPath.toRootedPath(Root.fromPath(pkgRoot2), PathFragment.create("foo/bar")); RootedPath absolutePath2 = - RootedPath.toRootedPath(root, PathFragment.create("pkgroot2/foo/bar")); + RootedPath.toRootedPath(Root.fromPath(root), PathFragment.create("pkgroot2/foo/bar")); new EqualsTester() .addEqualityGroup(rootedPathA1, rootedPathA2) .addEqualityGroup(rootedPathB1, rootedPathB2) diff --git a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java index fb3a9aaf2c..47cb2ed470 100644 --- a/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java +++ b/src/test/java/com/google/devtools/build/lib/windows/PathWindowsTest.java @@ -22,6 +22,7 @@ import com.google.devtools.build.lib.vfs.FileSystem; import com.google.devtools.build.lib.vfs.Path; import com.google.devtools.build.lib.vfs.Path.PathFactory; import com.google.devtools.build.lib.vfs.PathFragment; +import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem; import com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath; @@ -282,8 +283,8 @@ public class PathWindowsTest { assertThat(child).isInstanceOf(WindowsPath.class); assertThat(child.startsWith(ancestor)).isTrue(); assertThat(child.relativeTo(ancestor)).isEqualTo(PathFragment.create("baz")); - RootedPath actual = RootedPath.toRootedPath(ancestor, child); - assertThat(actual.getRoot()).isEqualTo(ancestor); + RootedPath actual = RootedPath.toRootedPath(Root.fromPath(ancestor), child); + assertThat(actual.getRoot()).isEqualTo(Root.fromPath(ancestor)); assertThat(actual.getRelativePath()).isEqualTo(PathFragment.create("baz")); } |