Skip to content

Generates and updates use_repo calls for participating Bazel module extensions

License

Notifications You must be signed in to change notification settings

fmeum/auto_use_repo

Repository files navigation

auto_use_repo

Generates and updates the use_repo calls for participating Bazel module extensions.

Usage for Bazel users

  1. Add a dependency on auto_use_repo in MODULE.bazel:

    bazel_dep(name = "auto_use_repo", version = "<latest release version>", dev_dependency = True)
  2. Update use_repo calls in MODULE.bazel by running:

    bazel run @auto_use_repo//:update

Usage for Bazel module extension authors

  1. Add a dependency on auto_use_repo in MODULE.bazel:

    bazel_dep(name = "auto_use_repo", version = "<latest release version>")
  2. In a module extension, load and instantiate the use_repos repository rule with a list of repositories that the root module should import with use_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 maintain use_repo calls for your module's own usage of my_extension, remember to add the name of the use_repos repo to root_repos if your module is the root module.

  3. Register the JSON file generated by use_repos in MODULE.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",
    )

Participating extensions

About

Generates and updates use_repo calls for participating Bazel module extensions

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published