From 937350211dcd55a4714ec32ebbf33fffcc42cdf2 Mon Sep 17 00:00:00 2001 From: kchodorow Date: Tue, 11 Jul 2017 18:12:55 +0200 Subject: Resolve references to @main-repo//foo to //foo Bazel was creating an dummy external repository for @main-repo, which doesn't work with package paths and will cause conflicts once @main-repo//foo and //foo refer to the same path. This adds a "soft pull" option to WorkspaceNameFunction: it can either parse the entire WORKSPACE file to find the name or just the first section. That way PackageLookupFunction can find the repository name without causing a circular dependency. This should have no change of behavior and is already tested in https://github.com/bazelbuild/bazel/blob/master/src/test/shell/bazel/workspace_test.sh#L176. PiperOrigin-RevId: 161536466 --- .../build/lib/skyframe/PackageLookupFunction.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java') diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java index c0a115ad6c..d264cea205 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/PackageLookupFunction.java @@ -18,6 +18,7 @@ import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.cmdline.Label; import com.google.devtools.build.lib.cmdline.LabelValidator; import com.google.devtools.build.lib.cmdline.PackageIdentifier; +import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.packages.BuildFileNotFoundException; import com.google.devtools.build.lib.packages.ErrorDeterminingRepositoryException; import com.google.devtools.build.lib.packages.NoSuchPackageException; @@ -294,8 +295,20 @@ public class PackageLookupFunction implements SkyFunction { private PackageLookupValue computeExternalPackageLookupValue( SkyKey skyKey, Environment env, PackageIdentifier packageIdentifier) throws PackageLookupFunctionException, InterruptedException { + // Check if this is the main repository. PackageIdentifier id = (PackageIdentifier) skyKey.argument(); - SkyKey repositoryKey = RepositoryValue.key(id.getRepository()); + RepositoryName repositoryName = id.getRepository(); + WorkspaceNameValue workspaceNameValue = (WorkspaceNameValue) + env.getValue(WorkspaceNameValue.firstChunk()); + if (workspaceNameValue == null) { + return null; + } + if (repositoryName.strippedName().equals(workspaceNameValue.getName())) { + return (PackageLookupValue) env.getValue(PackageLookupValue.key( + PackageIdentifier.createInMainRepo(id.getPackageFragment()))); + } + // Otherwise look up the repository. + SkyKey repositoryKey = RepositoryValue.key(repositoryName); RepositoryValue repositoryValue; try { repositoryValue = (RepositoryValue) env.getValueOrThrow( -- cgit v1.2.3