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/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);
}
/**