aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/pkgcache
diff options
context:
space:
mode:
authorGravatar janakr <janakr@google.com>2017-12-06 09:10:05 -0800
committerGravatar Copybara-Service <copybara-piper@google.com>2017-12-06 09:12:13 -0800
commitc6b291e17f90d82cdc4610bdf6cbecc568d1ebda (patch)
tree09631c988d0dcec956f2c885be261a0a02b71698 /src/main/java/com/google/devtools/build/lib/pkgcache
parent7e8cb5482749a222717a89c12b21c256b632bc84 (diff)
Expose utility method in PathPackageLocator for inserting workspace name.
PiperOrigin-RevId: 178105914
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/pkgcache')
-rw-r--r--src/main/java/com/google/devtools/build/lib/pkgcache/PathPackageLocator.java20
1 files changed, 14 insertions, 6 deletions
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 eb6eda4ec7..94694c1335 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
@@ -45,6 +45,8 @@ import java.util.concurrent.atomic.AtomicReference;
* filesystem) idempotent.
*/
public class PathPackageLocator implements Serializable {
+ private static final String WORKSPACE_WILDCARD = "%workspace%";
+
private final ImmutableList<Path> 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.
@@ -144,6 +146,9 @@ public class PathPackageLocator implements Serializable {
return "PathPackageLocator" + pathEntries;
}
+ public static String maybeReplaceWorkspaceInString(String pathElement, Path workspace) {
+ return pathElement.replace(WORKSPACE_WILDCARD, workspace.getPathString());
+ }
/**
* A factory of PathPackageLocators from a list of path elements. Elements may contain
* "%workspace%", indicating the workspace.
@@ -225,11 +230,10 @@ public class PathPackageLocator implements Serializable {
List<BuildFileName> buildFilesByPriority,
boolean checkExistence) {
List<Path> resolvedPaths = new ArrayList<>();
- final String workspaceWildcard = "%workspace%";
for (String pathElement : pathElements) {
// Replace "%workspace%" with the path of the enclosing workspace directory.
- pathElement = pathElement.replace(workspaceWildcard, workspace.getPathString());
+ pathElement = maybeReplaceWorkspaceInString(pathElement, workspace);
PathFragment pathElementFragment = PathFragment.create(pathElement);
@@ -239,10 +243,14 @@ public class PathPackageLocator implements Serializable {
if (!pathElementFragment.isAbsolute() && !clientWorkingDirectory.equals(workspace)) {
eventHandler.handle(
- Event.warn("The package path element '" + pathElementFragment + "' will be "
- + "taken relative to your working directory. You may have intended "
- + "to have the path taken relative to your workspace directory. "
- + "If so, please use the '" + workspaceWildcard + "' wildcard."));
+ Event.warn(
+ "The package path element '"
+ + pathElementFragment
+ + "' will be taken relative to your working directory. You may have intended to"
+ + " have the path taken relative to your workspace directory. If so, please use"
+ + "the '"
+ + WORKSPACE_WILDCARD
+ + "' wildcard."));
}
if (!checkExistence || rootPath.exists()) {