forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add is_root struct field to bazel_module (bazelbuild#15815)
This allows module extensions to check whether a given module is the root module, which is necessary to implement the analogues of --check_direct_dependencies and archive_override/git_override for dependencies managed by extensions. Closes bazelbuild#15792. PiperOrigin-RevId: 459058350 Change-Id: I4a08ce80a636e2cb2791323476fdccddf4131de0 Co-authored-by: Fabian Meumertzheim <[email protected]>
- Loading branch information
Showing
2 changed files
with
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,6 +314,7 @@ public void simpleExtension() throws Exception { | |
public void multipleModules() throws Exception { | ||
scratch.file( | ||
workspaceRoot.getRelative("MODULE.bazel").getPathString(), | ||
"module(name='root',version='1.0')", | ||
"bazel_dep(name='ext',version='1.0')", | ||
"bazel_dep(name='foo',version='1.0')", | ||
"bazel_dep(name='bar',version='2.0')", | ||
|
@@ -363,10 +364,12 @@ public void multipleModules() throws Exception { | |
modulesRoot.getRelative("ext.1.0/defs.bzl").getPathString(), | ||
"load('@data_repo//:defs.bzl','data_repo')", | ||
"def _ext_impl(ctx):", | ||
" data_str = 'modules:'", | ||
" data_str = ''", | ||
" for mod in ctx.modules:", | ||
" data_str += mod.name + '@' + mod.version + (' (root): ' if mod.is_root else ': ')", | ||
" for tag in mod.tags.tag:", | ||
" data_str += ' ' + tag.data", | ||
" data_str += tag.data", | ||
" data_str += '\\n'", | ||
" 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})"); | ||
|
@@ -378,7 +381,8 @@ public void multipleModules() throws Exception { | |
throw result.getError().getException(); | ||
} | ||
assertThat(result.get(skyKey).getModule().getGlobal("data")) | ||
.isEqualTo("modules: root [email protected] [email protected] [email protected]"); | ||
.isEqualTo( | ||
"[email protected] (root): root\n[email protected]: [email protected]\n[email protected]: [email protected]\n[email protected]: [email protected]\n"); | ||
} | ||
|
||
@Test | ||
|