docs/versions/7.4.0/rules/lib/repo/utils.mdx
The following functions can be loaded from
@bazel_tools//tools/build_defs/repo:utils.bzl.
Utils for manipulating external repositories, once fetched.
These utilities are intended to be used by other repository rules. They can be loaded as follows.
load(
"@bazel_tools//tools/build_defs/repo:utils.bzl",
"workspace_and_buildfile",
"patch",
"update_attrs",
)
<a id="download_remote_files"></a>
Utility function for downloading remote files.
This rule is intended to be used in the implementation function of
a repository rule. It assumes the parameters remote_file_urls and
remote_file_integrity to be present in ctx.attr.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> <tr id="download_remote_files-auth"> <td><code>auth</code></td> <td>optional. default is <code>None</code>
<p>An optional dict specifying authentication information for some of the URLs.
</p> </td> </tr> </tbody> </table><a id="get_auth"></a>
Utility function to obtain the correct auth dict for a list of urls from .netrc file.
Support optional netrc and auth_patterns attributes if available.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> <tr id="get_auth-urls"> <td><code>urls</code></td> <td>required.
<p>the list of urls to read
</p> </td> </tr> </tbody> </table>the auth dict which can be passed to repository_ctx.download
<a id="maybe"></a>
Utility function for only adding a repository if it's not already present.
This is to implement safe repositories.bzl macro documented in https://bazel.build/rules/deploying#dependencies.
required.
<p>repository rule function.
</p> </td> </tr> <tr id="maybe-name"> <td><code>name</code></td> <td>required.
<p>name of the repository to create.
</p> </td> </tr> <tr id="maybe-kwargs"> <td><code>kwargs</code></td> <td>optional.
<p>remaining arguments that are passed to the repo_rule function.
</p> </td> </tr> </tbody> </table>Nothing, defines the repository when needed as a side-effect.
<a id="parse_netrc"></a>
Utility function to parse at least a basic .netrc file.
required.
<p>input for the parser.
</p> </td> </tr> <tr id="parse_netrc-filename"> <td><code>filename</code></td> <td>optional. default is <code>None</code>
<p>filename to use in error messages, if any.
</p> </td> </tr> </tbody> </table>dict mapping a machine names to a dict with the information provided about them
<a id="patch"></a>
Implementation of patching an already extracted repository.
This rule is intended to be used in the implementation function of
a repository rule. If the parameters patches, patch_tool,
patch_args, patch_cmds and patch_cmds_win are not specified
then they are taken from ctx.attr.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> <tr id="patch-patches"> <td><code>patches</code></td> <td>optional. default is <code>None</code>
<p>The patch files to apply. List of strings, Labels, or paths.
</p> </td> </tr> <tr id="patch-patch_cmds"> <td><code>patch_cmds</code></td> <td>optional. default is <code>None</code>
<p>Bash commands to run for patching, passed one at a time to bash -c. List of strings
</p> </td> </tr> <tr id="patch-patch_cmds_win"> <td><code>patch_cmds_win</code></td> <td>optional. default is <code>None</code>
<p>Powershell commands to run for patching, passed one at a time to powershell /c. List of strings. If the boolean value of this parameter is false, patch_cmds will be used and this parameter will be ignored.
</p> </td> </tr> <tr id="patch-patch_tool"> <td><code>patch_tool</code></td> <td>optional. default is <code>None</code>
<p>Path of the patch tool to execute for applying patches. String.
</p> </td> </tr> <tr id="patch-patch_args"> <td><code>patch_args</code></td> <td>optional. default is <code>None</code>
<p>Arguments to pass to the patch tool. List of strings.
</p> </td> </tr> <tr id="patch-auth"> <td><code>auth</code></td> <td>optional. default is <code>None</code>
<p>An optional dict specifying authentication information for some of the URLs.
</p> </td> </tr> </tbody> </table><a id="read_netrc"></a>
Utility function to parse at least a basic .netrc file.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> <tr id="read_netrc-filename"> <td><code>filename</code></td> <td>required.
<p>the name of the .netrc file to read
</p> </td> </tr> </tbody> </table>dict mapping a machine names to a dict with the information provided about them
<a id="read_user_netrc"></a>
Read user's default netrc file.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> </tbody> </table>dict mapping a machine names to a dict with the information provided about them.
<a id="update_attrs"></a>
Utility function for altering and adding the specified attributes to a particular repository rule invocation.
This is used to make a rule reproducible.
required.
<p>dict of actually set attributes (either explicitly or implicitly) by a particular rule invocation
</p> </td> </tr> <tr id="update_attrs-keys"> <td><code>keys</code></td> <td>required.
<p>complete set of attributes defined on this rule
</p> </td> </tr> <tr id="update_attrs-override"> <td><code>override</code></td> <td>required.
<p>dict of attributes to override or add to orig
</p> </td> </tr> </tbody> </table>dict of attributes with the keys from override inserted/updated
<a id="use_netrc"></a>
Compute an auth dict from a parsed netrc file and a list of URLs.
required.
<p>a netrc file already parsed to a dict, e.g., as obtained from read_netrc
</p> </td> </tr> <tr id="use_netrc-urls"> <td><code>urls</code></td> <td>required.
<p>a list of URLs.
</p> </td> </tr> <tr id="use_netrc-patterns"> <td><code>patterns</code></td> <td>required.
<p>optional dict of url to authorization patterns
</p> </td> </tr> </tbody> </table>dict suitable as auth argument for ctx.download; more precisely, the dict will map all URLs where the netrc file provides login and password to a dict containing the corresponding login, password and optional authorization pattern, as well as the mapping of "type" to "basic" or "pattern".
<a id="workspace_and_buildfile"></a>
Utility function for writing WORKSPACE and, if requested, a BUILD file.
This rule is intended to be used in the implementation function of a
repository rule.
It assumes the parameters name, build_file, build_file_content,
workspace_file, and workspace_file_content to be
present in ctx.attr; the latter four possibly with value None.
required.
<p>The repository context of the repository rule calling this utility function.
</p> </td> </tr> </tbody> </table>