Skip to content

Commit 8e5cfdc

Browse files
authored
feat: return bzlmod extension metadata for declared repositories (#237)
- Update `bazel_binaries` extension to return metadata listing the declared repositories. - Update `custom_test_runner` test to properly declare its repositories. Closes #235.
1 parent 32eadb6 commit 8e5cfdc

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

MODULE.bazel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ bazel_binaries = use_extension(
1919
)
2020
bazel_binaries.download(version_file = "//:.bazelversion")
2121
bazel_binaries.download(version = "6.4.0")
22-
use_repo(bazel_binaries, "bazel_binaries")
22+
use_repo(
23+
bazel_binaries,
24+
"bazel_binaries",
25+
"bazel_binaries_bazelisk",
26+
"build_bazel_bazel_.bazelversion",
27+
"build_bazel_bazel_6_4_0",
28+
)
2329

2430
download_sample_file = use_extension(
2531
"//examples/env_var_with_rootpath:sample_file_extension.bzl",

MODULE.bazel.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bazel_integration_test/bzlmod/bazel_binaries.bzl

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,35 @@ version, version_file.\
131131
_BAZELISK_VERSION = "1.18.0"
132132

133133
def _bazel_binaries_impl(module_ctx):
134+
dep_names = []
135+
dev_dep_names = []
136+
137+
def _add_dep_name(name, is_dev_dependency):
138+
if is_dev_dependency:
139+
dev_dep_names.append(name)
140+
else:
141+
dep_names.append(name)
142+
143+
ext_is_dev_dep = not module_ctx.root_module_has_non_dev_dependency
144+
134145
# Create a repository for the bazelisk binary.
135146
bazelisk_repo_name = "bazel_binaries_bazelisk"
136147
_bazelisk_binary_repo_rule(
137148
name = bazelisk_repo_name,
138149
version = _BAZELISK_VERSION,
139150
)
151+
_add_dep_name(bazelisk_repo_name, is_dev_dependency = ext_is_dev_dep)
140152

141153
# Create version-specific bazel repos.
142154
version_infos = []
143155
for mod in module_ctx.modules:
144156
for download in mod.tags.download:
145157
vi = _declare_bazel_binary(download, bazelisk_repo_name)
146158
version_infos.append(vi)
159+
_add_dep_name(
160+
vi.repo_name,
161+
is_dev_dependency = module_ctx.is_dev_dependency(download),
162+
)
147163

148164
if len(version_infos) == 0:
149165
fail("No versions were specified.")
@@ -158,11 +174,18 @@ def _bazel_binaries_impl(module_ctx):
158174
if current_vi == None:
159175
current_vi = version_infos[0]
160176

177+
bazel_binaries_repo_name = "bazel_binaries"
161178
_bazel_binaries_helper(
162-
name = "bazel_binaries",
179+
name = bazel_binaries_repo_name,
163180
version_to_repo = version_to_repo,
164181
current_version = current_vi.version,
165182
)
183+
_add_dep_name(bazel_binaries_repo_name, is_dev_dependency = ext_is_dev_dep)
184+
185+
return module_ctx.extension_metadata(
186+
root_module_direct_deps = dep_names,
187+
root_module_direct_dev_deps = dev_dep_names,
188+
)
166189

167190
_download_tag = tag_class(
168191
attrs = {

examples/custom_test_runner/MODULE.bazel

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ bazel_binaries = use_extension(
3434
dev_dependency = True,
3535
)
3636
bazel_binaries.download(version_file = "//:.bazelversion")
37-
use_repo(bazel_binaries, "bazel_binaries")
37+
use_repo(
38+
bazel_binaries,
39+
"bazel_binaries",
40+
"bazel_binaries_bazelisk",
41+
"build_bazel_bazel_.bazelversion",
42+
)
3843

3944
# swift_deps START
4045
swift_deps = use_extension(

0 commit comments

Comments
 (0)