diff options
author | 2017-07-11 18:12:55 +0200 | |
---|---|---|
committer | 2017-07-11 18:26:24 +0200 | |
commit | 937350211dcd55a4714ec32ebbf33fffcc42cdf2 (patch) | |
tree | 77f2cb3d5b6c4fe1e66691a3f0bc4041593168c4 /src/main/java/com/google/devtools/build/lib/packages | |
parent | a334363a500fb9df953fe2c70184ee013ff77ccb (diff) |
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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/packages')
3 files changed, 9 insertions, 27 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/Package.java b/src/main/java/com/google/devtools/build/lib/packages/Package.java index 4ec65dd3b0..9132208b0e 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/Package.java +++ b/src/main/java/com/google/devtools/build/lib/packages/Package.java @@ -207,9 +207,13 @@ public class Package { * @precondition {@code name} must be a suffix of * {@code filename.getParentDirectory())}. */ - protected Package(PackageIdentifier packageId, String runfilesPrefix) { - this.packageIdentifier = packageId; - this.workspaceName = runfilesPrefix; + protected Package(PackageIdentifier packageId, String workspaceName) { + this.workspaceName = workspaceName; + if (workspaceName.equals(packageId.getRepository().strippedName())) { + this.packageIdentifier = PackageIdentifier.createInMainRepo(packageId.getPackageFragment()); + } else { + this.packageIdentifier = packageId; + } this.nameFragment = Canonicalizer.fragments().intern(packageId.getPackageFragment()); this.name = nameFragment.getPathString(); } @@ -300,7 +304,6 @@ public class Package { throw new IllegalArgumentException( "Invalid BUILD file name for package '" + packageIdentifier + "': " + filename); } - this.makeEnv = builder.makeEnv.build(); this.targets = ImmutableSortedKeyMap.copyOf(builder.targets); this.defaultVisibility = builder.defaultVisibility; diff --git a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java index cab4a4f6d6..da4d3e3163 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/PackageFactory.java @@ -1667,7 +1667,7 @@ public final class PackageFactory { ImmutableList<Label> skylarkFileDependencies) throws InterruptedException { Package.Builder pkgBuilder = new Package.Builder(packageBuilderHelper.createFreshPackage( - packageId, ruleClassProvider.getRunfilesPrefix())); + packageId, workspaceName)); StoredEventHandler eventHandler = new StoredEventHandler(); try (Mutability mutability = Mutability.create("package %s", packageId)) { @@ -1687,8 +1687,7 @@ public final class PackageFactory { // "defaultVisibility" comes from the command line. Let's give the BUILD file a chance to // set default_visibility once, be reseting the PackageBuilder.defaultVisibilitySet flag. .setDefaultVisibilitySet(false) - .setSkylarkFileDependencies(skylarkFileDependencies) - .setWorkspaceName(workspaceName); + .setSkylarkFileDependencies(skylarkFileDependencies); Event.replayEventsOn(eventHandler, pastEvents); for (Postable post : pastPosts) { diff --git a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java index ccb81e1201..f1c25777f6 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java +++ b/src/main/java/com/google/devtools/build/lib/packages/WorkspaceFactory.java @@ -28,7 +28,6 @@ import com.google.devtools.build.lib.events.NullEventHandler; import com.google.devtools.build.lib.events.StoredEventHandler; import com.google.devtools.build.lib.packages.Package.NameConflictException; import com.google.devtools.build.lib.packages.PackageFactory.EnvironmentExtension; -import com.google.devtools.build.lib.packages.RuleFactory.InvalidRuleException; import com.google.devtools.build.lib.skylarkinterface.Param; import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature; import com.google.devtools.build.lib.syntax.BaseFunction; @@ -316,25 +315,6 @@ public class WorkspaceFactory { throw new EvalException(ast.getLocation(), errorMessage); } PackageFactory.getContext(env, ast).pkgBuilder.setWorkspaceName(name); - Package.Builder builder = PackageFactory.getContext(env, ast).pkgBuilder; - RuleClass localRepositoryRuleClass = ruleFactory.getRuleClass("local_repository"); - RuleClass bindRuleClass = ruleFactory.getRuleClass("bind"); - Map<String, Object> kwargs = ImmutableMap.<String, Object>of( - "name", name, "path", "."); - try { - // This effectively adds a "local_repository(name = "<ws>", path = ".")" - // definition to the WORKSPACE file. - builder - .externalPackageData() - .createAndAddRepositoryRule( - builder, - localRepositoryRuleClass, - bindRuleClass, - kwargs, - ast); - } catch (InvalidRuleException | NameConflictException | LabelSyntaxException e) { - throw new EvalException(ast.getLocation(), e.getMessage()); - } return NONE; } }; |