Skip to content

Commit

Permalink
feat: return bzlmod extension metadata for declared repositories (#237)
Browse files Browse the repository at this point in the history
- Update `bazel_binaries` extension to return metadata listing the
declared repositories.
- Update `custom_test_runner` test to properly declare its repositories.

Closes #235.
  • Loading branch information
cgrindel authored Oct 30, 2023
1 parent 32eadb6 commit 8e5cfdc
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
8 changes: 7 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ bazel_binaries = use_extension(
)
bazel_binaries.download(version_file = "//:.bazelversion")
bazel_binaries.download(version = "6.4.0")
use_repo(bazel_binaries, "bazel_binaries")
use_repo(
bazel_binaries,
"bazel_binaries",
"bazel_binaries_bazelisk",
"build_bazel_bazel_.bazelversion",
"build_bazel_bazel_6_4_0",
)

download_sample_file = use_extension(
"//examples/env_var_with_rootpath:sample_file_extension.bzl",
Expand Down
12 changes: 11 additions & 1 deletion MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 24 additions & 1 deletion bazel_integration_test/bzlmod/bazel_binaries.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -131,19 +131,35 @@ version, version_file.\
_BAZELISK_VERSION = "1.18.0"

def _bazel_binaries_impl(module_ctx):
dep_names = []
dev_dep_names = []

def _add_dep_name(name, is_dev_dependency):
if is_dev_dependency:
dev_dep_names.append(name)
else:
dep_names.append(name)

ext_is_dev_dep = not module_ctx.root_module_has_non_dev_dependency

# Create a repository for the bazelisk binary.
bazelisk_repo_name = "bazel_binaries_bazelisk"
_bazelisk_binary_repo_rule(
name = bazelisk_repo_name,
version = _BAZELISK_VERSION,
)
_add_dep_name(bazelisk_repo_name, is_dev_dependency = ext_is_dev_dep)

# Create version-specific bazel repos.
version_infos = []
for mod in module_ctx.modules:
for download in mod.tags.download:
vi = _declare_bazel_binary(download, bazelisk_repo_name)
version_infos.append(vi)
_add_dep_name(
vi.repo_name,
is_dev_dependency = module_ctx.is_dev_dependency(download),
)

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

bazel_binaries_repo_name = "bazel_binaries"
_bazel_binaries_helper(
name = "bazel_binaries",
name = bazel_binaries_repo_name,
version_to_repo = version_to_repo,
current_version = current_vi.version,
)
_add_dep_name(bazel_binaries_repo_name, is_dev_dependency = ext_is_dev_dep)

return module_ctx.extension_metadata(
root_module_direct_deps = dep_names,
root_module_direct_dev_deps = dev_dep_names,
)

_download_tag = tag_class(
attrs = {
Expand Down
7 changes: 6 additions & 1 deletion examples/custom_test_runner/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ bazel_binaries = use_extension(
dev_dependency = True,
)
bazel_binaries.download(version_file = "//:.bazelversion")
use_repo(bazel_binaries, "bazel_binaries")
use_repo(
bazel_binaries,
"bazel_binaries",
"bazel_binaries_bazelisk",
"build_bazel_bazel_.bazelversion",
)

# swift_deps START
swift_deps = use_extension(
Expand Down

0 comments on commit 8e5cfdc

Please sign in to comment.