Generates and updates the use_repo
calls for participating Bazel module extensions.
-
Add a dependency on
auto_use_repo
inMODULE.bazel
:bazel_dep(name = "auto_use_repo", version = "<latest release version>", dev_dependency = True)
-
Update
use_repo
calls inMODULE.bazel
by running:bazel run @auto_use_repo//:update
-
Add a dependency on
auto_use_repo
inMODULE.bazel
:bazel_dep(name = "auto_use_repo", version = "<latest release version>")
-
In a module extension, load and instantiate the
use_repos
repository rule with a list of repositories that the root module should import withuse_repo
:load("@auto_use_repo//:repositories.bzl", "use_repos") def my_extension_impl(module_ctx): root_repos = [] for module in module_ctx.modules: ... if module.is_root: root_repos.append(...) ... use_repos( name = "internal_auto_use_repos", root_repos = root_repos, ) my_extension = module_extension( implementation = my_extension_impl, )
If you also want to use
auto_use_repo
to maintainuse_repo
calls for your module's own usage ofmy_extension
, remember to add the name of theuse_repos
repo toroot_repos
if your module is the root module. -
Register the JSON file generated by
use_repos
inMODULE.bazel
:my_extension = use_extension("//:extensions.bzl", "my_extension") ... use_repo(my_extension, "internal_auto_use_repos") auto_use_repo = use_extension("@auto_use_repo//:extensions.bzl", "auto_use_repo") auto_use_repo.register( extension_bzl_file = "//:extensions.bzl", extension_name = "my_extension", repositories_json_file = "@internal_auto_use_repos//:repositories.json", )