xref: /aosp_15_r20/external/bazel-skylib/docs/modules_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1*bcb5dc79SHONG Yifan<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2*bcb5dc79SHONG Yifan
3*bcb5dc79SHONG YifanSkylib module containing utilities for Bazel modules and module extensions.
4*bcb5dc79SHONG Yifan
5*bcb5dc79SHONG Yifan<a id="modules.as_extension"></a>
6*bcb5dc79SHONG Yifan
7*bcb5dc79SHONG Yifan## modules.as_extension
8*bcb5dc79SHONG Yifan
9*bcb5dc79SHONG Yifan<pre>
10*bcb5dc79SHONG Yifanmodules.as_extension(<a href="#modules.as_extension-macro">macro</a>, <a href="#modules.as_extension-doc">doc</a>)
11*bcb5dc79SHONG Yifan</pre>
12*bcb5dc79SHONG Yifan
13*bcb5dc79SHONG YifanWraps a WORKSPACE dependency macro into a module extension.
14*bcb5dc79SHONG Yifan
15*bcb5dc79SHONG YifanExample:
16*bcb5dc79SHONG Yifan```starlark
17*bcb5dc79SHONG Yifandef rules_foo_deps(optional_arg = True):
18*bcb5dc79SHONG Yifan    some_repo_rule(name = "foobar")
19*bcb5dc79SHONG Yifan    http_archive(name = "bazqux")
20*bcb5dc79SHONG Yifan
21*bcb5dc79SHONG Yifanrules_foo_deps_ext = modules.as_extension(rules_foo_deps)
22*bcb5dc79SHONG Yifan```
23*bcb5dc79SHONG Yifan
24*bcb5dc79SHONG Yifan
25*bcb5dc79SHONG Yifan**PARAMETERS**
26*bcb5dc79SHONG Yifan
27*bcb5dc79SHONG Yifan
28*bcb5dc79SHONG Yifan| Name  | Description | Default Value |
29*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- |
30*bcb5dc79SHONG Yifan| <a id="modules.as_extension-macro"></a>macro |  A [WORKSPACE dependency macro](https://bazel.build/rules/deploying#dependencies), i.e., a function with no required parameters that instantiates one or more repository rules.   |  none |
31*bcb5dc79SHONG Yifan| <a id="modules.as_extension-doc"></a>doc |  A description of the module extension that can be extracted by documentation generating tools.   |  `None` |
32*bcb5dc79SHONG Yifan
33*bcb5dc79SHONG Yifan**RETURNS**
34*bcb5dc79SHONG Yifan
35*bcb5dc79SHONG YifanA module extension that generates the repositories instantiated by the given macro and also
36*bcb5dc79SHONG Yifanuses [`use_all_repos`](#use_all_repos) to indicate that all of those repositories should be
37*bcb5dc79SHONG Yifanimported via `use_repo`. The extension is marked as reproducible if supported by the current
38*bcb5dc79SHONG Yifanversion of Bazel and thus doesn't result in a lockfile entry.
39*bcb5dc79SHONG Yifan
40*bcb5dc79SHONG Yifan
41*bcb5dc79SHONG Yifan<a id="modules.use_all_repos"></a>
42*bcb5dc79SHONG Yifan
43*bcb5dc79SHONG Yifan## modules.use_all_repos
44*bcb5dc79SHONG Yifan
45*bcb5dc79SHONG Yifan<pre>
46*bcb5dc79SHONG Yifanmodules.use_all_repos(<a href="#modules.use_all_repos-module_ctx">module_ctx</a>, <a href="#modules.use_all_repos-reproducible">reproducible</a>)
47*bcb5dc79SHONG Yifan</pre>
48*bcb5dc79SHONG Yifan
49*bcb5dc79SHONG YifanReturn from a module extension that should have all its repositories imported via `use_repo`.
50*bcb5dc79SHONG Yifan
51*bcb5dc79SHONG YifanExample:
52*bcb5dc79SHONG Yifan```starlark
53*bcb5dc79SHONG Yifandef _ext_impl(module_ctx):
54*bcb5dc79SHONG Yifan    some_repo_rule(name = "foobar")
55*bcb5dc79SHONG Yifan    http_archive(name = "bazqux")
56*bcb5dc79SHONG Yifan    return modules.use_all_repos(module_ctx)
57*bcb5dc79SHONG Yifan
58*bcb5dc79SHONG Yifanext = module_extension(_ext_impl)
59*bcb5dc79SHONG Yifan```
60*bcb5dc79SHONG Yifan
61*bcb5dc79SHONG Yifan
62*bcb5dc79SHONG Yifan**PARAMETERS**
63*bcb5dc79SHONG Yifan
64*bcb5dc79SHONG Yifan
65*bcb5dc79SHONG Yifan| Name  | Description | Default Value |
66*bcb5dc79SHONG Yifan| :------------- | :------------- | :------------- |
67*bcb5dc79SHONG Yifan| <a id="modules.use_all_repos-module_ctx"></a>module_ctx |  The [`module_ctx`](https://bazel.build/rules/lib/builtins/module_ctx) object passed to the module extension's implementation function.   |  none |
68*bcb5dc79SHONG Yifan| <a id="modules.use_all_repos-reproducible"></a>reproducible |  The value of the `reproducible` parameter to pass to the [`extension_metadata`](https://bazel.build/rules/lib/builtins/extension_metadata.html) object returned by this function. This is safe to set with Bazel versions that don't support this parameter and will be ignored in that case.   |  `False` |
69*bcb5dc79SHONG Yifan
70*bcb5dc79SHONG Yifan**RETURNS**
71*bcb5dc79SHONG Yifan
72*bcb5dc79SHONG YifanAn [`extension_metadata`](https://bazel.build/rules/lib/builtins/extension_metadata.html)
73*bcb5dc79SHONG Yifanobject that, when returned from a module extension implementation function, specifies that all
74*bcb5dc79SHONG Yifanrepositories generated by this extension should be imported via `use_repo`. If the current
75*bcb5dc79SHONG Yifanversion of Bazel doesn't support `extension_metadata`, returns `None` instead, which can
76*bcb5dc79SHONG Yifansafely be returned from a module extension implementation function in all versions of Bazel.
77*bcb5dc79SHONG Yifan
78*bcb5dc79SHONG Yifan
79