diff options
author | tomlu <tomlu@google.com> | 2018-01-17 14:36:26 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-01-17 14:37:59 -0800 |
commit | ee6a6862e26704854fb08bd90912890814cc3426 (patch) | |
tree | 294eac82202e393c5baae0e357325f2488ab3cbb /src/main/java/com/google/devtools/build/lib/rules/repository | |
parent | f323fb3043bc782526e0e47933efedea9c5c2ad9 (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/repository')
4 files changed, 17 insertions, 9 deletions
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 9811287cb9..9021546d65 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.skyframe.InconsistentFilesystemException; 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 @@ public class NewLocalRepositoryFunction extends RepositoryFunction { 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 7d93da6f98..14efd5e10b 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.EvalException; 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 @@ public class NewRepositoryFileHandler { } // 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 @@ public class NewRepositoryFileHandler { 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 0cf44e6edd..024287deb3 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.syntax.Type; 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 @@ public abstract class RepositoryFunction { 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 @@ public abstract class RepositoryFunction { } // And now for the file - Path packageRoot = pkgLookupValue.getRoot(); + Root packageRoot = pkgLookupValue.getRoot(); return RootedPath.toRootedPath(packageRoot, label.toPathFragment()); } @@ -473,8 +474,10 @@ public abstract class RepositoryFunction { @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 ad0e5abb15..f2cda7aa7d 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.RepositoryValue; 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 @@ public class RepositoryLoaderFunction implements SkyFunction { 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; |