The following functions can be loaded from @bazel_tools//tools/build_defs/repo:utils.bzl.

maybe

maybe(repo_rule, name, kwargs)

Utility function for only adding a repository if it’s not already present.

This is to implement safe repositories.bzl macro documented in https://docs.bazel.build/versions/main/skylark/deploying.html#dependencies.

Parameters

repo_rule required.

repository rule function.

name required.

name of the repository to create.

kwargs optional.

remaining arguments that are passed to the repo_rule function.

parse_netrc

parse_netrc(contents, filename)

Utility function to parse at least a basic .netrc file.

Parameters

contents required.

input for the parser.

filename optional. default is None

filename to use in error messages, if any.

patch

patch(ctx, patches, patch_cmds, patch_cmds_win, patch_tool, patch_args)

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.

Parameters

ctx required.

The repository context of the repository rule calling this utility function.

patches optional. default is None

The patch files to apply. List of strings, Labels, or paths.

patch_cmds optional. default is None

Bash commands to run for patching, passed one at a time to bash -c. List of strings

patch_cmds_win optional. default is None

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.

patch_tool optional. default is None

Path of the patch tool to execute for applying patches. String.

patch_args optional. default is None

Arguments to pass to the patch tool. List of strings.

read_netrc

read_netrc(ctx, filename)

Utility function to parse at least a basic .netrc file.

Parameters

ctx required.

The repository context of the repository rule calling this utility function.

filename required.

the name of the .netrc file to read

update_attrs

update_attrs(orig, keys, override)

Utility function for altering and adding the specified attributes to a particular repository rule invocation.

This is used to make a rule reproducible.

Parameters

orig required.

dict of actually set attributes (either explicitly or implicitly) by a particular rule invocation

keys required.

complete set of attributes defined on this rule

override required.

dict of attributes to override or add to orig

use_netrc

use_netrc(netrc, urls, patterns)

Compute an auth dict from a parsed netrc file and a list of URLs.

Parameters

netrc required.

a netrc file already parsed to a dict, e.g., as obtained from read_netrc

urls required.

a list of URLs.

patterns required.

optional dict of url to authorization patterns

workspace_and_buildfile

workspace_and_buildfile(ctx)

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.

Parameters

ctx required.

The repository context of the repository rule calling this utility function.