2
0
Fork 0
mirror of https://github.com/bazelbuild/bazel-skylib synced 2024-11-28 08:43:51 +00:00
bazel-skylib/docs/modules_doc.md
Fabian Meumertzheim 553c08dc60
Add helper functions for module extensions as modules (#456)
Adds a new module `modules` with two helper functions for module
extensions:

* `use_all_repos` makes it easy to return an appropriate
  `extension_metadata` from a module extension (if supported) to
  indicate that all repositories generated by the extension should be
  imported via `use_repo`.
* `as_extension` turns a WORKSPACE macro into a module extension that
  uses `use_all_repos` to automate the generation of `use_repo` calls.
2024-04-24 14:53:32 -04:00

2.5 KiB
Executable file

Skylib module containing utilities for Bazel modules and module extensions.

modules.as_extension

modules.as_extension(macro, doc)

Wraps a WORKSPACE dependency macro into a module extension.

Example:

def rules_foo_deps(optional_arg = True):
    some_repo_rule(name = "foobar")
    http_archive(name = "bazqux")

rules_foo_deps_ext = modules.as_extension(rules_foo_deps)

PARAMETERS

Name Description Default Value
macro A WORKSPACE dependency macro, i.e., a function with no required parameters that instantiates one or more repository rules. none
doc A description of the module extension that can be extracted by documentation generating tools. None

RETURNS

A module extension that generates the repositories instantiated by the given macro and also uses use_all_repos to indicate that all of those repositories should be imported via use_repo.

modules.use_all_repos

modules.use_all_repos(module_ctx)

Return from a module extension that should have all its repositories imported via use_repo.

Example:

def _ext_impl(module_ctx):
    some_repo_rule(name = "foobar")
    http_archive(name = "bazqux")
    return modules.use_all_repos(module_ctx)

ext = module_extension(_ext_impl)

PARAMETERS

Name Description Default Value
module_ctx The module_ctx object passed to the module extension's implementation function. none

RETURNS

An extension_metadata object that, when returned from a module extension implementation function, specifies that all repositories generated by this extension should be imported via use_repo. If the current version of Bazel doesn't support extension_metadata, returns None instead, which can safely be returned from a module extension implementation function in all versions of Bazel.