aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java7
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunctionTest.java40
2 files changed, 45 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
index 732620342d..3c0382e600 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupFunction.java
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.repository.LocalRepositoryRule;
import com.google.devtools.build.lib.skyframe.PackageFunction.PackageFunctionException;
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.RootedPath;
import com.google.devtools.build.skyframe.SkyFunction;
@@ -208,8 +209,10 @@ public class LocalRepositoryLookupFunction implements SkyFunction {
@Override
public boolean apply(@Nullable Rule rule) {
AggregatingAttributeMapper mapper = AggregatingAttributeMapper.of(rule);
- PathFragment pathAttr = PathFragment.create(mapper.get("path", Type.STRING));
- return directory.getRelativePath().equals(pathAttr);
+ // Construct the path. If not absolute, it will be relative to the workspace.
+ Path localPath =
+ workspacePath.getRoot().getRelative(mapper.get("path", Type.STRING));
+ return directory.asPath().equals(localPath);
}
},
null);
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 c8c5bae031..12230c48d9 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
@@ -164,6 +164,46 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase {
}
@Test
+ public void testLocalRepository_absolutePath() throws Exception {
+ scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='/abs/local/repo')");
+ scratch.file("/abs/local/repo/WORKSPACE");
+ scratch.file("/abs/local/repo/BUILD");
+
+ LocalRepositoryLookupValue repositoryLookupValue =
+ lookupDirectory(
+ RootedPath.toRootedPath(
+ rootDirectory.getRelative("/abs"), PathFragment.create("local/repo")));
+ assertThat(repositoryLookupValue).isNotNull();
+ assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local");
+ }
+
+ @Test
+ public void testLocalRepository_nonNormalizedPath() throws Exception {
+ scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='./local/repo')");
+ scratch.file("local/repo/WORKSPACE");
+ scratch.file("local/repo/BUILD");
+
+ LocalRepositoryLookupValue repositoryLookupValue =
+ lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo")));
+ assertThat(repositoryLookupValue).isNotNull();
+ assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local");
+ }
+
+ @Test
+ public void testLocalRepository_absolutePath_nonNormalized() throws Exception {
+ scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='/abs/local/./repo')");
+ scratch.file("/abs/local/repo/WORKSPACE");
+ scratch.file("/abs/local/repo/BUILD");
+
+ LocalRepositoryLookupValue repositoryLookupValue =
+ lookupDirectory(
+ RootedPath.toRootedPath(
+ rootDirectory.getRelative("/abs"), PathFragment.create("local/repo")));
+ assertThat(repositoryLookupValue).isNotNull();
+ assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local");
+ }
+
+ @Test
public void testLocalRepositorySubPackage() throws Exception {
scratch.overwriteFile("WORKSPACE", "local_repository(name='local', path='local/repo')");
scratch.file("local/repo/WORKSPACE");