forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows module extensions to determine whether a given tag represents a dev dependency. Fixes bazelbuild#17101 Work towards bazelbuild#17908
- Loading branch information
Showing
8 changed files
with
133 additions
and
14 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
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 |
---|---|---|
|
@@ -446,7 +446,7 @@ public void multipleModules_devDependency() throws Exception { | |
" data_str = 'modules:'", | ||
" for mod in ctx.modules:", | ||
" for tag in mod.tags.tag:", | ||
" data_str += ' ' + tag.data", | ||
" data_str += ' ' + tag.data + ' ' + str(ctx.is_dev_dependency(tag))", | ||
" data_repo(name='ext_repo',data=data_str)", | ||
"tag=tag_class(attrs={'data':attr.string()})", | ||
"ext=module_extension(implementation=_ext_impl,tag_classes={'tag':tag})"); | ||
|
@@ -457,7 +457,7 @@ public void multipleModules_devDependency() throws Exception { | |
if (result.hasError()) { | ||
throw result.getError().getException(); | ||
} | ||
assertThat(result.get(skyKey).getModule().getGlobal("data")).isEqualTo("modules: root [email protected]"); | ||
assertThat(result.get(skyKey).getModule().getGlobal("data")).isEqualTo("modules: root True [email protected] False"); | ||
} | ||
|
||
@Test | ||
|
@@ -497,7 +497,7 @@ public void multipleModules_ignoreDevDependency() throws Exception { | |
" data_str = 'modules:'", | ||
" for mod in ctx.modules:", | ||
" for tag in mod.tags.tag:", | ||
" data_str += ' ' + tag.data", | ||
" data_str += ' ' + tag.data + ' ' + str(ctx.is_dev_dependency(tag))", | ||
" data_repo(name='ext_repo',data=data_str)", | ||
"tag=tag_class(attrs={'data':attr.string()})", | ||
"ext=module_extension(implementation=_ext_impl,tag_classes={'tag':tag})"); | ||
|
@@ -511,7 +511,7 @@ public void multipleModules_ignoreDevDependency() throws Exception { | |
if (result.hasError()) { | ||
throw result.getError().getException(); | ||
} | ||
assertThat(result.get(skyKey).getModule().getGlobal("data")).isEqualTo("modules: [email protected]"); | ||
assertThat(result.get(skyKey).getModule().getGlobal("data")).isEqualTo("modules: [email protected] False"); | ||
} | ||
|
||
@Test | ||
|
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 |
---|---|---|
|
@@ -484,6 +484,7 @@ public void testModuleExtensions_good() throws Exception { | |
Dict.<String, Object>builder() | ||
.put("key", "val") | ||
.buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation( | ||
Location.fromFileLineColumn("[email protected]/MODULE.bazel", 4, 11)) | ||
.build()) | ||
|
@@ -501,6 +502,7 @@ public void testModuleExtensions_good() throws Exception { | |
Dict.<String, Object>builder() | ||
.put("key1", "val1") | ||
.buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation( | ||
Location.fromFileLineColumn("[email protected]/MODULE.bazel", 7, 12)) | ||
.build()) | ||
|
@@ -511,6 +513,7 @@ public void testModuleExtensions_good() throws Exception { | |
Dict.<String, Object>builder() | ||
.put("key2", "val2") | ||
.buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation( | ||
Location.fromFileLineColumn("[email protected]/MODULE.bazel", 8, 12)) | ||
.build()) | ||
|
@@ -529,6 +532,7 @@ public void testModuleExtensions_good() throws Exception { | |
Dict.<String, Object>builder() | ||
.put("coord", "junit") | ||
.buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation( | ||
Location.fromFileLineColumn("[email protected]/MODULE.bazel", 12, 10)) | ||
.build()) | ||
|
@@ -539,6 +543,7 @@ public void testModuleExtensions_good() throws Exception { | |
Dict.<String, Object>builder() | ||
.put("coord", "guava") | ||
.buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation( | ||
Location.fromFileLineColumn("[email protected]/MODULE.bazel", 14, 10)) | ||
.build()) | ||
|
@@ -551,12 +556,16 @@ public void testModuleExtensions_duplicateProxy_asRoot() throws Exception { | |
scratch.file( | ||
rootDirectory.getRelative("MODULE.bazel").getPathString(), | ||
"myext1 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"myext1.tag(name = 'tag1')", | ||
"use_repo(myext1, 'alpha')", | ||
"myext2 = use_extension('//:defs.bzl','myext')", | ||
"myext2.tag(name = 'tag2')", | ||
"use_repo(myext2, 'beta')", | ||
"myext3 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"myext3.tag(name = 'tag3')", | ||
"use_repo(myext3, 'gamma')", | ||
"myext4 = use_extension('//:defs.bzl','myext')", | ||
"myext4.tag(name = 'tag4')", | ||
"use_repo(myext4, 'delta')"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of()); | ||
|
||
|
@@ -580,6 +589,34 @@ public void testModuleExtensions_duplicateProxy_asRoot() throws Exception { | |
ImmutableBiMap.of( | ||
"alpha", "alpha", "beta", "beta", "gamma", "gamma", "delta", | ||
"delta")) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag1").buildImmutable()) | ||
.setDevDependency(true) | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 2, 11)) | ||
.build()) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag2").buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 5, 11)) | ||
.build()) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag3").buildImmutable()) | ||
.setDevDependency(true) | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 8, 11)) | ||
.build()) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag4").buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation(Location.fromFileLineColumn("<root>/MODULE.bazel", 11, 11)) | ||
.build()) | ||
.build()) | ||
.build()); | ||
} | ||
|
@@ -593,12 +630,16 @@ public void testModuleExtensions_duplicateProxy_asDep() throws Exception { | |
createModuleKey("mymod", "1.0"), | ||
"module(name='mymod',version='1.0')", | ||
"myext1 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"myext1.tag(name = 'tag1')", | ||
"use_repo(myext1, 'alpha')", | ||
"myext2 = use_extension('//:defs.bzl','myext')", | ||
"myext2.tag(name = 'tag2')", | ||
"use_repo(myext2, 'beta')", | ||
"myext3 = use_extension('//:defs.bzl','myext',dev_dependency=True)", | ||
"myext3.tag(name = 'tag3')", | ||
"use_repo(myext3, 'gamma')", | ||
"myext4 = use_extension('//:defs.bzl','myext')", | ||
"myext4.tag(name = 'tag4')", | ||
"use_repo(myext4, 'delta')"); | ||
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl())); | ||
|
||
|
@@ -617,8 +658,22 @@ public void testModuleExtensions_duplicateProxy_asDep() throws Exception { | |
ModuleExtensionUsage.builder() | ||
.setExtensionBzlFile("//:defs.bzl") | ||
.setExtensionName("myext") | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 4, 23)) | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 5, 23)) | ||
.setImports(ImmutableBiMap.of("beta", "beta", "delta", "delta")) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag2").buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 6, 11)) | ||
.build()) | ||
.addTag(Tag.builder() | ||
.setTagName("tag") | ||
.setAttributeValues( | ||
Dict.<String, Object>builder().put("name", "tag4").buildImmutable()) | ||
.setDevDependency(false) | ||
.setLocation(Location.fromFileLineColumn("[email protected]/MODULE.bazel", 12, 11)) | ||
.build()) | ||
.build()) | ||
.build()); | ||
} | ||
|
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