Introduce Root class.
This class represents a root (such as a package path or an output root) used for file lookups and artifacts. It is meant to be as opaque as possible in order to hide the user's environment from sky keys and sky functions.
Roots are used by RootedPaths and ArtifactRoots.
This CL attempts to make the minimum number of modifications necessary to change RootedPath and ArtifactRoot to use these fields. Deprecated methods and invasive accessors are permitted to minimise the risk of any observable changes.
RELNOTES: None
PiperOrigin-RevId: 182271759
diff --git a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java
index faa6db0..8e470fa 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/AbstractAction.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.Path;
+import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.lib.vfs.Symlinks;
import com.google.devtools.build.skyframe.SkyFunction;
import java.io.IOException;
@@ -399,13 +400,13 @@
if (output.getRoot() == null) {
throw e;
}
- String outputRootDir = output.getRoot().getPath().getPathString();
- if (!path.getPathString().startsWith(outputRootDir)) {
+ Root outputRoot = output.getRoot().getRoot();
+ if (!outputRoot.contains(path)) {
throw e;
}
Path parentDir = path.getParentDirectory();
- if (!parentDir.isWritable() && parentDir.getPathString().startsWith(outputRootDir)) {
+ if (!parentDir.isWritable() && outputRoot.contains(parentDir)) {
// Retry deleting after making the parent writable.
parentDir.setWritable(true);
deleteOutput(fileSystem, output);
diff --git a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
index a72c77d..82594e7 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/Artifact.java
@@ -190,7 +190,7 @@
*/
@VisibleForTesting
public Artifact(Path path, ArtifactRoot root, PathFragment execPath, ArtifactOwner owner) {
- if (root == null || !path.startsWith(root.getPath())) {
+ if (root == null || !root.getRoot().contains(path)) {
throw new IllegalArgumentException(root + ": illegal root for " + path
+ " (execPath: " + execPath + ")");
}
@@ -209,7 +209,7 @@
// These two lines establish the invariant that
// execPath == rootRelativePath <=> execPath.equals(rootRelativePath)
// This is important for isSourceArtifact.
- PathFragment rootRel = path.relativeTo(root.getPath());
+ PathFragment rootRel = root.getRoot().relativize(path);
if (!execPath.endsWith(rootRel)) {
throw new IllegalArgumentException(execPath + ": illegal execPath doesn't end with "
+ rootRel + " at " + path + " with root " + root);
@@ -245,15 +245,21 @@
*/
@VisibleForTesting // Only exists for testing.
public Artifact(Path path, ArtifactRoot root) {
- this(path, root, root.getExecPath().getRelative(path.relativeTo(root.getPath())),
+ this(
+ path,
+ root,
+ root.getExecPath().getRelative(root.getRoot().relativize(path)),
ArtifactOwner.NULL_OWNER);
}
/** Constructs a source or derived Artifact for the specified root-relative path and root. */
@VisibleForTesting // Only exists for testing.
public Artifact(PathFragment rootRelativePath, ArtifactRoot root) {
- this(root.getPath().getRelative(rootRelativePath), root,
- root.getExecPath().getRelative(rootRelativePath), ArtifactOwner.NULL_OWNER);
+ this(
+ root.getRoot().getRelative(rootRelativePath),
+ root,
+ root.getExecPath().getRelative(rootRelativePath),
+ ArtifactOwner.NULL_OWNER);
}
public final Path getPath() {
@@ -665,7 +671,11 @@
} else {
// Derived Artifact: path and root are under execRoot
PathFragment execRoot = trimTail(path.asFragment(), execPath);
- return "[[" + execRoot + "]" + root.getPath().asFragment().relativeTo(execRoot) + "]"
+ return "[["
+ + execRoot
+ + "]"
+ + root.getRoot().asPath().asFragment().relativeTo(execRoot)
+ + "]"
+ rootRelativePath;
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
index 26d97f7..c6330d0 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactFactory.java
@@ -149,7 +149,7 @@
Preconditions.checkArgument(!execPath.isAbsolute(), "%s %s %s", execPath, root, owner);
Preconditions.checkNotNull(owner, "%s %s", execPath, root);
execPath = execPath.normalize();
- return getArtifact(root.getPath().getRelative(execPath), root, execPath, owner, null);
+ return getArtifact(root.getRoot().getRelative(execPath), root, execPath, owner, null);
}
@Override
@@ -161,10 +161,10 @@
Preconditions.checkArgument(!root.isSourceRoot());
Preconditions.checkArgument(!rootRelativePath.isAbsolute(), rootRelativePath);
Preconditions.checkArgument(rootRelativePath.isNormalized(), rootRelativePath);
- Preconditions.checkArgument(root.getPath().startsWith(execRootParent), "%s %s", root,
- execRootParent);
- Preconditions.checkArgument(!root.getPath().equals(execRootParent), "%s %s", root,
- execRootParent);
+ Preconditions.checkArgument(
+ root.getRoot().asPath().startsWith(execRootParent), "%s %s", root, execRootParent);
+ Preconditions.checkArgument(
+ !root.getRoot().asPath().equals(execRootParent), "%s %s", root, execRootParent);
// TODO(bazel-team): this should only accept roots from derivedRoots.
//Preconditions.checkArgument(derivedRoots.contains(root), "%s not in %s", root, derivedRoots);
}
@@ -180,7 +180,7 @@
public Artifact getDerivedArtifact(
PathFragment rootRelativePath, ArtifactRoot root, ArtifactOwner owner) {
validatePath(rootRelativePath, root);
- Path path = root.getPath().getRelative(rootRelativePath);
+ Path path = root.getRoot().getRelative(rootRelativePath);
return getArtifact(path, root, path.relativeTo(root.getExecRoot()), owner, null);
}
@@ -195,7 +195,7 @@
public Artifact getFilesetArtifact(
PathFragment rootRelativePath, ArtifactRoot root, ArtifactOwner owner) {
validatePath(rootRelativePath, root);
- Path path = root.getPath().getRelative(rootRelativePath);
+ Path path = root.getRoot().getRelative(rootRelativePath);
return getArtifact(
path, root, path.relativeTo(root.getExecRoot()), owner, SpecialArtifactType.FILESET);
}
@@ -210,7 +210,7 @@
public Artifact getTreeArtifact(
PathFragment rootRelativePath, ArtifactRoot root, ArtifactOwner owner) {
validatePath(rootRelativePath, root);
- Path path = root.getPath().getRelative(rootRelativePath);
+ Path path = root.getRoot().getRelative(rootRelativePath);
return getArtifact(
path, root, path.relativeTo(root.getExecRoot()), owner, SpecialArtifactType.TREE);
}
@@ -218,7 +218,7 @@
public Artifact getConstantMetadataArtifact(
PathFragment rootRelativePath, ArtifactRoot root, ArtifactOwner owner) {
validatePath(rootRelativePath, root);
- Path path = root.getPath().getRelative(rootRelativePath);
+ Path path = root.getRoot().getRelative(rootRelativePath);
return getArtifact(
path, root, path.relativeTo(root.getExecRoot()), owner,
SpecialArtifactType.CONSTANT_METADATA);
@@ -395,7 +395,7 @@
ArtifactRoot sourceRoot =
packageRoots.getRootForPackage(PackageIdentifier.create(RepositoryName.MAIN, execPath));
if (sourceRoot != null) {
- return sourceRoot.getPath().getRelative(execPath);
+ return sourceRoot.getRoot().getRelative(execPath);
}
return execRoot.getRelative(execPath);
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
index 47b3c5e..8f2480d 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/ArtifactRoot.java
@@ -24,6 +24,7 @@
import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
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.Serializable;
import java.util.Objects;
import javax.annotation.Nullable;
@@ -56,21 +57,21 @@
// This must always be consistent with Package.getSourceRoot; otherwise computing source roots
// from exec paths does not work, which can break the action cache for input-discovering actions.
- public static ArtifactRoot computeSourceRoot(Path packageRoot, RepositoryName repository) {
+ public static ArtifactRoot computeSourceRoot(Root packageRoot, RepositoryName repository) {
if (repository.isMain()) {
return asSourceRoot(packageRoot);
} else {
- Path actualRoot = packageRoot;
+ Path actualRootPath = packageRoot.asPath();
for (int i = 0; i < repository.getSourceRoot().segmentCount(); i++) {
- actualRoot = actualRoot.getParentDirectory();
+ actualRootPath = actualRootPath.getParentDirectory();
}
- return asSourceRoot(actualRoot);
+ return asSourceRoot(Root.fromPath(actualRootPath));
}
}
/** Returns the given path as a source root. The path may not be {@code null}. */
- public static ArtifactRoot asSourceRoot(Path path) {
- return new ArtifactRoot(null, path);
+ public static ArtifactRoot asSourceRoot(Root path) {
+ return new ArtifactRoot(null, PathFragment.EMPTY_FRAGMENT, path);
}
/**
@@ -83,34 +84,37 @@
public static ArtifactRoot asDerivedRoot(Path execRoot, Path root) {
Preconditions.checkArgument(root.startsWith(execRoot));
Preconditions.checkArgument(!root.equals(execRoot));
- return new ArtifactRoot(execRoot, root);
+ PathFragment execPath = root.relativeTo(execRoot);
+ return new ArtifactRoot(execRoot, execPath, Root.fromPath(root));
}
public static ArtifactRoot middlemanRoot(Path execRoot, Path outputDir) {
Path root = outputDir.getRelative("internal");
Preconditions.checkArgument(root.startsWith(execRoot));
Preconditions.checkArgument(!root.equals(execRoot));
- return new ArtifactRoot(execRoot, root, true);
+ PathFragment execPath = root.relativeTo(execRoot);
+ return new ArtifactRoot(execRoot, execPath, Root.fromPath(root), true);
}
@Nullable private final Path execRoot;
- private final Path path;
+ private final Root root;
private final boolean isMiddlemanRoot;
private final PathFragment execPath;
- private ArtifactRoot(@Nullable Path execRoot, Path path, boolean isMiddlemanRoot) {
+ private ArtifactRoot(
+ @Nullable Path execRoot, PathFragment execPath, Root root, boolean isMiddlemanRoot) {
this.execRoot = execRoot;
- this.path = Preconditions.checkNotNull(path);
+ this.root = Preconditions.checkNotNull(root);
this.isMiddlemanRoot = isMiddlemanRoot;
- this.execPath = isSourceRoot() ? PathFragment.EMPTY_FRAGMENT : path.relativeTo(execRoot);
+ this.execPath = execPath;
}
- private ArtifactRoot(@Nullable Path execRoot, Path path) {
- this(execRoot, path, false);
+ private ArtifactRoot(@Nullable Path execRoot, PathFragment execPath, Root root) {
+ this(execRoot, execPath, root, false);
}
- public Path getPath() {
- return path;
+ public Root getRoot() {
+ return root;
}
/**
@@ -142,12 +146,12 @@
@Override
public int compareTo(ArtifactRoot o) {
- return path.compareTo(o.path);
+ return root.compareTo(o.root);
}
@Override
public int hashCode() {
- return Objects.hash(execRoot, path.hashCode());
+ return Objects.hash(execRoot, root.hashCode());
}
@Override
@@ -159,12 +163,12 @@
return false;
}
ArtifactRoot r = (ArtifactRoot) o;
- return path.equals(r.path) && Objects.equals(execRoot, r.execRoot);
+ return root.equals(r.root) && Objects.equals(execRoot, r.execRoot);
}
@Override
public String toString() {
- return path + (isSourceRoot() ? "[source]" : "[derived]");
+ return root + (isSourceRoot() ? "[source]" : "[derived]");
}
@Override
diff --git a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java
index 3a9e211..75e0da2 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/FilesetTraversalParams.java
@@ -19,8 +19,8 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.cmdline.Label;
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 java.util.Set;
@@ -75,7 +75,7 @@
*
* <p>This is typically the workspace root or some output tree's root (e.g. genfiles, binfiles).
*/
- public abstract Path getRootPart();
+ public abstract Root getRootPart();
/**
* Returns the {@link #getRootPart() root}-relative part of the path.
@@ -96,12 +96,12 @@
static DirectTraversalRoot forPackage(Artifact buildFile) {
return new AutoValue_FilesetTraversalParams_DirectTraversalRoot(
- buildFile.getRoot().getPath(), buildFile.getRootRelativePath().getParentDirectory());
+ buildFile.getRoot().getRoot(), buildFile.getRootRelativePath().getParentDirectory());
}
static DirectTraversalRoot forFileOrDirectory(Artifact fileOrDirectory) {
return new AutoValue_FilesetTraversalParams_DirectTraversalRoot(
- fileOrDirectory.getRoot().getPath(), fileOrDirectory.getRootRelativePath());
+ fileOrDirectory.getRoot().getRoot(), fileOrDirectory.getRootRelativePath());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/actions/PackageRoots.java b/src/main/java/com/google/devtools/build/lib/actions/PackageRoots.java
index 9275e3f..aff9430 100644
--- a/src/main/java/com/google/devtools/build/lib/actions/PackageRoots.java
+++ b/src/main/java/com/google/devtools/build/lib/actions/PackageRoots.java
@@ -17,6 +17,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.Root;
import java.util.Optional;
import javax.annotation.Nullable;
@@ -32,7 +33,7 @@
* this build are present in the map. Should only be needed for planting the symlink forest. If it
* is absent, planting the symlink forest is not necessary.
*/
- Optional<ImmutableMap<PackageIdentifier, Path>> getPackageRootsMap();
+ Optional<ImmutableMap<PackageIdentifier, Root>> getPackageRootsMap();
PackageRootLookup getPackageRootLookup();
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
index de2bd46..506ff64 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/skylark/SkylarkRuleContext.java
@@ -1008,6 +1008,6 @@
public String getBuildFileRelativePath() throws EvalException {
checkMutable("build_file_path");
Package pkg = ruleContext.getRule().getPackage();
- return pkg.getBuildFile().getPath().relativeTo(pkg.getSourceRoot()).getPathString();
+ return pkg.getSourceRoot().relativize(pkg.getBuildFile().getPath()).getPathString();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
index c0c522d..566e52b 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/MavenServerFunction.java
@@ -30,6 +30,7 @@
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.SkyFunction;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -102,9 +103,10 @@
} else {
PathFragment settingsFilePath =
PathFragment.create(mapper.get("settings_file", Type.STRING));
- RootedPath settingsPath = RootedPath.toRootedPath(
- directories.getWorkspace().getRelative(settingsFilePath),
- PathFragment.EMPTY_FRAGMENT);
+ RootedPath settingsPath =
+ RootedPath.toRootedPath(
+ Root.fromPath(directories.getWorkspace().getRelative(settingsFilePath)),
+ PathFragment.EMPTY_FRAGMENT);
FileValue fileValue = (FileValue) env.getValue(FileValue.key(settingsPath));
if (fileValue == null) {
return null;
@@ -187,9 +189,11 @@
if (m2Home != null) {
PathFragment mavenInstallSettings =
PathFragment.create(m2Home).getRelative("conf/settings.xml");
- systemKey = FileValue.key(
- RootedPath.toRootedPath(directories.getWorkspace().getRelative(mavenInstallSettings),
- PathFragment.EMPTY_FRAGMENT));
+ systemKey =
+ FileValue.key(
+ RootedPath.toRootedPath(
+ Root.fromPath(directories.getWorkspace().getRelative(mavenInstallSettings)),
+ PathFragment.EMPTY_FRAGMENT));
settingsFilesBuilder.add(systemKey);
}
@@ -198,9 +202,11 @@
SkyKey userKey = null;
if (userHome != null) {
PathFragment userSettings = PathFragment.create(userHome).getRelative(".m2/settings.xml");
- userKey = FileValue.key(RootedPath.toRootedPath(
- directories.getWorkspace().getRelative(userSettings),
- PathFragment.EMPTY_FRAGMENT));
+ userKey =
+ FileValue.key(
+ RootedPath.toRootedPath(
+ Root.fromPath(directories.getWorkspace().getRelative(userSettings)),
+ PathFragment.EMPTY_FRAGMENT));
settingsFilesBuilder.add(userKey);
}
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
index 26b63c7..1e4e9b4 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidNdkRepositoryFunction.java
@@ -39,6 +39,7 @@
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.view.config.crosstool.CrosstoolConfig.CToolchain;
import com.google.devtools.build.lib.view.config.crosstool.CrosstoolConfig.CrosstoolRelease;
@@ -358,7 +359,8 @@
releaseFilePath = directory.getRelative("RELEASE.TXT");
}
- SkyKey releaseFileKey = FileValue.key(RootedPath.toRootedPath(directory, releaseFilePath));
+ SkyKey releaseFileKey =
+ FileValue.key(RootedPath.toRootedPath(Root.fromPath(directory), releaseFilePath));
String releaseFileContent = "";
try {
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryFunction.java
index 846653a..ccf3d53 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidRepositoryFunction.java
@@ -22,6 +22,7 @@
import com.google.devtools.build.lib.vfs.Dirent;
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.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -49,7 +50,7 @@
*/
final DirectoryListingValue getDirectoryListing(Path root, PathFragment dirPath, Environment env)
throws RepositoryFunctionException, InterruptedException {
- RootedPath rootedPath = RootedPath.toRootedPath(root, dirPath);
+ RootedPath rootedPath = RootedPath.toRootedPath(Root.fromPath(root), dirPath);
try {
FileValue dirFileValue =
(FileValue) env.getValueOrThrow(FileValue.key(rootedPath), IOException.class);
@@ -66,7 +67,7 @@
}
return (DirectoryListingValue)
env.getValueOrThrow(
- DirectoryListingValue.key(RootedPath.toRootedPath(root, dirPath)),
+ DirectoryListingValue.key(RootedPath.toRootedPath(Root.fromPath(root), dirPath)),
InconsistentFilesystemException.class);
} catch (IOException e) {
throw new RepositoryFunctionException(e, Transience.PERSISTENT);
diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
index e888f73..b7f1dbe 100644
--- a/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/android/AndroidSdkRepositoryFunction.java
@@ -38,6 +38,7 @@
import com.google.devtools.build.lib.vfs.FileSystem;
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.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -303,8 +304,8 @@
Path sourcePropertiesFilePath = directory.getRelative(
"build-tools/" + buildToolsDirectory + "/source.properties");
- SkyKey releaseFileKey = FileValue.key(
- RootedPath.toRootedPath(directory, sourcePropertiesFilePath));
+ SkyKey releaseFileKey =
+ FileValue.key(RootedPath.toRootedPath(Root.fromPath(directory), sourcePropertiesFilePath));
try {
env.getValueOrThrow(releaseFileKey, IOException.class);
@@ -401,7 +402,8 @@
input ->
DirectoryListingValue.key(
RootedPath.toRootedPath(
- root, root.getRelative(path).getRelative(input.getName())))));
+ Root.fromPath(root),
+ root.getRelative(path).getRelative(input.getName())))));
Map<SkyKey, ValueOrException<InconsistentFilesystemException>> values =
env.getValuesOrThrow(
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
index ea4c801..2b607d8 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/ExecutionTool.java
@@ -96,6 +96,7 @@
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.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
@@ -518,7 +519,7 @@
}
private void prepare(PackageRoots packageRoots) throws ExecutorInitException {
- Optional<ImmutableMap<PackageIdentifier, Path>> packageRootMap =
+ Optional<ImmutableMap<PackageIdentifier, Root>> packageRootMap =
packageRoots.getPackageRootsMap();
if (!packageRootMap.isPresent()) {
return;
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
index 5c16e79..2cfd532 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/OutputDirectoryLinksUtils.java
@@ -26,6 +26,7 @@
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -98,7 +99,8 @@
Set<Path> binPaths =
targetConfigs
.stream()
- .map(targetConfig -> targetConfig.getBinDirectory(repositoryName).getPath())
+ .map(targetConfig -> targetConfig.getBinDirectory(repositoryName).getRoot())
+ .map(Root::asPath)
.distinct()
.collect(toImmutableSet());
if (binPaths.size() == 1) {
@@ -109,7 +111,8 @@
Set<Path> testLogsPaths =
targetConfigs
.stream()
- .map(targetConfig -> targetConfig.getTestLogsDirectory(repositoryName).getPath())
+ .map(targetConfig -> targetConfig.getTestLogsDirectory(repositoryName).getRoot())
+ .map(Root::asPath)
.distinct()
.collect(toImmutableSet());
if (testLogsPaths.size() == 1) {
@@ -124,7 +127,8 @@
Set<Path> genfilesPaths =
targetConfigs
.stream()
- .map(targetConfig -> targetConfig.getGenfilesDirectory(repositoryName).getPath())
+ .map(targetConfig -> targetConfig.getGenfilesDirectory(repositoryName).getRoot())
+ .map(Root::asPath)
.distinct()
.collect(toImmutableSet());
if (genfilesPaths.size() == 1) {
diff --git a/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java b/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java
index 948090c..4b4f7cc 100644
--- a/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java
+++ b/src/main/java/com/google/devtools/build/lib/buildtool/SymlinkForest.java
@@ -26,6 +26,7 @@
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 java.io.IOException;
import java.util.Map;
import java.util.Set;
@@ -40,14 +41,16 @@
private static final Logger logger = Logger.getLogger(SymlinkForest.class.getName());
private static final boolean LOG_FINER = logger.isLoggable(Level.FINER);
- private final ImmutableMap<PackageIdentifier, Path> packageRoots;
+ private final ImmutableMap<PackageIdentifier, Root> packageRoots;
private final Path execroot;
private final String workspaceName;
private final String productName;
private final String[] prefixes;
SymlinkForest(
- ImmutableMap<PackageIdentifier, Path> packageRoots, Path execroot, String productName,
+ ImmutableMap<PackageIdentifier, Root> packageRoots,
+ Path execroot,
+ String productName,
String workspaceName) {
this.packageRoots = packageRoots;
this.execroot = execroot;
@@ -112,22 +115,22 @@
// Create a sorted map of all dirs (packages and their ancestors) to sets of their roots.
// Packages come from exactly one root, but their shared ancestors may come from more.
// The map is maintained sorted lexicographically, so parents are before their children.
- Map<PackageIdentifier, Set<Path>> dirRootsMap = Maps.newTreeMap();
- for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) {
+ Map<PackageIdentifier, Set<Root>> dirRootsMap = Maps.newTreeMap();
+ for (Map.Entry<PackageIdentifier, Root> entry : packageRoots.entrySet()) {
PackageIdentifier pkgId = entry.getKey();
- Path pkgRoot = entry.getValue();
+ Root pkgRoot = entry.getValue();
for (int i = 1; i <= pkgId.getPackageFragment().segmentCount(); i++) {
if (pkgId.equals(Label.EXTERNAL_PACKAGE_IDENTIFIER)) {
// This isn't a "real" package, don't add it to the symlink tree.
continue;
}
PackageIdentifier dir = createInRepo(pkgId, pkgId.getPackageFragment().subFragment(0, i));
- Set<Path> roots = dirRootsMap.computeIfAbsent(dir, k -> Sets.newHashSet());
+ Set<Root> roots = dirRootsMap.computeIfAbsent(dir, k -> Sets.newHashSet());
roots.add(pkgRoot);
}
}
// Now add in roots for all non-pkg dirs that are in between two packages, and missed above.
- for (Map.Entry<PackageIdentifier, Set<Path>> entry : dirRootsMap.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Set<Root>> entry : dirRootsMap.entrySet()) {
PackageIdentifier dir = entry.getKey();
if (!packageRoots.containsKey(dir)) {
PackageIdentifier pkgId = longestPathPrefix(dir, packageRoots.keySet());
@@ -137,7 +140,7 @@
}
}
// Create output dirs for all dirs that have more than one root and need to be split.
- for (Map.Entry<PackageIdentifier, Set<Path>> entry : dirRootsMap.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Set<Root>> entry : dirRootsMap.entrySet()) {
PackageIdentifier dir = entry.getKey();
if (!dir.getRepository().isMain()) {
FileSystemUtils.createDirectoryAndParents(
@@ -153,9 +156,9 @@
}
// Make dir links for single rooted dirs.
- for (Map.Entry<PackageIdentifier, Set<Path>> entry : dirRootsMap.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Set<Root>> entry : dirRootsMap.entrySet()) {
PackageIdentifier dir = entry.getKey();
- Set<Path> roots = entry.getValue();
+ Set<Root> roots = entry.getValue();
// Simple case of one root for this dir.
if (roots.size() == 1) {
if (dir.getPackageFragment().segmentCount() > 1
@@ -163,7 +166,7 @@
continue; // skip--an ancestor will link this one in from above
}
// This is the top-most dir that can be linked to a single root. Make it so.
- Path root = roots.iterator().next(); // lone root in set
+ Root root = roots.iterator().next(); // lone root in set
if (LOG_FINER) {
logger.finer(
"ln -s "
@@ -176,13 +179,13 @@
}
}
// Make links for dirs within packages, skip parent-only dirs.
- for (Map.Entry<PackageIdentifier, Set<Path>> entry : dirRootsMap.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Set<Root>> entry : dirRootsMap.entrySet()) {
PackageIdentifier dir = entry.getKey();
if (entry.getValue().size() > 1) {
// If this dir is at or below a package dir, link in its contents.
PackageIdentifier pkgId = longestPathPrefix(dir, packageRoots.keySet());
if (pkgId != null) {
- Path root = packageRoots.get(pkgId);
+ Root root = packageRoots.get(pkgId);
try {
Path absdir = root.getRelative(dir.getSourceRoot());
if (absdir.isDirectory()) {
@@ -191,7 +194,7 @@
"ln -s " + absdir + "/* " + execroot.getRelative(dir.getSourceRoot()) + "/");
}
for (Path target : absdir.getDirectoryEntries()) {
- PathFragment p = target.relativeTo(root);
+ PathFragment p = root.relativize(target);
if (!dirRootsMap.containsKey(createInRepo(pkgId, p))) {
//LOG.finest("ln -s " + target + " " + linkRoot.getRelative(p));
execroot.getRelative(p).createSymbolicLink(target);
@@ -208,7 +211,7 @@
}
}
- for (Map.Entry<PackageIdentifier, Path> entry : packageRoots.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Root> entry : packageRoots.entrySet()) {
PackageIdentifier pkgId = entry.getKey();
if (!pkgId.getPackageFragment().equals(PathFragment.EMPTY_FRAGMENT)) {
continue;
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java
index 9f1daa7..ca12997 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/Package.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java
@@ -42,6 +42,7 @@
import com.google.devtools.build.lib.vfs.Canonicalizer;
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.protobuf.CodedInputStream;
import com.google.protobuf.CodedOutputStream;
import java.io.IOException;
@@ -112,10 +113,10 @@
protected String workspaceName;
/**
- * The root of the source tree in which this package was found. It is an invariant that
- * {@code sourceRoot.getRelative(packageId.getSourceRoot()).equals(packageDirectory)}.
+ * The root of the source tree in which this package was found. It is an invariant that {@code
+ * sourceRoot.getRelative(packageId.getSourceRoot()).equals(packageDirectory)}.
*/
- private Path sourceRoot;
+ private Root sourceRoot;
/**
* The "Make" environment of this package, containing package-local
@@ -273,22 +274,22 @@
/**
* Returns the source root (a directory) beneath which this package's BUILD file was found.
*
- * <p> Assumes invariant:
- * {@code getSourceRoot().getRelative(packageId.getSourceRoot()).equals(getPackageDirectory())}
+ * <p>Assumes invariant: {@code
+ * getSourceRoot().getRelative(packageId.getSourceRoot()).equals(getPackageDirectory())}
*/
- public Path getSourceRoot() {
+ public Root getSourceRoot() {
return sourceRoot;
}
// This must always be consistent with Root.computeSourceRoot; otherwise computing source roots
// from exec paths does not work, which can break the action cache for input-discovering actions.
- private static Path getSourceRoot(Path buildFile, PathFragment packageFragment) {
+ private static Root getSourceRoot(Path buildFile, PathFragment packageFragment) {
Path current = buildFile.getParentDirectory();
for (int i = 0, len = packageFragment.segmentCount();
i < len && !packageFragment.equals(PathFragment.EMPTY_FRAGMENT); i++) {
current = current.getParentDirectory();
}
- return current;
+ return Root.fromPath(current);
}
/**
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
index 3939751..af09f1a 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/LoadingPhaseRunner.java
@@ -24,8 +24,8 @@
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.syntax.Type;
-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.Collection;
import java.util.List;
import javax.annotation.Nullable;
@@ -57,13 +57,11 @@
@Nullable LoadingCallback callback)
throws TargetParsingException, LoadingFailedException, InterruptedException;
- /**
- * Returns a map of collected package names to root paths.
- */
- public static ImmutableMap<PackageIdentifier, Path> collectPackageRoots(
+ /** Returns a map of collected package names to root paths. */
+ public static ImmutableMap<PackageIdentifier, Root> collectPackageRoots(
Collection<Package> packages) {
// Make a map of the package names to their root paths.
- ImmutableMap.Builder<PackageIdentifier, Path> packageRoots = ImmutableMap.builder();
+ ImmutableMap.Builder<PackageIdentifier, Root> packageRoots = ImmutableMap.builder();
for (Package pkg : packages) {
packageRoots.put(pkg.getPackageIdentifier(), pkg.getSourceRoot());
}
diff --git a/src/main/java/com/google/devtools/build/lib/pkgcache/PathPackageLocator.java b/src/main/java/com/google/devtools/build/lib/pkgcache/PathPackageLocator.java
index 94694c1..b0c780b 100644
--- a/src/main/java/com/google/devtools/build/lib/pkgcache/PathPackageLocator.java
+++ b/src/main/java/com/google/devtools/build/lib/pkgcache/PathPackageLocator.java
@@ -27,6 +27,7 @@
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.Symlinks;
import com.google.devtools.build.lib.vfs.UnixGlob;
import java.io.IOException;
@@ -47,7 +48,7 @@
public class PathPackageLocator implements Serializable {
private static final String WORKSPACE_WILDCARD = "%workspace%";
- private final ImmutableList<Path> pathEntries;
+ private final ImmutableList<Root> pathEntries;
// Transient because this is an injected value in Skyframe, and as such, its serialized
// representation is used as a key. We want a change to output base not to invalidate things.
private final transient Path outputBase;
@@ -56,7 +57,7 @@
@VisibleForTesting
public PathPackageLocator(
- Path outputBase, List<Path> pathEntries, List<BuildFileName> buildFilesByPriority) {
+ Path outputBase, List<Root> pathEntries, List<BuildFileName> buildFilesByPriority) {
this.outputBase = outputBase;
this.pathEntries = ImmutableList.copyOf(pathEntries);
this.buildFilesByPriority = ImmutableList.copyOf(buildFilesByPriority);
@@ -133,11 +134,8 @@
return null;
}
-
- /**
- * Returns an immutable ordered list of the directories on the package path.
- */
- public ImmutableList<Path> getPathEntries() {
+ /** Returns an immutable ordered list of the directories on the package path. */
+ public ImmutableList<Root> getPathEntries() {
return pathEntries;
}
@@ -187,38 +185,18 @@
}
/**
- * A factory of PathPackageLocators from a list of path elements. Elements may contain
- * "%workspace%", indicating the workspace.
+ * A factory of PathPackageLocators from a list of path elements.
*
* @param outputBase the output base. Can be null if remote repositories are not in use.
- * @param pathElements Each element must be an absolute path, relative path, or some string
- * "%workspace%" + relative, where relative is itself a relative path. The special symbol
- * "%workspace%" means to interpret the path relative to the nearest enclosing workspace.
- * Relative paths are interpreted relative to the client's working directory, which may be
- * below the workspace.
- * @param eventHandler The eventHandler.
- * @param workspace The nearest enclosing package root directory.
- * @param clientWorkingDirectory The client's working directory.
+ * @param pathElements Each element must be a {@link Root} object.
* @param buildFilesByPriority The ordered collection of {@link BuildFileName}s to check in each
* potential package directory.
* @return a {@link PathPackageLocator} that uses the {@code outputBase} and {@code pathElements}
* provided.
*/
public static PathPackageLocator createWithoutExistenceCheck(
- Path outputBase,
- List<String> pathElements,
- EventHandler eventHandler,
- Path workspace,
- Path clientWorkingDirectory,
- List<BuildFileName> buildFilesByPriority) {
- return createInternal(
- outputBase,
- pathElements,
- eventHandler,
- workspace,
- clientWorkingDirectory,
- buildFilesByPriority,
- false);
+ Path outputBase, List<Root> pathElements, List<BuildFileName> buildFilesByPriority) {
+ return new PathPackageLocator(outputBase, pathElements, buildFilesByPriority);
}
private static PathPackageLocator createInternal(
@@ -229,7 +207,7 @@
Path clientWorkingDirectory,
List<BuildFileName> buildFilesByPriority,
boolean checkExistence) {
- List<Path> resolvedPaths = new ArrayList<>();
+ List<Root> resolvedPaths = new ArrayList<>();
for (String pathElement : pathElements) {
// Replace "%workspace%" with the path of the enclosing workspace directory.
@@ -254,7 +232,7 @@
}
if (!checkExistence || rootPath.exists()) {
- resolvedPaths.add(rootPath);
+ resolvedPaths.add(Root.fromPath(rootPath));
}
}
@@ -276,7 +254,7 @@
private Path getFilePath(PathFragment suffix,
AtomicReference<? extends UnixGlob.FilesystemCalls> cache) {
- for (Path pathEntry : pathEntries) {
+ for (Root pathEntry : pathEntries) {
Path buildFile = pathEntry.getRelative(suffix);
try {
FileStatus stat = cache.get().statIfFound(buildFile, Symlinks.FOLLOW);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java
index a459e42..ad05f41 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcIncLibrary.java
@@ -93,7 +93,7 @@
.getRelative(packageFragment)
.getRelative(includeDirectory);
Path includeRoot =
- configIncludeDirectory.getPath().getRelative(packageFragment).getRelative(includeDirectory);
+ configIncludeDirectory.getRoot().getRelative(packageFragment).getRelative(includeDirectory);
// For every source artifact, we compute a virtual artifact that is below the include directory.
// These are used for include checking.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
index 8f2a0c6..7bede6c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppCompileAction.java
@@ -64,6 +64,7 @@
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.SkyFunction;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -904,16 +905,16 @@
}
}
// Still not found: see if it is in a subdir of a declared package.
- Path root = input.getRoot().getPath();
+ Root root = input.getRoot().getRoot();
for (Path dir = input.getPath().getParentDirectory();;) {
if (dir.getRelative(BUILD_PATH_FRAGMENT).exists()) {
return false; // Bad: this is a sub-package, not a subdir of a declared package.
}
dir = dir.getParentDirectory();
- if (dir.equals(root)) {
+ if (dir.equals(root.asPath())) {
return false; // Bad: at the top, give up.
}
- if (declaredIncludeDirs.contains(dir.relativeTo(root))) {
+ if (declaredIncludeDirs.contains(root.relativize(dir))) {
return true; // OK: found under a declared dir.
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
index 8edc2d9..40d8030 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
@@ -38,6 +38,7 @@
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.view.config.crosstool.CrosstoolConfig.LipoMode;
import com.google.devtools.build.skyframe.SkyFunction;
@@ -304,8 +305,10 @@
PrecomputedValue.dependOnBuildId(env);
} else {
Path path = fdoMode == FdoMode.AUTO_FDO ? getAutoFdoImportsPath(fdoProfile) : fdoProfile;
- env.getValue(FileValue.key(RootedPath.toRootedPathMaybeUnderRoot(path,
- ImmutableList.of(execRoot))));
+ env.getValue(
+ FileValue.key(
+ RootedPath.toRootedPathMaybeUnderRoot(
+ path, ImmutableList.of(Root.fromPath(execRoot)))));
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java
index b07f75e..6ad546c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/IncludeScanner.java
@@ -155,7 +155,7 @@
for (Artifact included : includes) {
// Check for absolute includes -- we assign the file system root as
// the root path for such includes
- if (included.getRoot().getPath().isRootDirectory()) {
+ if (included.getRoot().getRoot().isRootDirectory()) {
if (FileSystemUtils.startsWithAny(
included.getPath().asFragment(), absoluteBuiltInIncludeDirs)) {
// Skip include files found in absolute include directories.
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
index 9811287..9021546 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewLocalRepositoryFunction.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.vfs.FileSystem;
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.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException;
@@ -56,7 +57,7 @@
FileSystem fs = directories.getOutputBase().getFileSystem();
Path path = fs.getPath(pathFragment);
- RootedPath dirPath = RootedPath.toRootedPath(fs.getRootDirectory(), path);
+ RootedPath dirPath = RootedPath.toRootedPath(Root.fromFileSystemRoot(fs), path);
try {
FileValue dirFileValue =
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/NewRepositoryFileHandler.java b/src/main/java/com/google/devtools/build/lib/rules/repository/NewRepositoryFileHandler.java
index 7d93da6f..14efd5e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/NewRepositoryFileHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/NewRepositoryFileHandler.java
@@ -25,6 +25,7 @@
import com.google.devtools.build.lib.syntax.Type;
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.Environment;
import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
@@ -216,7 +217,7 @@
}
// And now for the file
- Path packageRoot = pkgLookupValue.getRoot();
+ Root packageRoot = pkgLookupValue.getRoot();
rootedFile = RootedPath.toRootedPath(packageRoot, label.toPathFragment());
} else {
// TODO(dmarting): deprecate using a path for the workspace_file attribute.
@@ -236,9 +237,10 @@
if (file.isAbsolute()) {
rootedFile =
RootedPath.toRootedPath(
- fileTarget.getParentDirectory(), PathFragment.create(fileTarget.getBaseName()));
+ Root.fromPath(fileTarget.getParentDirectory()),
+ PathFragment.create(fileTarget.getBaseName()));
} else {
- rootedFile = RootedPath.toRootedPath(workspacePath, file);
+ rootedFile = RootedPath.toRootedPath(Root.fromPath(workspacePath), file);
}
}
SkyKey fileKey = FileValue.key(rootedFile);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
index 0cf44e6..024287d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryFunction.java
@@ -42,6 +42,7 @@
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.Symlinks;
import com.google.devtools.build.skyframe.SkyFunction.Environment;
@@ -212,7 +213,7 @@
Path file = rule.getPackage().getPackageDirectory().getRelative(filePathFragment);
rootedPath =
RootedPath.toRootedPath(
- file.getParentDirectory(), PathFragment.create(file.getBaseName()));
+ Root.fromPath(file.getParentDirectory()), PathFragment.create(file.getBaseName()));
}
SkyKey fileSkyKey = FileValue.key(rootedPath);
@@ -281,7 +282,7 @@
}
// And now for the file
- Path packageRoot = pkgLookupValue.getRoot();
+ Root packageRoot = pkgLookupValue.getRoot();
return RootedPath.toRootedPath(packageRoot, label.toPathFragment());
}
@@ -473,8 +474,10 @@
@Nullable
protected static FileValue getRepositoryDirectory(Path repositoryDirectory, Environment env)
throws RepositoryFunctionException, InterruptedException {
- SkyKey outputDirectoryKey = FileValue.key(RootedPath.toRootedPath(
- repositoryDirectory, PathFragment.EMPTY_FRAGMENT));
+ SkyKey outputDirectoryKey =
+ FileValue.key(
+ RootedPath.toRootedPath(
+ Root.fromPath(repositoryDirectory), PathFragment.EMPTY_FRAGMENT));
FileValue value;
try {
value = (FileValue) env.getValueOrThrow(outputDirectoryKey, IOException.class);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java
index ad0e5ab..f2cda7a 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryLoaderFunction.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.skyframe.WorkspaceFileValue;
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;
@@ -54,7 +55,8 @@
SkyKey workspaceKey =
WorkspaceFileValue.key(
- RootedPath.toRootedPath(repository.getPath(), PathFragment.create("WORKSPACE")));
+ RootedPath.toRootedPath(
+ Root.fromPath(repository.getPath()), PathFragment.create("WORKSPACE")));
WorkspaceFileValue workspacePackage = (WorkspaceFileValue) env.getValue(workspaceKey);
if (workspacePackage == null) {
return null;
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/ProjectFile.java b/src/main/java/com/google/devtools/build/lib/runtime/ProjectFile.java
index 59c0a23..30760ec 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/ProjectFile.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/ProjectFile.java
@@ -16,6 +16,7 @@
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.OptionsParsingException;
import java.util.List;
@@ -38,7 +39,7 @@
* Returns an (optionally cached) project file instance. If there is no such file, or if the
* file cannot be parsed, then it throws an exception.
*/
- ProjectFile getProjectFile(Path workingDirectory, List<Path> packagePath, PathFragment path)
+ ProjectFile getProjectFile(Path workingDirectory, List<Root> packagePath, PathFragment path)
throws OptionsParsingException;
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java
index 0badadd..7d5e05f 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/InfoItem.java
@@ -224,7 +224,7 @@
public byte[] get(Supplier<BuildConfiguration> configurationSupplier, CommandEnvironment env)
throws AbruptExitException {
checkNotNull(configurationSupplier);
- return print(configurationSupplier.get().getBinDirectory(RepositoryName.MAIN).getPath());
+ return print(configurationSupplier.get().getBinDirectory(RepositoryName.MAIN).getRoot());
}
}
@@ -245,8 +245,7 @@
public byte[] get(Supplier<BuildConfiguration> configurationSupplier, CommandEnvironment env)
throws AbruptExitException {
checkNotNull(configurationSupplier);
- return print(
- configurationSupplier.get().getGenfilesDirectory(RepositoryName.MAIN).getPath());
+ return print(configurationSupplier.get().getGenfilesDirectory(RepositoryName.MAIN).getRoot());
}
}
@@ -267,8 +266,7 @@
public byte[] get(Supplier<BuildConfiguration> configurationSupplier, CommandEnvironment env)
throws AbruptExitException {
checkNotNull(configurationSupplier);
- return print(
- configurationSupplier.get().getTestLogsDirectory(RepositoryName.MAIN).getPath());
+ return print(configurationSupplier.get().getTestLogsDirectory(RepositoryName.MAIN).getRoot());
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java
index ffb8164..a14ff5a 100644
--- a/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/runtime/commands/ProjectFileSupport.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.skyframe.BazelSkyframeExecutorConstants;
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.OptionPriority.PriorityCategory;
import com.google.devtools.common.options.OptionsParser;
import com.google.devtools.common.options.OptionsParsingException;
@@ -60,7 +61,7 @@
// cwd is a subdirectory of the workspace, that will be surprising, and we should interpret it
// relative to the cwd instead.
PathFragment projectFilePath = PathFragment.create(targets.get(0).substring(1));
- List<Path> packagePath =
+ List<Root> packagePath =
PathPackageLocator.create(
// We only need a non-null outputBase for the PathPackageLocator if we support
// external
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
index 2fcbfbe..b1f816d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ASTFileLookupFunction.java
@@ -24,6 +24,7 @@
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;
@@ -79,7 +80,7 @@
//
// Determine whether the file designated by fileLabel exists.
//
- Path packageRoot = pkgLookupValue.getRoot();
+ Root packageRoot = pkgLookupValue.getRoot();
RootedPath rootedPath = RootedPath.toRootedPath(packageRoot, filePathFragment);
SkyKey fileSkyKey = FileValue.key(rootedPath);
FileValue fileValue = null;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
index d060835..bf635c9 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionMetadataHandler.java
@@ -554,7 +554,7 @@
throws IOException {
Path path = artifact.getPath();
RootedPath rootedPath =
- RootedPath.toRootedPath(artifact.getRoot().getPath(), artifact.getRootRelativePath());
+ RootedPath.toRootedPath(artifact.getRoot().getRoot(), artifact.getRootRelativePath());
if (statNoFollow == null) {
statNoFollow = FileStatusWithDigestAdapter.adapt(path.statIfFound(Symlinks.NOFOLLOW));
if (statNoFollow == null) {
@@ -573,8 +573,9 @@
throw new IOException("symlink cycle");
}
}
- RootedPath realRootedPath = RootedPath.toRootedPathMaybeUnderRoot(realPath,
- ImmutableList.of(artifact.getRoot().getPath()));
+ RootedPath realRootedPath =
+ RootedPath.toRootedPathMaybeUnderRoot(
+ realPath, ImmutableList.of(artifact.getRoot().getRoot()));
FileStateValue fileStateValue =
FileStateValue.createWithStatNoFollow(rootedPath, statNoFollow, tsgm);
// TODO(bazel-team): consider avoiding a 'stat' here when the symlink target hasn't changed
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
index e607b19..627184d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ArtifactFunction.java
@@ -214,8 +214,8 @@
private FileArtifactValue createSourceValue(Artifact artifact, boolean mandatory, Environment env)
throws MissingInputFileException, InterruptedException {
- SkyKey fileSkyKey = FileValue.key(RootedPath.toRootedPath(artifact.getRoot().getPath(),
- artifact.getPath()));
+ SkyKey fileSkyKey =
+ FileValue.key(RootedPath.toRootedPath(artifact.getRoot().getRoot(), artifact.getPath()));
FileValue fileValue;
try {
fileValue = (FileValue) env.getValueOrThrow(fileSkyKey, IOException.class);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
index 713022c..8d96dd3 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/BlacklistedPackagePrefixesFunction.java
@@ -17,8 +17,8 @@
import com.google.common.io.CharStreams;
import com.google.common.io.LineProcessor;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
-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;
@@ -58,7 +58,7 @@
return null;
}
- for (Path packagePathEntry : pkgLocator.getPathEntries()) {
+ for (Root packagePathEntry : pkgLocator.getPathEntries()) {
RootedPath rootedPatternFile =
RootedPath.toRootedPath(packagePathEntry, additionalBlacklistedPackagePrefixesFile);
FileValue patternFileValue = (FileValue) env.getValue(FileValue.key(rootedPatternFile));
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
index e2edd9d..491275c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ContainingPackageLookupValue.java
@@ -15,7 +15,7 @@
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.Root;
import com.google.devtools.build.skyframe.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -36,7 +36,7 @@
public abstract PackageIdentifier getContainingPackageName();
/** If there is a containing package, returns its package root */
- public abstract Path getContainingPackageRoot();
+ public abstract Root getContainingPackageRoot();
public static SkyKey key(PackageIdentifier id) {
Preconditions.checkArgument(!id.getPackageFragment().isAbsolute(), id);
@@ -44,7 +44,7 @@
return LegacySkyKey.create(SkyFunctions.CONTAINING_PACKAGE_LOOKUP, id);
}
- public static ContainingPackage withContainingPackage(PackageIdentifier pkgId, Path root) {
+ public static ContainingPackage withContainingPackage(PackageIdentifier pkgId, Root root) {
return new ContainingPackage(pkgId, root);
}
@@ -64,7 +64,7 @@
}
@Override
- public Path getContainingPackageRoot() {
+ public Root getContainingPackageRoot() {
throw new IllegalStateException();
}
}
@@ -72,9 +72,9 @@
/** A successful lookup value. */
public static class ContainingPackage extends ContainingPackageLookupValue {
private final PackageIdentifier containingPackage;
- private final Path containingPackageRoot;
+ private final Root containingPackageRoot;
- private ContainingPackage(PackageIdentifier pkgId, Path containingPackageRoot) {
+ private ContainingPackage(PackageIdentifier pkgId, Root containingPackageRoot) {
this.containingPackage = pkgId;
this.containingPackageRoot = containingPackageRoot;
}
@@ -90,7 +90,7 @@
}
@Override
- public Path getContainingPackageRoot() {
+ public Root getContainingPackageRoot() {
return containingPackageRoot;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwareness.java b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwareness.java
index 64c9033..507a49f 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwareness.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwareness.java
@@ -14,7 +14,7 @@
package com.google.devtools.build.lib.skyframe;
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.OptionsClassProvider;
import java.io.Closeable;
import javax.annotation.Nullable;
@@ -36,11 +36,11 @@
* Returns a {@link DiffAwareness} instance suitable for managing changes to files under the
* given package path entry, or {@code null} if this factory cannot create such an instance.
*
- * <p> Skyframe has a collection of factories, and will create a {@link DiffAwareness} instance
+ * <p>Skyframe has a collection of factories, and will create a {@link DiffAwareness} instance
* per package path entry using one of the factories that returns a non-null value.
*/
@Nullable
- DiffAwareness maybeCreate(Path pathEntry);
+ DiffAwareness maybeCreate(Root pathEntry);
}
/** Opaque view of the filesystem under a package path entry at a specific point in time. */
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java
index 8c9ffb7..7bd831b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DiffAwarenessManager.java
@@ -19,7 +19,7 @@
import com.google.devtools.build.lib.events.EventHandler;
import com.google.devtools.build.lib.skyframe.DiffAwareness.View;
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.OptionsClassProvider;
import java.util.Map;
import java.util.logging.Logger;
@@ -36,7 +36,7 @@
// The manager attempts to instantiate these in the order in which they are passed to the
// constructor; this is critical in the case where a factory always succeeds.
private final ImmutableList<? extends DiffAwareness.Factory> diffAwarenessFactories;
- private Map<Path, DiffAwarenessState> currentDiffAwarenessStates = Maps.newHashMap();
+ private Map<Root, DiffAwarenessState> currentDiffAwarenessStates = Maps.newHashMap();
public DiffAwarenessManager(Iterable<? extends DiffAwareness.Factory> diffAwarenessFactories) {
this.diffAwarenessFactories = ImmutableList.copyOf(diffAwarenessFactories);
@@ -77,11 +77,11 @@
}
/**
- * Gets the set of changed files since the last call with this path entry, or
- * {@code ModifiedFileSet.EVERYTHING_MODIFIED} if this is the first such call.
+ * Gets the set of changed files since the last call with this path entry, or {@code
+ * ModifiedFileSet.EVERYTHING_MODIFIED} if this is the first such call.
*/
public ProcessableModifiedFileSet getDiff(
- EventHandler eventHandler, Path pathEntry, OptionsClassProvider options) {
+ EventHandler eventHandler, Root pathEntry, OptionsClassProvider options) {
DiffAwarenessState diffAwarenessState = maybeGetDiffAwarenessState(pathEntry);
if (diffAwarenessState == null) {
return BrokenProcessableModifiedFileSet.INSTANCE;
@@ -120,7 +120,7 @@
}
private void handleBrokenDiffAwareness(
- EventHandler eventHandler, Path pathEntry, BrokenDiffAwarenessException e) {
+ EventHandler eventHandler, Root pathEntry, BrokenDiffAwarenessException e) {
currentDiffAwarenessStates.remove(pathEntry);
logger.info("Broken diff awareness for " + pathEntry + ": " + e);
eventHandler.handle(Event.warn(e.getMessage() + "... temporarily falling back to manually "
@@ -132,7 +132,7 @@
* current one, or otherwise {@code null} if no factory could make a fresh one.
*/
@Nullable
- private DiffAwarenessState maybeGetDiffAwarenessState(Path pathEntry) {
+ private DiffAwarenessState maybeGetDiffAwarenessState(Root pathEntry) {
DiffAwarenessState diffAwarenessState = currentDiffAwarenessStates.get(pathEntry);
if (diffAwarenessState != null) {
return diffAwarenessState;
@@ -153,15 +153,15 @@
private class ProcessableModifiedFileSetImpl implements ProcessableModifiedFileSet {
private final ModifiedFileSet modifiedFileSet;
- private final Path pathEntry;
+ private final Root pathEntry;
/**
* The {@link View} that should be the baseline on the next {@link #getDiff} call after
* {@link #markProcessed} is called.
*/
private final View nextView;
- private ProcessableModifiedFileSetImpl(ModifiedFileSet modifiedFileSet, Path pathEntry,
- View nextView) {
+ private ProcessableModifiedFileSetImpl(
+ ModifiedFileSet modifiedFileSet, Root pathEntry, View nextView) {
this.modifiedFileSet = modifiedFileSet;
this.pathEntry = pathEntry;
this.nextView = nextView;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java b/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
index eae3b0c..94a1a3b 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/DirtinessCheckerUtils.java
@@ -21,7 +21,7 @@
import com.google.common.collect.ImmutableList;
import com.google.devtools.build.lib.skyframe.ExternalFilesHelper.FileType;
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.lib.vfs.RootedPath;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -92,9 +92,9 @@
}
static final class MissingDiffDirtinessChecker extends BasicFilesystemDirtinessChecker {
- private final Set<Path> missingDiffPackageRoots;
+ private final Set<Root> missingDiffPackageRoots;
- MissingDiffDirtinessChecker(final Set<Path> missingDiffPackageRoots) {
+ MissingDiffDirtinessChecker(final Set<Root> missingDiffPackageRoots) {
this.missingDiffPackageRoots = missingDiffPackageRoots;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/EnvironmentBackedRecursivePackageProvider.java b/src/main/java/com/google/devtools/build/lib/skyframe/EnvironmentBackedRecursivePackageProvider.java
index 9dc0b1c..ccbc126 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/EnvironmentBackedRecursivePackageProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/EnvironmentBackedRecursivePackageProvider.java
@@ -33,6 +33,7 @@
import com.google.devtools.build.lib.rules.repository.RepositoryDirectoryValue;
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.Environment;
import com.google.devtools.build.skyframe.SkyKey;
@@ -135,7 +136,7 @@
throw new MissingDepException();
}
- List<Path> roots = new ArrayList<>();
+ List<Root> roots = new ArrayList<>();
if (repository.isMain()) {
roots.addAll(packageLocator.getPathEntries());
} else {
@@ -149,7 +150,7 @@
eventHandler.handle(Event.error(String.format("No such repository '%s'", repository)));
return ImmutableList.of();
}
- roots.add(repositoryValue.getPath());
+ roots.add(Root.fromPath(repositoryValue.getPath()));
}
if (blacklistedSubdirectories.contains(directory)) {
@@ -158,7 +159,7 @@
PathFragment.checkAllPathsAreUnder(blacklistedSubdirectories, directory);
LinkedHashSet<PathFragment> packageNames = new LinkedHashSet<>();
- for (Path root : roots) {
+ for (Root root : roots) {
RecursivePkgValue lookup = (RecursivePkgValue) env.getValue(RecursivePkgValue.key(
repository, RootedPath.toRootedPath(root, directory), blacklistedSubdirectories));
if (lookup == null) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java b/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
index e3b15f6..53c1aad 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GlobDescriptor.java
@@ -23,9 +23,8 @@
import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
import com.google.devtools.build.lib.skyframe.serialization.strings.StringCodecs;
import com.google.devtools.build.lib.util.StringCanonicalizer;
-import com.google.devtools.build.lib.vfs.Path;
-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 com.google.devtools.build.skyframe.SkyFunctionName;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.protobuf.CodedInputStream;
@@ -45,8 +44,8 @@
private static final Interner<GlobDescriptor> interner = BlazeInterners.newWeakInterner();
/** Creates and returns a new {@link ObjectCodec} for {@link GlobDescriptor}s. */
- public static ObjectCodec<GlobDescriptor> getCodec(PathCodec pathCodec) {
- return new GlobDescriptorCodec(pathCodec);
+ public static ObjectCodec<GlobDescriptor> getCodec(ObjectCodec<Root> rootCodec) {
+ return new GlobDescriptorCodec(rootCodec);
}
/**
@@ -55,14 +54,13 @@
* @param packageId the name of the owner package (must be an existing package)
* @param packageRoot the package root of {@code packageId}
* @param subdir the subdirectory being looked at (must exist and must be a directory. It's
- * assumed that there are no other packages between {@code packageName} and
- * {@code subdir}.
+ * assumed that there are no other packages between {@code packageName} and {@code subdir}.
* @param pattern a valid glob pattern
* @param excludeDirs true if directories should be excluded from results
*/
public static GlobDescriptor create(
PackageIdentifier packageId,
- Path packageRoot,
+ Root packageRoot,
PathFragment subdir,
String pattern,
boolean excludeDirs) {
@@ -72,13 +70,17 @@
}
private final PackageIdentifier packageId;
- private final Path packageRoot;
+ private final Root packageRoot;
private final PathFragment subdir;
private final String pattern;
private final boolean excludeDirs;
- private GlobDescriptor(PackageIdentifier packageId, Path packageRoot, PathFragment subdir,
- String pattern, boolean excludeDirs) {
+ private GlobDescriptor(
+ PackageIdentifier packageId,
+ Root packageRoot,
+ PathFragment subdir,
+ String pattern,
+ boolean excludeDirs) {
this.packageId = Preconditions.checkNotNull(packageId);
this.packageRoot = Preconditions.checkNotNull(packageRoot);
this.subdir = Preconditions.checkNotNull(subdir);
@@ -102,10 +104,8 @@
return packageId;
}
- /**
- * Returns the package root of {@code getPackageId()}.
- */
- public Path getPackageRoot() {
+ /** Returns the package root of {@code getPackageId()}. */
+ public Root getPackageRoot() {
return packageRoot;
}
@@ -168,11 +168,11 @@
private static class GlobDescriptorCodec implements ObjectCodec<GlobDescriptor> {
private final PackageIdentifierCodec packageIdCodec = new PackageIdentifierCodec();
- private final PathCodec pathCodec;
+ private final ObjectCodec<Root> rootCodec;
private final ObjectCodec<String> stringCodec = StringCodecs.asciiOptimized();
- private GlobDescriptorCodec(PathCodec pathCodec) {
- this.pathCodec = pathCodec;
+ private GlobDescriptorCodec(ObjectCodec<Root> rootCodec) {
+ this.rootCodec = rootCodec;
}
@Override
@@ -184,7 +184,7 @@
public void serialize(GlobDescriptor globDesc, CodedOutputStream codedOut)
throws IOException, SerializationException {
packageIdCodec.serialize(globDesc.getPackageId(), codedOut);
- pathCodec.serialize(globDesc.getPackageRoot(), codedOut);
+ rootCodec.serialize(globDesc.getPackageRoot(), codedOut);
PathFragment.CODEC.serialize(globDesc.getSubdir(), codedOut);
stringCodec.serialize(globDesc.getPattern(), codedOut);
codedOut.writeBoolNoTag(globDesc.excludeDirs());
@@ -194,7 +194,7 @@
public GlobDescriptor deserialize(CodedInputStream codedIn)
throws SerializationException, IOException {
PackageIdentifier packageId = packageIdCodec.deserialize(codedIn);
- Path packageRoot = pathCodec.deserialize(codedIn);
+ Root packageRoot = rootCodec.deserialize(codedIn);
PathFragment pathFragment = PathFragment.CODEC.deserialize(codedIn);
String pattern = stringCodec.deserialize(codedIn);
boolean excludeDirs = codedIn.readBool();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GlobValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/GlobValue.java
index eb00cb9..e268135 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GlobValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GlobValue.java
@@ -20,8 +20,8 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
-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.UnixGlob;
import com.google.devtools.build.skyframe.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -75,14 +75,19 @@
}
/**
- * Constructs a {@link SkyKey} for a glob lookup. {@code packageName} is assumed to be an
- * existing package. Trying to glob into a non-package is undefined behavior.
+ * Constructs a {@link SkyKey} for a glob lookup. {@code packageName} is assumed to be an existing
+ * package. Trying to glob into a non-package is undefined behavior.
*
* @throws InvalidGlobPatternException if the pattern is not valid.
*/
@ThreadSafe
- public static SkyKey key(PackageIdentifier packageId, Path packageRoot, String pattern,
- boolean excludeDirs, PathFragment subdir) throws InvalidGlobPatternException {
+ public static SkyKey key(
+ PackageIdentifier packageId,
+ Root packageRoot,
+ String pattern,
+ boolean excludeDirs,
+ PathFragment subdir)
+ throws InvalidGlobPatternException {
if (pattern.indexOf('?') != -1) {
throw new InvalidGlobPatternException(pattern, "wildcard ? forbidden");
}
@@ -101,8 +106,12 @@
* <p>Do not use outside {@code GlobFunction}.
*/
@ThreadSafe
- static SkyKey internalKey(PackageIdentifier packageId, Path packageRoot, PathFragment subdir,
- String pattern, boolean excludeDirs) {
+ static SkyKey internalKey(
+ PackageIdentifier packageId,
+ Root packageRoot,
+ PathFragment subdir,
+ String pattern,
+ boolean excludeDirs) {
return GlobDescriptor.create(packageId, packageRoot, subdir, pattern, excludeDirs);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java b/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java
index d7e74ff..f73ac24 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/GraphBackedRecursivePackageProvider.java
@@ -43,6 +43,7 @@
import com.google.devtools.build.lib.skyframe.TargetPatternValue.TargetPatternKey;
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.SkyKey;
import com.google.devtools.build.skyframe.SkyValue;
@@ -201,7 +202,7 @@
return ImmutableList.of();
}
- List<Path> roots = new ArrayList<>();
+ List<Root> roots = new ArrayList<>();
if (repository.isMain()) {
roots.addAll(pkgPath.getPathEntries());
} else {
@@ -212,14 +213,14 @@
// "nothing".
return ImmutableList.of();
}
- roots.add(repositoryValue.getPath());
+ roots.add(Root.fromPath(repositoryValue.getPath()));
}
// If we found a TargetsBelowDirectory pattern in the universe that contains this directory,
// then we can look for packages in and under it in the graph. If we didn't find one, then the
// directory wasn't in the universe, so return an empty list.
ImmutableList.Builder<PathFragment> builder = ImmutableList.builder();
- for (Path root : roots) {
+ for (Root root : roots) {
RootedPath rootedDir = RootedPath.toRootedPath(root, directory);
TraversalInfo info =
new TraversalInfo(rootedDir, blacklistedSubdirectories, excludedSubdirectories);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
index 897a8e0..76cfd37 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalDiffAwareness.java
@@ -23,6 +23,7 @@
import com.google.devtools.build.lib.util.OS;
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.common.options.Option;
import com.google.devtools.common.options.OptionDocumentationCategory;
import com.google.devtools.common.options.OptionEffectTag;
@@ -73,10 +74,10 @@
}
@Override
- public DiffAwareness maybeCreate(com.google.devtools.build.lib.vfs.Path pathEntry) {
+ public DiffAwareness maybeCreate(Root pathEntry) {
com.google.devtools.build.lib.vfs.Path resolvedPathEntry;
try {
- resolvedPathEntry = pathEntry.resolveSymbolicLinks();
+ resolvedPathEntry = pathEntry.asPath().resolveSymbolicLinks();
} catch (IOException e) {
return null;
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/MapAsPackageRoots.java b/src/main/java/com/google/devtools/build/lib/skyframe/MapAsPackageRoots.java
index f4ac69f..e3d2baa 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/MapAsPackageRoots.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/MapAsPackageRoots.java
@@ -18,7 +18,7 @@
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.PackageRoots;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.Root;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
@@ -28,22 +28,22 @@
* planted for execution.
*/
public class MapAsPackageRoots implements PackageRoots {
- private final ImmutableMap<PackageIdentifier, Path> packageRootsMap;
+ private final ImmutableMap<PackageIdentifier, Root> packageRootsMap;
- MapAsPackageRoots(ImmutableMap<PackageIdentifier, Path> packageRootsMap) {
+ MapAsPackageRoots(ImmutableMap<PackageIdentifier, Root> packageRootsMap) {
this.packageRootsMap = packageRootsMap;
}
@Override
- public Optional<ImmutableMap<PackageIdentifier, Path>> getPackageRootsMap() {
+ public Optional<ImmutableMap<PackageIdentifier, Root>> getPackageRootsMap() {
return Optional.of(packageRootsMap);
}
@Override
public PackageRootLookup getPackageRootLookup() {
- Map<Path, ArtifactRoot> rootMap = new HashMap<>();
+ Map<Root, ArtifactRoot> rootMap = new HashMap<>();
Map<PackageIdentifier, ArtifactRoot> realPackageRoots = new HashMap<>();
- for (Map.Entry<PackageIdentifier, Path> entry : packageRootsMap.entrySet()) {
+ for (Map.Entry<PackageIdentifier, Root> entry : packageRootsMap.entrySet()) {
ArtifactRoot root = rootMap.get(entry.getValue());
if (root == null) {
root = ArtifactRoot.asSourceRoot(entry.getValue());
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
index b10ab4b..6da94fd 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageFunction.java
@@ -60,6 +60,7 @@
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;
@@ -433,7 +434,7 @@
* @throws PackageFunctionException if there is an error computing the workspace file or adding
* its rules to the //external package.
*/
- private SkyValue getExternalPackage(Environment env, Path packageLookupPath)
+ private SkyValue getExternalPackage(Environment env, Root packageLookupPath)
throws PackageFunctionException, InterruptedException {
SkylarkSemantics skylarkSemantics = PrecomputedValue.SKYLARK_SEMANTICS.get(env);
if (skylarkSemantics == null) {
@@ -808,7 +809,7 @@
}
private static void handleLabelsCrossingSubpackagesAndPropagateInconsistentFilesystemExceptions(
- Path pkgRoot, PackageIdentifier pkgId, Package.Builder pkgBuilder, Environment env)
+ Root pkgRoot, PackageIdentifier pkgId, Package.Builder pkgBuilder, Environment env)
throws InternalInconsistentFilesystemException, InterruptedException {
Set<SkyKey> containingPkgLookupKeys = Sets.newHashSet();
Map<Target, SkyKey> targetToKey = new HashMap<>();
@@ -887,7 +888,10 @@
}
private static boolean maybeAddEventAboutLabelCrossingSubpackage(
- Package.Builder pkgBuilder, Path pkgRoot, Label label, @Nullable Location location,
+ Package.Builder pkgBuilder,
+ Root pkgRoot,
+ Label label,
+ @Nullable Location location,
@Nullable ContainingPackageLookupValue containingPkgLookupValue) {
if (containingPkgLookupValue == null) {
return true;
@@ -914,7 +918,7 @@
PathFragment labelNameFragment = PathFragment.create(label.getName());
String message = String.format("Label '%s' crosses boundary of subpackage '%s'",
label, containingPkg);
- Path containingRoot = containingPkgLookupValue.getContainingPackageRoot();
+ Root containingRoot = containingPkgLookupValue.getContainingPackageRoot();
if (pkgRoot.equals(containingRoot)) {
PathFragment labelNameInContainingPackage = labelNameFragment.subFragment(
containingPkg.getPackageFragment().segmentCount()
@@ -993,12 +997,15 @@
*/
private static class SkyframeHybridGlobber implements GlobberWithSkyframeGlobDeps {
private final PackageIdentifier packageId;
- private final Path packageRoot;
+ private final Root packageRoot;
private final Environment env;
private final LegacyGlobber legacyGlobber;
private final Set<SkyKey> globDepsRequested = Sets.newConcurrentHashSet();
- private SkyframeHybridGlobber(PackageIdentifier packageId, Path packageRoot, Environment env,
+ private SkyframeHybridGlobber(
+ PackageIdentifier packageId,
+ Root packageRoot,
+ Environment env,
LegacyGlobber legacyGlobber) {
this.packageId = packageId;
this.packageRoot = packageRoot;
@@ -1225,7 +1232,7 @@
private GlobberWithSkyframeGlobDeps makeGlobber(
Path buildFilePath,
PackageIdentifier packageId,
- Path packageRoot,
+ Root packageRoot,
SkyFunction.Environment env) {
LegacyGlobber legacyGlobber = packageFactory.createLegacyGlobber(
buildFilePath.getParentDirectory(), packageId, packageLocator);
@@ -1243,15 +1250,14 @@
}
/**
- * Constructs a {@link Package} object for the given package using legacy package loading.
- * Note that the returned package may be in error.
+ * Constructs a {@link Package} object for the given package using legacy package loading. Note
+ * that the returned package may be in error.
*
* <p>May return null if the computation has to be restarted.
*
- * <p>Exactly one of {@code replacementContents} and {@code buildFileValue} will be
- * non-{@code null}. The former indicates that we have a faux BUILD file with the given contents
- * and the latter indicates that we have a legitimate BUILD file and should actually read its
- * contents.
+ * <p>Exactly one of {@code replacementContents} and {@code buildFileValue} will be non-{@code
+ * null}. The former indicates that we have a faux BUILD file with the given contents and the
+ * latter indicates that we have a legitimate BUILD file and should actually read its contents.
*/
@Nullable
private BuilderAndGlobDeps loadPackage(
@@ -1263,7 +1269,7 @@
RuleVisibility defaultVisibility,
SkylarkSemantics skylarkSemantics,
List<Statement> preludeStatements,
- Path packageRoot,
+ Root packageRoot,
Environment env)
throws InterruptedException, PackageFunctionException {
BuilderAndGlobDeps builderAndGlobDeps = packageFunctionCache.getIfPresent(packageId);
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
index 00d0c34..780b4d8 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java
@@ -25,8 +25,8 @@
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.pkgcache.PathPackageLocator;
import com.google.devtools.build.lib.syntax.EvalException;
-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;
@@ -120,7 +120,7 @@
// to having restart the SkyFunction after every new dependency. However, if we try to batch
// the missing value keys, more dependencies than necessary will be declared. This wart can be
// fixed once we have nicer continuation support [skyframe-loading]
- for (Path packagePathEntry : pkgLocator.getPathEntries()) {
+ for (Root packagePathEntry : pkgLocator.getPathEntries()) {
// This checks for the build file names in the correct precedence order.
for (BuildFileName buildFileName : buildFilesByPriority) {
@@ -168,7 +168,7 @@
private PackageLookupValue getPackageLookupValue(
Environment env,
- ImmutableList<Path> packagePathEntries,
+ ImmutableList<Root> packagePathEntries,
PackageIdentifier packageIdentifier,
BuildFileName buildFileName)
throws PackageLookupFunctionException, InterruptedException {
@@ -177,7 +177,7 @@
// to having restart the SkyFunction after every new dependency. However, if we try to batch
// the missing value keys, more dependencies than necessary will be declared. This wart can be
// fixed once we have nicer continuation support [skyframe-loading]
- for (Path packagePathEntry : packagePathEntries) {
+ for (Root packagePathEntry : packagePathEntries) {
PackageLookupValue result =
getPackageLookupValue(env, packagePathEntry, packageIdentifier, buildFileName);
if (result == null) {
@@ -192,7 +192,7 @@
private PackageLookupValue getPackageLookupValue(
Environment env,
- Path packagePathEntry,
+ Root packagePathEntry,
PackageIdentifier packageIdentifier,
BuildFileName buildFileName)
throws InterruptedException, PackageLookupFunctionException {
@@ -235,7 +235,7 @@
if (localRepositoryPath.isAbsolute()) {
// We need the package path to also be absolute.
pathToRequestedPackage =
- packagePathEntry.asFragment().getRelative(pathToRequestedPackage);
+ packagePathEntry.getRelative(pathToRequestedPackage).asFragment();
}
PathFragment remainingPath = pathToRequestedPackage.relativeTo(localRepositoryPath);
PackageIdentifier correctPackage =
@@ -264,7 +264,7 @@
}
private PackageLookupValue computeWorkspacePackageLookupValue(
- Environment env, ImmutableList<Path> packagePathEntries)
+ Environment env, ImmutableList<Root> packagePathEntries)
throws PackageLookupFunctionException, InterruptedException {
PackageLookupValue result =
getPackageLookupValue(
@@ -281,7 +281,7 @@
if (packagePathEntries.isEmpty()) {
return PackageLookupValue.NO_BUILD_FILE_VALUE;
}
- Path lastPackagePath = packagePathEntries.get(packagePathEntries.size() - 1);
+ Root lastPackagePath = packagePathEntries.get(packagePathEntries.size() - 1);
FileValue lastPackagePackagePathFileValue = getFileValue(
RootedPath.toRootedPath(lastPackagePath, PathFragment.EMPTY_FRAGMENT),
env,
@@ -326,14 +326,14 @@
PathFragment buildFileFragment =
id.getPackageFragment().getRelative(buildFileName.getFilenameFragment());
RootedPath buildFileRootedPath =
- RootedPath.toRootedPath(repositoryValue.getPath(), buildFileFragment);
+ RootedPath.toRootedPath(Root.fromPath(repositoryValue.getPath()), buildFileFragment);
FileValue fileValue = getFileValue(buildFileRootedPath, env, packageIdentifier);
if (fileValue == null) {
return null;
}
if (fileValue.isFile()) {
- return PackageLookupValue.success(repositoryValue.getPath(), buildFileName);
+ return PackageLookupValue.success(Root.fromPath(repositoryValue.getPath()), buildFileName);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
index 50bccd5..408bc27 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupValue.java
@@ -17,8 +17,8 @@
import com.google.common.base.Preconditions;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
import com.google.devtools.build.lib.packages.BuildFileName;
-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.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyKey;
@@ -61,7 +61,7 @@
protected PackageLookupValue() {
}
- public static PackageLookupValue success(Path root, BuildFileName buildFileName) {
+ public static PackageLookupValue success(Root root, BuildFileName buildFileName) {
return new SuccessfulPackageLookupValue(root, buildFileName);
}
@@ -75,10 +75,10 @@
}
/**
- * For a successful package lookup, returns the root (package path entry) that the package
- * resides in.
+ * For a successful package lookup, returns the root (package path entry) that the package resides
+ * in.
*/
- public abstract Path getRoot();
+ public abstract Root getRoot();
/** For a successful package lookup, returns the build file name that the package uses. */
public abstract BuildFileName getBuildFileName();
@@ -120,10 +120,10 @@
/** Successful lookup value. */
public static class SuccessfulPackageLookupValue extends PackageLookupValue {
- private final Path root;
+ private final Root root;
private final BuildFileName buildFileName;
- private SuccessfulPackageLookupValue(Path root, BuildFileName buildFileName) {
+ private SuccessfulPackageLookupValue(Root root, BuildFileName buildFileName) {
this.root = root;
this.buildFileName = buildFileName;
}
@@ -134,7 +134,7 @@
}
@Override
- public Path getRoot() {
+ public Root getRoot() {
return root;
}
@@ -176,7 +176,7 @@
}
@Override
- public Path getRoot() {
+ public Root getRoot() {
throw new IllegalStateException();
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageRootsNoSymlinkCreation.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageRootsNoSymlinkCreation.java
index 16f03e7..68dacda 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageRootsNoSymlinkCreation.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageRootsNoSymlinkCreation.java
@@ -19,7 +19,7 @@
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.PackageRoots;
import com.google.devtools.build.lib.cmdline.PackageIdentifier;
-import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.Root;
import java.util.Optional;
/**
@@ -30,12 +30,12 @@
private final ArtifactRoot sourceRoot;
@VisibleForTesting
- public PackageRootsNoSymlinkCreation(Path sourcePath) {
+ public PackageRootsNoSymlinkCreation(Root sourcePath) {
this.sourceRoot = ArtifactRoot.asSourceRoot(sourcePath);
}
@Override
- public Optional<ImmutableMap<PackageIdentifier, Path>> getPackageRootsMap() {
+ public Optional<ImmutableMap<PackageIdentifier, Root>> getPackageRootsMap() {
return Optional.empty();
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
index fd0f08f..0eab832 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/PrepareDepsOfPatternFunction.java
@@ -37,8 +37,8 @@
import com.google.devtools.build.lib.skyframe.EnvironmentBackedRecursivePackageProvider.MissingDepException;
import com.google.devtools.build.lib.util.BatchCallback;
import com.google.devtools.build.lib.util.BatchCallback.NullCallback;
-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;
@@ -246,7 +246,7 @@
Preconditions.checkArgument(excludedSubdirectories.isEmpty(), excludedSubdirectories);
FilteringPolicy policy =
rulesOnly ? FilteringPolicies.RULES_ONLY : FilteringPolicies.NO_FILTER;
- List<Path> roots = new ArrayList<>();
+ List<Root> roots = new ArrayList<>();
if (repository.isMain()) {
roots.addAll(pkgPath.getPathEntries());
} else {
@@ -261,10 +261,10 @@
// already checked for its existence.
throw new IllegalStateException(String.format("No such repository '%s'", repository));
}
- roots.add(repositoryValue.getPath());
+ roots.add(Root.fromPath(repositoryValue.getPath()));
}
- for (Path root : roots) {
+ for (Root root : roots) {
RootedPath rootedPath = RootedPath.toRootedPath(root, directoryPathFragment);
env.getValues(
ImmutableList.of(
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java b/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java
index e46f4f2..d4fba1a 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ProcessPackageDirectory.java
@@ -25,8 +25,8 @@
import com.google.devtools.build.lib.packages.NoSuchPackageException;
import com.google.devtools.build.lib.vfs.Dirent;
import com.google.devtools.build.lib.vfs.Dirent.Type;
-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.SkyKey;
@@ -167,7 +167,7 @@
RootedPath rootedPath,
RepositoryName repositoryName,
Set<PathFragment> excludedPaths) {
- Path root = rootedPath.getRoot();
+ Root root = rootedPath.getRoot();
PathFragment rootRelativePath = rootedPath.getRelativePath();
boolean followSymlinks = shouldFollowSymlinksWhenTraversing(dirListingValue.getDirents());
List<SkyKey> childDeps = new ArrayList<>();
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
index 5b0549f..d8e569e 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalFunction.java
@@ -24,8 +24,8 @@
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.ResolvedFileFactory;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalValue.TraversalRequest;
import com.google.devtools.build.lib.vfs.Dirent;
-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;
@@ -308,7 +308,7 @@
return PkgLookupResult.conflict(traversal, rootInfo);
} else {
// The traversal's root was a source directory and it defines a package.
- Path pkgRoot = pkgLookup.getRoot();
+ Root pkgRoot = pkgLookup.getRoot();
if (!pkgRoot.equals(traversal.path.getRoot())) {
// However the root of this package is different from what we expected. stat() the real
// BUILD file of that package.
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
index c37dfc4..d3bbc16 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/RecursiveFilesystemTraversalValue.java
@@ -23,8 +23,8 @@
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalFunction.DanglingSymlinkException;
import com.google.devtools.build.lib.skyframe.RecursiveFilesystemTraversalFunction.FileType;
-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.LegacySkyKey;
import com.google.devtools.build.skyframe.SkyKey;
@@ -167,7 +167,7 @@
* <p>This method can be used when a package is found out to be under a different root path than
* originally assumed.
*/
- TraversalRequest forChangedRootPath(Path newRoot) {
+ TraversalRequest forChangedRootPath(Root newRoot) {
return duplicate(RootedPath.toRootedPath(newRoot, path.getRelativePath()),
skipTestingForSubpackage);
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
index 0313d47..c9f87fa 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SequencedSkyframeExecutor.java
@@ -66,6 +66,7 @@
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.BuildDriver;
import com.google.devtools.build.skyframe.Differencer;
import com.google.devtools.build.skyframe.InMemoryMemoizingEvaluator;
@@ -312,11 +313,11 @@
}
TimestampGranularityMonitor tsgm = this.tsgm.get();
modifiedFiles = 0;
- Map<Path, DiffAwarenessManager.ProcessableModifiedFileSet> modifiedFilesByPathEntry =
+ Map<Root, DiffAwarenessManager.ProcessableModifiedFileSet> modifiedFilesByPathEntry =
Maps.newHashMap();
- Set<Pair<Path, DiffAwarenessManager.ProcessableModifiedFileSet>>
+ Set<Pair<Root, DiffAwarenessManager.ProcessableModifiedFileSet>>
pathEntriesWithoutDiffInformation = Sets.newHashSet();
- for (Path pathEntry : pkgLocator.get().getPathEntries()) {
+ for (Root pathEntry : pkgLocator.get().getPathEntries()) {
DiffAwarenessManager.ProcessableModifiedFileSet modifiedFileSet =
diffAwarenessManager.getDiff(eventHandler, pathEntry, options);
if (modifiedFileSet.getModifiedFileSet().treatEverythingAsModified()) {
@@ -359,10 +360,11 @@
* diff. Removes entries from the given map as they are processed. All of the files need to be
* invalidated, so the map should be empty upon completion of this function.
*/
- private void handleDiffsWithCompleteDiffInformation(TimestampGranularityMonitor tsgm,
- Map<Path, DiffAwarenessManager.ProcessableModifiedFileSet> modifiedFilesByPathEntry)
- throws InterruptedException {
- for (Path pathEntry : ImmutableSet.copyOf(modifiedFilesByPathEntry.keySet())) {
+ private void handleDiffsWithCompleteDiffInformation(
+ TimestampGranularityMonitor tsgm,
+ Map<Root, DiffAwarenessManager.ProcessableModifiedFileSet> modifiedFilesByPathEntry)
+ throws InterruptedException {
+ for (Root pathEntry : ImmutableSet.copyOf(modifiedFilesByPathEntry.keySet())) {
DiffAwarenessManager.ProcessableModifiedFileSet processableModifiedFileSet =
modifiedFilesByPathEntry.get(pathEntry);
ModifiedFileSet modifiedFileSet = processableModifiedFileSet.getModifiedFileSet();
@@ -380,7 +382,7 @@
private void handleDiffsWithMissingDiffInformation(
ExtendedEventHandler eventHandler,
TimestampGranularityMonitor tsgm,
- Set<Pair<Path, DiffAwarenessManager.ProcessableModifiedFileSet>>
+ Set<Pair<Root, DiffAwarenessManager.ProcessableModifiedFileSet>>
pathEntriesWithoutDiffInformation,
boolean checkOutputFiles)
throws InterruptedException {
@@ -406,8 +408,8 @@
// system values under package roots for which we don't have diff information. If at least
// one path entry doesn't have diff information, then we're going to have to iterate over
// the skyframe values at least once no matter what.
- Set<Path> diffPackageRootsUnderWhichToCheck = new HashSet<>();
- for (Pair<Path, DiffAwarenessManager.ProcessableModifiedFileSet> pair :
+ Set<Root> diffPackageRootsUnderWhichToCheck = new HashSet<>();
+ for (Pair<Root, DiffAwarenessManager.ProcessableModifiedFileSet> pair :
pathEntriesWithoutDiffInformation) {
diffPackageRootsUnderWhichToCheck.add(pair.getFirst());
}
@@ -438,7 +440,7 @@
new MissingDiffDirtinessChecker(diffPackageRootsUnderWhichToCheck)))));
handleChangedFiles(diffPackageRootsUnderWhichToCheck, diff);
- for (Pair<Path, DiffAwarenessManager.ProcessableModifiedFileSet> pair :
+ for (Pair<Root, DiffAwarenessManager.ProcessableModifiedFileSet> pair :
pathEntriesWithoutDiffInformation) {
pair.getSecond().markProcessed();
}
@@ -450,7 +452,7 @@
}
private void handleChangedFiles(
- Collection<Path> diffPackageRootsUnderWhichToCheck, Differencer.Diff diff) {
+ Collection<Root> diffPackageRootsUnderWhichToCheck, Differencer.Diff diff) {
Collection<SkyKey> changedKeysWithoutNewValues = diff.changedKeysWithoutNewValues();
Map<SkyKey, SkyValue> changedKeysWithNewValues = diff.changedKeysWithNewValues();
@@ -467,9 +469,10 @@
private static final int MAX_NUMBER_OF_CHANGED_KEYS_TO_LOG = 10;
- private static void logDiffInfo(Iterable<Path> pathEntries,
- Collection<SkyKey> changedWithoutNewValue,
- Map<SkyKey, ? extends SkyValue> changedWithNewValue) {
+ private static void logDiffInfo(
+ Iterable<Root> pathEntries,
+ Collection<SkyKey> changedWithoutNewValue,
+ Map<SkyKey, ? extends SkyValue> changedWithNewValue) {
int numModified = changedWithNewValue.size() + changedWithoutNewValue.size();
StringBuilder result = new StringBuilder("DiffAwareness found ")
.append(numModified)
@@ -564,7 +567,7 @@
@Override
public void invalidateFilesUnderPathForTesting(
- ExtendedEventHandler eventHandler, ModifiedFileSet modifiedFileSet, Path pathEntry)
+ ExtendedEventHandler eventHandler, ModifiedFileSet modifiedFileSet, Root pathEntry)
throws InterruptedException {
if (lastAnalysisDiscarded) {
// Values were cleared last build, but they couldn't be deleted because they were needed for
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
index 81159c3..d724a90 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeBuildView.java
@@ -64,7 +64,7 @@
import com.google.devtools.build.lib.skyframe.SkyframeActionExecutor.ConflictException;
import com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.SkylarkImportFailedException;
import com.google.devtools.build.lib.util.OrderedSetMultimap;
-import com.google.devtools.build.lib.vfs.Path;
+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;
@@ -216,7 +216,7 @@
skyframeExecutor.findArtifactConflicts();
Collection<AspectValue> goodAspects = Lists.newArrayListWithCapacity(values.size());
- Path singleSourceRoot = skyframeExecutor.getForcedSingleSourceRootIfNoExecrootSymlinkCreation();
+ Root singleSourceRoot = skyframeExecutor.getForcedSingleSourceRootIfNoExecrootSymlinkCreation();
NestedSetBuilder<Package> packages =
singleSourceRoot == null ? NestedSetBuilder.stableOrder() : null;
for (AspectValueKey aspectKey : aspectKeys) {
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index d5519db..29cb592 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -130,6 +130,7 @@
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.UnixGlob;
import com.google.devtools.build.skyframe.BuildDriver;
@@ -715,7 +716,7 @@
* need to track all loaded packages.
*/
@Nullable
- protected Path getForcedSingleSourceRootIfNoExecrootSymlinkCreation() {
+ protected Root getForcedSingleSourceRootIfNoExecrootSymlinkCreation() {
return null;
}
@@ -910,7 +911,7 @@
}
@VisibleForTesting
- ImmutableList<Path> getPathEntries() {
+ ImmutableList<Root> getPathEntries() {
return pkgLocator.get().getPathEntries();
}
@@ -923,9 +924,11 @@
|| (oldType.equals(Dirent.Type.SYMLINK) && newType.equals(FileStateType.SYMLINK));
}
- protected Differencer.Diff getDiff(TimestampGranularityMonitor tsgm,
- Iterable<PathFragment> modifiedSourceFiles, final Path pathEntry)
- throws InterruptedException {
+ protected Differencer.Diff getDiff(
+ TimestampGranularityMonitor tsgm,
+ Iterable<PathFragment> modifiedSourceFiles,
+ final Root pathEntry)
+ throws InterruptedException {
if (Iterables.isEmpty(modifiedSourceFiles)) {
return new ImmutableDiff(ImmutableList.<SkyKey>of(), ImmutableMap.<SkyKey, SkyValue>of());
}
@@ -1626,7 +1629,7 @@
*/
@VisibleForTesting
public abstract void invalidateFilesUnderPathForTesting(
- ExtendedEventHandler eventHandler, ModifiedFileSet modifiedFileSet, Path pathEntry)
+ ExtendedEventHandler eventHandler, ModifiedFileSet modifiedFileSet, Root pathEntry)
throws InterruptedException;
/**
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
index 7fee331..e995c5c 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/packages/AbstractPackageLoader.java
@@ -69,6 +69,7 @@
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.BuildDriver;
import com.google.devtools.build.skyframe.Differencer;
import com.google.devtools.build.skyframe.ErrorInfo;
@@ -215,7 +216,7 @@
PathPackageLocator pkgLocator =
new PathPackageLocator(
null,
- ImmutableList.of(workspaceDir),
+ ImmutableList.of(Root.fromPath(workspaceDir)),
BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY);
this.ruleClassProvider = builder.ruleClassProvider;
this.skylarkSemantics = builder.skylarkSemantics;
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java
index 4a8858c..53962ba 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/serialization/testutils/FsUtils.java
@@ -17,6 +17,7 @@
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.FileSystemProvider;
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;
@@ -29,7 +30,7 @@
public static final RootedPath TEST_ROOT =
RootedPath.toRootedPath(
- TEST_FILESYSTEM.getPath(PathFragment.create("/anywhere/at/all")),
+ Root.fromPath(TEST_FILESYSTEM.getPath(PathFragment.create("/anywhere/at/all"))),
PathFragment.create("all/at/anywhere"));
private FsUtils() {}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
index e914663..a469f20 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/FileSystem.java
@@ -113,7 +113,9 @@
}
/** Lazy-initialized on first access, always use {@link FileSystem#getRootDirectory} */
- private Path rootPath;
+ private volatile Path rootPath;
+
+ private volatile Root root;
/** Returns filesystem-specific path factory. */
protected PathFactory getPathFactory() {
@@ -159,6 +161,17 @@
return rootPath;
}
+ final Root getRoot() {
+ if (root == null) {
+ synchronized (this) {
+ if (root == null) {
+ root = new Root.PathRoot(getRootDirectory());
+ }
+ }
+ }
+ return root;
+ }
+
/**
* Returns whether or not the FileSystem supports modifications of files and file entries.
*
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/Root.java b/src/main/java/com/google/devtools/build/lib/vfs/Root.java
new file mode 100644
index 0000000..41f65de
--- /dev/null
+++ b/src/main/java/com/google/devtools/build/lib/vfs/Root.java
@@ -0,0 +1,179 @@
+// 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 com.google.common.base.Preconditions;
+import com.google.devtools.build.lib.skyframe.serialization.ObjectCodec;
+import com.google.devtools.build.lib.skyframe.serialization.SerializationException;
+import com.google.protobuf.CodedInputStream;
+import com.google.protobuf.CodedOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+
+/**
+ * A root path used in {@link RootedPath} and in artifact roots.
+ *
+ * <p>A typical root could be the exec path, a package root, or an output root specific to some
+ * configuration.
+ */
+public interface Root extends Comparable<Root>, Serializable {
+
+ static ObjectCodec<Root> getCodec(PathCodec pathCodec) {
+ return new RootCodec(pathCodec);
+ }
+
+ /** Constructs a root from a path. */
+ static Root fromPath(Path path) {
+ return new PathRoot(path);
+ }
+
+ /** Returns a root from the file system's root directory. */
+ static Root fromFileSystemRoot(FileSystem fileSystem) {
+ return fileSystem.getRoot();
+ }
+
+ /** Returns a path by concatenating the root and the root-relative path. */
+ Path getRelative(PathFragment relativePath);
+
+ /** Returns a path by concatenating the root and the root-relative path. */
+ Path getRelative(String relativePath);
+
+ /** Returns the relative path between the root and the given path. */
+ PathFragment relativize(Path path);
+
+ @Deprecated
+ PathFragment relativize(PathFragment relativePath);
+
+ /** Returns whether the given path is under this root. */
+ boolean contains(Path path);
+
+ @Deprecated
+ boolean contains(PathFragment relativePath);
+
+ /**
+ * Returns the underlying path. Please avoid using this method. Roots may eventually not be
+ * directly backed by paths.
+ */
+ Path asPath();
+
+ @Deprecated
+ boolean isRootDirectory();
+
+ /** Implementation of Root that is backed by a {@link Path}. */
+ final class PathRoot implements Root {
+ private final Path path;
+
+ PathRoot(Path path) {
+ this.path = path;
+ }
+
+ @Override
+ public Path getRelative(PathFragment relativePath) {
+ return path.getRelative(relativePath);
+ }
+
+ @Override
+ public Path getRelative(String relativePath) {
+ return path.getRelative(relativePath);
+ }
+
+ @Override
+ public PathFragment relativize(Path path) {
+ return path.relativeTo(this.path);
+ }
+
+ @Override
+ public PathFragment relativize(PathFragment relativePath) {
+ Preconditions.checkArgument(relativePath.isAbsolute());
+ return relativePath.relativeTo(path.asFragment());
+ }
+
+ @Override
+ public boolean contains(Path path) {
+ return path.startsWith(this.path);
+ }
+
+ @Override
+ public boolean contains(PathFragment relativePath) {
+ return relativePath.isAbsolute() && relativePath.startsWith(path.asFragment());
+ }
+
+ @Override
+ public Path asPath() {
+ return path;
+ }
+
+ @Override
+ public boolean isRootDirectory() {
+ return path.isRootDirectory();
+ }
+
+ @Override
+ public String toString() {
+ return path.toString();
+ }
+
+ @Override
+ public int compareTo(Root o) {
+ return path.compareTo(((PathRoot) o).path);
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ PathRoot pathRoot = (PathRoot) o;
+ return path.equals(pathRoot.path);
+ }
+
+ @Override
+ public int hashCode() {
+ return path.hashCode();
+ }
+ }
+
+ /** Codec to serialize {@link Root}s. */
+ class RootCodec implements ObjectCodec<Root> {
+ private final PathCodec pathCodec;
+
+ private RootCodec(PathCodec pathCodec) {
+ this.pathCodec = pathCodec;
+ }
+
+ @Override
+ public Class<Root> getEncodedClass() {
+ return Root.class;
+ }
+
+ @Override
+ public void serialize(Root obj, CodedOutputStream codedOut)
+ throws SerializationException, IOException {
+ if (obj instanceof PathRoot) {
+ pathCodec.serialize(((PathRoot) obj).path, codedOut);
+ } else {
+ throw new AssertionError("Unknown Root subclass: " + obj.getClass().getName());
+ }
+ }
+
+ @Override
+ public Root deserialize(CodedInputStream codedIn) throws SerializationException, IOException {
+ Path path = pathCodec.deserialize(codedIn);
+ return new PathRoot(path);
+ }
+ }
+}
diff --git a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
index a704b37..415e0ac 100644
--- a/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
+++ b/src/main/java/com/google/devtools/build/lib/vfs/RootedPath.java
@@ -23,25 +23,24 @@
import java.util.Objects;
/**
- * A {@link PathFragment} relative to a root, which is an absolute {@link Path}. Typically the root
- * will be a package path entry.
+ * A {@link PathFragment} relative to a {@link Root}. Typically the root will be a package path
+ * entry.
*
- * Two {@link RootedPath}s are considered equal iff they have equal roots and equal relative paths.
+ * <p>Two {@link RootedPath}s are considered equal iff they have equal roots and equal relative
+ * paths.
*
- * TODO(bazel-team): refactor Artifact to use this instead of Root.
- * TODO(bazel-team): use an opaque root representation so as to not expose the absolute path to
- * clients via #asPath or #getRoot.
+ * <p>TODO(bazel-team): refactor Artifact to use this instead of Root. TODO(bazel-team): use an
+ * opaque root representation so as to not expose the absolute path to clients via #asPath or
+ * #getRoot.
*/
public class RootedPath implements Serializable {
- private final Path root;
+ private final Root root;
private final PathFragment relativePath;
private final Path path;
- /**
- * Constructs a {@link RootedPath} from an absolute root path and a non-absolute relative path.
- */
- private RootedPath(Path root, PathFragment relativePath) {
+ /** Constructs a {@link RootedPath} from a {@link Root} and path fragment relative to the root. */
+ private RootedPath(Root root, PathFragment relativePath) {
Preconditions.checkState(!relativePath.isAbsolute(), "relativePath: %s root: %s", relativePath,
root);
this.root = root;
@@ -49,32 +48,29 @@
this.path = root.getRelative(this.relativePath);
}
- /**
- * Returns a rooted path representing {@code relativePath} relative to {@code root}.
- */
- public static RootedPath toRootedPath(Path root, PathFragment relativePath) {
+ /** Returns a rooted path representing {@code relativePath} relative to {@code root}. */
+ public static RootedPath toRootedPath(Root root, PathFragment relativePath) {
if (relativePath.isAbsolute()) {
if (root.isRootDirectory()) {
return new RootedPath(
- root.getRelative(relativePath.windowsVolume()), relativePath.toRelative());
+ Root.fromPath(root.getRelative(relativePath.windowsVolume())),
+ relativePath.toRelative());
} else {
Preconditions.checkArgument(
- relativePath.startsWith(root.asFragment()),
+ root.contains(relativePath),
"relativePath '%s' is absolute, but it's not under root '%s'",
relativePath,
root);
- return new RootedPath(root, relativePath.relativeTo(root.asFragment()));
+ return new RootedPath(root, root.relativize(relativePath));
}
} else {
return new RootedPath(root, relativePath);
}
}
- /**
- * Returns a rooted path representing {@code path} under the root {@code root}.
- */
- public static RootedPath toRootedPath(Path root, Path path) {
- Preconditions.checkState(path.startsWith(root), "path: %s root: %s", path, root);
+ /** Returns a rooted path representing {@code path} under the root {@code root}. */
+ public static RootedPath toRootedPath(Root root, Path path) {
+ Preconditions.checkState(root.contains(path), "path: %s root: %s", path, root);
return toRootedPath(root, path.asFragment());
}
@@ -82,13 +78,13 @@
* Returns a rooted path representing {@code path} under one of the package roots, or under the
* filesystem root if it's not under any package root.
*/
- public static RootedPath toRootedPathMaybeUnderRoot(Path path, Iterable<Path> packagePathRoots) {
- for (Path root : packagePathRoots) {
- if (path.startsWith(root)) {
+ public static RootedPath toRootedPathMaybeUnderRoot(Path path, Iterable<Root> packagePathRoots) {
+ for (Root root : packagePathRoots) {
+ if (root.contains(path)) {
return toRootedPath(root, path);
}
}
- return toRootedPath(path.getFileSystem().getRootDirectory(), path);
+ return toRootedPath(Root.fromFileSystemRoot(path.getFileSystem()), path);
}
public Path asPath() {
@@ -99,7 +95,7 @@
return path;
}
- public Path getRoot() {
+ public Root getRoot() {
return root;
}
@@ -135,11 +131,11 @@
/** Custom serialization for {@link RootedPath}s. */
public static class RootedPathCodec implements ObjectCodec<RootedPath> {
- private final PathCodec pathCodec;
+ private final ObjectCodec<Root> rootCodec;
/** Create an instance which will deserialize RootedPaths on {@code fileSystem}. */
public RootedPathCodec(FileSystem fileSystem) {
- this.pathCodec = new PathCodec(fileSystem);
+ this.rootCodec = Root.getCodec(new PathCodec(fileSystem));
}
@Override
@@ -150,14 +146,14 @@
@Override
public void serialize(RootedPath rootedPath, CodedOutputStream codedOut)
throws IOException, SerializationException {
- pathCodec.serialize(rootedPath.getRoot(), codedOut);
+ rootCodec.serialize(rootedPath.getRoot(), codedOut);
PathFragment.CODEC.serialize(rootedPath.getRelativePath(), codedOut);
}
@Override
public RootedPath deserialize(CodedInputStream codedIn)
throws IOException, SerializationException {
- Path root = pathCodec.deserialize(codedIn);
+ Root root = rootCodec.deserialize(codedIn);
PathFragment relativePath = PathFragment.CODEC.deserialize(codedIn);
return toRootedPath(root, relativePath);
}
diff --git a/src/test/java/com/google/devtools/build/lib/BUILD b/src/test/java/com/google/devtools/build/lib/BUILD
index f3e0f82..d650c9f 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 @@
"//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 8892fcf..15f6bd7 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.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 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 94b1a0f..ab2afc9 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.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 @@
@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 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 @@
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 dfe4e07..5d36934 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.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 @@
@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 @@
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 @@
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 681b2a3..cd47c41 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.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 @@
@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 @@
@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 @@
@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 @@
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 @@
@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 @@
@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 @@
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 @@
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 5227dba..911f690 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.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 @@
@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 @@
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 28da727..b1e63b6 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 @@
@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 @@
@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 @@
@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 c3f8e0f..dd756ca 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.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 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 d39547a..2e0eae4 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.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 @@
.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 f1de38e..491d54e 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.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 @@
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 ec184e8..e31d516 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.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 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 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 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 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 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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
// 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 @@
@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 ed382c4..eca896a 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 @@
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 5a54a9e0..94ac8a8 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 @@
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 a13091d..5bfb86f 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 @@
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 3f6e62d..e8d2af4 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.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 @@
}
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 edd3189..8501af6 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 @@
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 @@
}
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 fdddbee..519807f 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.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 @@
pkgLocator =
new PathPackageLocator(
outputBase,
- ImmutableList.of(rootDirectory),
+ ImmutableList.of(Root.fromPath(rootDirectory)),
BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY);
directories =
new BlazeDirectories(
@@ -335,8 +336,8 @@
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 1a5c6ea..eb91237 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 @@
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 @@
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 e3587cc..d25fb6a 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.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 @@
skyframeExecutor.preparePackageLoading(
new PathPackageLocator(
outputBase,
- ImmutableList.of(rootDirectory),
+ ImmutableList.of(Root.fromPath(rootDirectory)),
BazelSkyframeExecutorConstants.BUILD_FILES_BY_PRIORITY),
packageCacheOptions,
skylarkSemanticsOptions,
@@ -428,8 +429,8 @@
* @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 @@
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 @@
skyframeExecutor.invalidateFilesUnderPathForTesting(
reporter,
new ModifiedFileSet.Builder().modify(PathFragment.create(buildFilePathString)).build(),
- rootDirectory);
+ Root.fromPath(rootDirectory));
return (Rule) getTarget("//" + packageName + ":" + ruleName);
}
@@ -976,7 +977,8 @@
}
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 7953c33..b7dd9ba 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.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 @@
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 8538733..ab550a0 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.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 @@
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 @@
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 @@
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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 a71ba03..73a4a3b 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.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 @@
// 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 9e14fac..f875251 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.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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 @@
@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 af481f8..eb35dd6 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.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 @@
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 @@
*/
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 7ebb3c2..aaf0c5f 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.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 @@
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 184f222..40324ad 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.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 @@
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 6e83bbe..d4373b4 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.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 @@
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 @@
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 @@
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 @@
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 3a4943a..c2180ef 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.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 @@
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 8fd9d55..9134e4d 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.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 @@
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 @@
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 @@
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 13faa5f..1cac353 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.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 @@
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 @@
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 fb8a3cb..f6ec361 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.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 @@
}
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 48953ce..e03f85d 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.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 @@
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 9d1607e..ef89884 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.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 @@
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 37bcf0d..18c5bb4 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.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 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 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 b70d273..ac3c2c8 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.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 @@
.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 703c3ff..3819117 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 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 273d986..6c4a74f 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 @@
@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 08d6f9c..d21acf1 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.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 @@
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 @@
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 @@
/** 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 49d292a..4cc07e2 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.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 @@
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 929531e..c767d51 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.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 @@
@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 b522705..023ce84 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.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 @@
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 b7db0b3..64244a5 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.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 @@
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 @@
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 f122174..9b2e73d 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.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 @@
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 339ad4e..c5abc9e 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.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 @@
}
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 @@
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 375c715..2020506 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.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 @@
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 0728c54..fe2b28c 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.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 @@
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 @@
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 @@
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 @@
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 dee4a46..5dbbaba 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.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 @@
@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 @@
@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 @@
@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 @@
@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 @@
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 0a0b460..d0e33b5 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.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 @@
@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 @@
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 @@
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 @@
}
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 @@
.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 @@
.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 @@
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 @@
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 @@
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 @@
// 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 @@
@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 @@
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 @@
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 811afd1..38bffd7 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 @@
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 @@
@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 2671226..20fadee 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.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 @@
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 @@
}
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 @@
}
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 01ed4fd..851b7a8 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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
@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 3601eaa..e9605e3 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.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 @@
@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 51cf1cf..ed8a74d 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.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 @@
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 @@
}
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 @@
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 @@
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 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 @@
// 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 @@
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 @@
@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 @@
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 a854d2e..2445058 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.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 @@
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 @@
@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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 8773d54..07c7062 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.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 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 @@
.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 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 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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.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 @@
.invalidateFilesUnderPathForTesting(
reporter,
ModifiedFileSet.builder().modify(PathFragment.create("foo/irrelevant")).build(),
- rootDirectory);
+ Root.fromPath(rootDirectory));
assertThat(validPackage(skyKey)).isSameAs(value);
}
@@ -421,7 +423,7 @@
.invalidateFilesUnderPathForTesting(
reporter,
ModifiedFileSet.builder().modify(PathFragment.create("foo/irrelevant")).build(),
- rootDirectory);
+ Root.fromPath(rootDirectory));
assertThat(validPackage(skyKey)).isSameAs(value);
}
@@ -450,10 +452,11 @@
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 @@
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 @@
"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 @@
}
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 @@
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 d9a3f5a..6f34ab6 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.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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 @@
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 @@
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 2f43b7c0..fa745c6 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.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 @@
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 be3b163..49d502b 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.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 @@
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 @@
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 1779162..96fa7e4 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.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 @@
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 @@
}
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 @@
}
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 @@
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 @@
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 f07b6ab..ac45a7e 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.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 @@
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 e205cab..b6bd394 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.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 @@
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 e497ab7..10e9674 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.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 @@
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 @@
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 63e900f..b13b879 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.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 @@
.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 f20cea8..9084371 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.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 @@
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 bbf3489..172ec39 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.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 @@
.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 9d73fc8..03ec708 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.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 @@
.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 1e944d2..75a4888 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.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 @@
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 8595811..27e95b5 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.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 @@
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 @@
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 95e1a62..ece3f59 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.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 @@
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 d5e37ce..95e9e88 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.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 @@
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 63483f5..ec17377 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.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 @@
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 72f657d..be3c0ae 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.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 @@
.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 @@
.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 0000000..c007f4b
--- /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 d84d8b7..6f452c2 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 @@
@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 fb3a9aa..47cb2ed 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.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 @@
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"));
}