forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bzlmod: Allow multiple
use_extension
s on the same extension (bazelb…
…uild#14945) Fixes bazelbuild#14635. PiperOrigin-RevId: 432155351
- Loading branch information
Showing
3 changed files
with
87 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -499,21 +499,83 @@ public void testModuleExtensions_good() throws Exception { | |
} | ||
|
||
@Test | ||
public void testModuleExtensions_duplicateProxy() throws Exception { | ||
public void testModuleExtensions_duplicateProxy_asRoot() throws Exception { | ||
scratch.file( | ||
rootDirectory.getRelative("MODULE.bazel").getPathString(), | ||
"myext1 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"use_repo(myext1, 'alpha')", | ||
"myext2 = use_extension('//:defs.bzl','myext')", | ||
"use_repo(myext2, 'beta')", | ||
"myext3 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"use_repo(myext3, 'gamma')", | ||
"myext4 = use_extension('//:defs.bzl','myext')", | ||
"use_repo(myext4, 'delta')"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of()); | ||
|
||
SkyKey skyKey = ModuleFileValue.KEY_FOR_ROOT_MODULE; | ||
EvaluationResult<ModuleFileValue> result = | ||
driver.evaluate(ImmutableList.of(skyKey), evaluationContext); | ||
if (result.hasError()) { | ||
throw result.getError().getException(); | ||
} | ||
ModuleFileValue moduleFileValue = result.get(skyKey); | ||
assertThat(moduleFileValue.getModule()) | ||
.isEqualTo( | ||
Module.builder() | ||
.setKey(ModuleKey.ROOT) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionName("myext") | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 1, 23)) | ||
.setImports( | ||
ImmutableBiMap.of( | ||
"alpha", "alpha", "beta", "beta", "gamma", "gamma", "delta", | ||
"delta")) | ||
.build()) | ||
.build()); | ||
} | ||
|
||
@Test | ||
public void testModuleExtensions_duplicateProxy_asDep() throws Exception { | ||
FakeRegistry registry = | ||
registryFactory | ||
.newFakeRegistry("/foo") | ||
.addModule( | ||
createModuleKey("mymod", "1.0"), | ||
"module(name='mymod',version='1.0')", | ||
"myext1 = use_extension('//:defs.bzl','myext')", | ||
"myext2 = use_extension('//:defs.bzl','myext')"); | ||
"myext1 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"use_repo(myext1, 'alpha')", | ||
"myext2 = use_extension('//:defs.bzl','myext')", | ||
"use_repo(myext2, 'beta')", | ||
"myext3 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"use_repo(myext3, 'gamma')", | ||
"myext4 = use_extension('//:defs.bzl','myext')", | ||
"use_repo(myext4, 'delta')"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl())); | ||
|
||
SkyKey skyKey = ModuleFileValue.key(createModuleKey("mymod", "1.0"), null); | ||
reporter.removeHandler(failFastHandler); // expect failures | ||
driver.evaluate(ImmutableList.of(skyKey), evaluationContext); | ||
assertContainsEvent("this extension is already being used at"); | ||
EvaluationResult<ModuleFileValue> result = | ||
driver.evaluate(ImmutableList.of(skyKey), evaluationContext); | ||
if (result.hasError()) { | ||
throw result.getError().getException(); | ||
} | ||
ModuleFileValue moduleFileValue = result.get(skyKey); | ||
assertThat(moduleFileValue.getModule()) | ||
.isEqualTo( | ||
Module.builder() | ||
.setName("mymod") | ||
.setVersion(Version.parse("1.0")) | ||
.setKey(createModuleKey("mymod", "1.0")) | ||
.setRegistry(registry) | ||
.addExtensionUsage( | ||
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionName("myext") | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 4, 23)) | ||
.setImports(ImmutableBiMap.of("beta", "beta", "delta", "delta")) | ||
.build()) | ||
.build()); | ||
} | ||
|
||
@Test | ||
|