diff options
author | 2017-09-05 18:31:10 +0200 | |
---|---|---|
committer | 2017-09-06 10:10:09 +0200 | |
commit | e0dfb3c3d70efc49c703be7e4c8e93c8a6b38d6b (patch) | |
tree | de98ba794d396262407e19b2bb6a08580b9a4dd0 /src | |
parent | 268c0bcbf79f9f3f72d95fa51af0f1b18c5ce29e (diff) |
Update LocalRepositoryLookupFunction to also return the path of the
repository.
Part of #3553.
Change-Id: Id8b4958844b2ad7b5ce4b2ea00a91b6b22acc025
PiperOrigin-RevId: 167589110
Diffstat (limited to 'src')
3 files changed, 41 insertions, 4 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 3c0382e600..8b618f4ec7 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 @@ -218,8 +218,11 @@ public class LocalRepositoryLookupFunction implements SkyFunction { null); if (rule != null) { try { + String path = (String) rule.getAttributeContainer().getAttr("path"); return Optional.of( - LocalRepositoryLookupValue.success(RepositoryName.create("@" + rule.getName()))); + LocalRepositoryLookupValue.success( + RepositoryName.create("@" + rule.getName()), + PathFragment.create(path).normalize())); } catch (LabelSyntaxException e) { // This shouldn't be possible if the rule name is valid, and it should already have been // validated. diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java index b2a0c548e1..0bdf7ab2b6 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/LocalRepositoryLookupValue.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.skyframe; import com.google.devtools.build.lib.cmdline.RepositoryName; +import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.RootedPath; import com.google.devtools.build.skyframe.LegacySkyKey; import com.google.devtools.build.skyframe.SkyKey; @@ -39,8 +40,9 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { return MAIN_REPO_VALUE; } - public static LocalRepositoryLookupValue success(RepositoryName repositoryName) { - return new SuccessfulLocalRepositoryLookupValue(repositoryName); + public static LocalRepositoryLookupValue success( + RepositoryName repositoryName, PathFragment path) { + return new SuccessfulLocalRepositoryLookupValue(repositoryName, path); } public static LocalRepositoryLookupValue notFound() { @@ -60,6 +62,12 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { */ public abstract RepositoryName getRepository(); + /** + * Returns the path to the local repository, or throws a {@link IllegalStateException} if there + * was no repository found. + */ + public abstract PathFragment getPath(); + /** Represents a successful lookup of the main repository. */ public static final class MainRepositoryLookupValue extends LocalRepositoryLookupValue { @@ -77,6 +85,11 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { } @Override + public PathFragment getPath() { + return PathFragment.EMPTY_FRAGMENT; + } + + @Override public String toString() { return "MainRepositoryLookupValue"; } @@ -97,9 +110,11 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { public static final class SuccessfulLocalRepositoryLookupValue extends LocalRepositoryLookupValue { private final RepositoryName repositoryName; + private final PathFragment path; - public SuccessfulLocalRepositoryLookupValue(RepositoryName repositoryName) { + public SuccessfulLocalRepositoryLookupValue(RepositoryName repositoryName, PathFragment path) { this.repositoryName = repositoryName; + this.path = path; } @Override @@ -113,6 +128,11 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { } @Override + public PathFragment getPath() { + return path; + } + + @Override public String toString() { return "SuccessfulLocalRepositoryLookupValue(" + repositoryName + ")"; } @@ -149,6 +169,11 @@ public abstract class LocalRepositoryLookupValue implements SkyValue { } @Override + public PathFragment getPath() { + throw new IllegalStateException("Repository was not found"); + } + + @Override public String toString() { return "NotFoundLocalRepositoryLookupValue"; } 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 12230c48d9..610eb728ef 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 @@ -139,6 +139,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.EMPTY_FRAGMENT)); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); } @Test @@ -149,6 +150,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("some/path"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); } @Test @@ -161,6 +163,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); } @Test @@ -175,6 +178,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { 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")); } @Test @@ -187,6 +191,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); } @Test @@ -201,6 +206,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { 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")); } @Test @@ -215,6 +221,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo/sub/package"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository().getName()).isEqualTo("@local"); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.create("local/repo")); } @Test @@ -227,6 +234,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { lookupDirectory(RootedPath.toRootedPath(rootDirectory, PathFragment.create("local/repo"))); assertThat(repositoryLookupValue).isNotNull(); assertThat(repositoryLookupValue.getRepository()).isEqualTo(RepositoryName.MAIN); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); } @Test @@ -265,6 +273,7 @@ public class LocalRepositoryLookupFunctionTest extends FoundationTestCase { 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); + assertThat(repositoryLookupValue.getPath()).isEqualTo(PathFragment.EMPTY_FRAGMENT); } // TODO(katre): Add tests for the following exceptions |