-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Canonicalize the label by adding the current module's repo_name if the label doesn't specify a repository name. This is necessary as ModuleExtensionUsages are grouped by the string value of this label, but later mapped to their Label representation. If multiple strings map to the same Label, this would result in a crash. Also enforce that `module()` is called first (if at all). Closes #17920. PiperOrigin-RevId: 520890201 Change-Id: Ice8e2feb0da591e3ba953f4a85284766ba599ebf
- Loading branch information
1 parent
e97f62d
commit dd82239
Showing
4 changed files
with
155 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -473,7 +473,7 @@ public void testModuleExtensions_good() throws Exception { | |
.setRegistry(registry) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionBzlFile("@mymod//:defs.bzl") | ||
.setExtensionName("myext1") | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 2, 23)) | ||
.setImports(ImmutableBiMap.of("repo1", "repo1")) | ||
|
@@ -491,7 +491,7 @@ public void testModuleExtensions_good() throws Exception { | |
.build()) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionBzlFile("@mymod//:defs.bzl") | ||
.setExtensionName("myext2") | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 5, 23)) | ||
.setImports(ImmutableBiMap.of("other_repo1", "repo1", "repo2", "repo2")) | ||
|
@@ -582,7 +582,7 @@ public void testModuleExtensions_duplicateProxy_asRoot() throws Exception { | |
.setKey(ModuleKey.ROOT) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionBzlFile("@//:defs.bzl") | ||
.setExtensionName("myext") | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 1, 23)) | ||
.setImports( | ||
|
@@ -672,7 +672,7 @@ public void testModuleExtensions_duplicateProxy_asDep() throws Exception { | |
.setRegistry(registry) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionBzlFile("@mymod//:defs.bzl") | ||
.setExtensionName("myext") | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 5, 23)) | ||
.setImports(ImmutableBiMap.of("beta", "beta", "delta", "delta")) | ||
|
@@ -956,4 +956,34 @@ public void moduleRepoName_conflict() throws Exception { | |
|
||
assertContainsEvent("The repo name 'bbb' is already being used as the module's own repo name"); | ||
} | ||
|
||
@Test | ||
public void module_calledTwice() throws Exception { | ||
scratch.file( | ||
rootDirectory.getRelative("MODULE.bazel").getPathString(), | ||
"module(name='aaa',version='0.1',repo_name='bbb')", | ||
"module(name='aaa',version='0.1',repo_name='bbb')"); | ||
FakeRegistry registry = registryFactory.newFakeRegistry("/foo"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl())); | ||
|
||
reporter.removeHandler(failFastHandler); // expect failures | ||
evaluator.evaluate(ImmutableList.of(ModuleFileValue.KEY_FOR_ROOT_MODULE), evaluationContext); | ||
|
||
assertContainsEvent("the module() directive can only be called once"); | ||
} | ||
|
||
@Test | ||
public void module_calledLate() throws Exception { | ||
scratch.file( | ||
rootDirectory.getRelative("MODULE.bazel").getPathString(), | ||
"use_extension('//:extensions.bzl', 'my_ext')", | ||
"module(name='aaa',version='0.1',repo_name='bbb')"); | ||
FakeRegistry registry = registryFactory.newFakeRegistry("/foo"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl())); | ||
|
||
reporter.removeHandler(failFastHandler); // expect failures | ||
evaluator.evaluate(ImmutableList.of(ModuleFileValue.KEY_FOR_ROOT_MODULE), evaluationContext); | ||
|
||
assertContainsEvent("if module() is called, it must be called before any other functions"); | ||
} | ||
} |