implementation function when you create a repository rule.
Members
- attr
- delete
- download
- download_and_extract
- execute
- extract
- file
- getenv
- name
- original_name
- os
- patch
- path
- read
- rename
- repo_metadata
- report_progress
- symlink
- template
- watch
- watch_tree
- which
- workspace_root
attr
delete
Parameters
ParameterDescriptionpathstring; or path;
required
Path of the file to delete, relative to the repository directory, or absolute. Can be a path or a string.
download
success, a flag which is true if the download completed successfully, and if successful, a hash of the file with the fields sha256 and integrity. When sha256 or integrity is user specified, setting an explicit canonical_id is highly recommended. e.g. get_default_canonical_id
Parameters
ParameterDescriptionurlstring; or Iterable of string s;
required
List of mirror URLs referencing the same file.
outputstring; or Label; or path;
default is ''
path to the output file, relative to the repository directory.
sha256string;
default is ''
The expected SHA-256 hash of the file downloaded. This must match the SHA-256 hash of the file downloaded. It is a security risk to omit the SHA-256 as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. If provided, the repository cache will first be checked for a file with the given hash; a download will only be attempted if the file was not found in the cache. After a successful download, the file will be added to the cache.
executablebool;
default is False
Set the executable flag on the created file, false by default.
allow_failbool;
default is False
If set, indicate the error in the return value instead of raising an error for failed downloads.
canonical_idstring;
default is ''
If set, restrict cache hits to those cases where the file was added to the cache with the same canonical id. By default caching uses the checksum ( sha256 or integrity).
authdict;
default is {}
An optional dict specifying authentication information for some of the URLs.
headersdict;
default is {}
An optional dict specifying http headers for all URLs.
integritystring;
default is ''
Expected checksum of the file downloaded, in Subresource Integrity format. This must match the checksum of the file downloaded. It is a security risk to omit the checksum as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. If provided, the repository cache will first be checked for a file with the given checksum; a download will only be attempted if the file was not found in the cache. After a successful download, the file will be added to the cache.
blockbool;
default is True
If set to false, the call returns immediately and instead of the regular return value, it returns a token with one single method, wait(), which blocks until the download is finished and returns the usual return value or throws as usual.
download_and_extract
success, a flag which is true if the download completed successfully, and if successful, a hash of the file with the fields sha256 and integrity. When sha256 or integrity is user specified, setting an explicit canonical_id is highly recommended. e.g. get_default_canonical_id
Parameters
ParameterDescriptionurlstring; or Iterable of string s;
required
List of mirror URLs referencing the same file.
outputstring; or Label; or path;
default is ''
Path to the directory where the archive will be unpacked, relative to the repository directory.
sha256string;
default is ''
The expected SHA-256 hash of the file downloaded. This must match the SHA-256 hash of the file downloaded. It is a security risk to omit the SHA-256 as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. If provided, the repository cache will first be checked for a file with the given hash; a download will only be attempted if the file was not found in the cache. After a successful download, the file will be added to the cache.
typestring;
default is ''
The archive type of the downloaded file. By default, the archive type is determined from the file extension of the URL. If the file has no extension, you can explicitly specify either “zip”, “jar”, “war”, “aar”, “nupkg”, “whl”, “tar”, “tar.gz”, “tgz”, “tar.xz”, “txz”, “.tar.zst”, “.tzst”, “tar.bz2”, “.tbz”, “.ar”, or “.deb” here.
strip_prefixstring;
default is ''
A directory prefix to strip from the extracted files. Many archives contain a
top-level directory that contains all files in the archive. Instead of needing to
specify this prefix over and over in the build_file, this field can
be used to strip it from extracted files.
For compatibility, this parameter may also be used under the deprecated name
stripPrefix.
allow_failbool;
default is False
If set, indicate the error in the return value instead of raising an error for failed downloads.
canonical_idstring;
default is ''
If set, restrict cache hits to those cases where the file was added to the cache with the same canonical id. By default caching uses the checksum
( sha256 or integrity).
authdict;
default is {}
An optional dict specifying authentication information for some of the URLs.
headersdict;
default is {}
An optional dict specifying http headers for all URLs.
integritystring;
default is ''
Expected checksum of the file downloaded, in Subresource Integrity format. This must match the checksum of the file downloaded. It is a security risk to omit the checksum as remote files can change. At best omitting this field will make your build non-hermetic. It is optional to make development easier but should be set before shipping. If provided, the repository cache will first be checked for a file with the given checksum; a download will only be attempted if the file was not found in the cache. After a successful download, the file will be added to the cache.
rename_filesdict;
default is {}
An optional dict specifying files to rename during the extraction. Archive entries with names exactly matching a key will be renamed to the value, prior to any directory prefix adjustment. This can be used to extract archives that contain non-Unicode filenames, or which have files that would extract to the same path on case-insensitive filesystems.
execute
timeout (in seconds, default 600 seconds). This method returns an exec_result structure containing the output of the command. The environment map can be used to override some environment variables to be passed to the process.
Parameters
ParameterDescriptionargumentssequence;
required
List of arguments, the first element should be the path to the program to execute.
timeoutint;
default is 600
Maximum duration of the command in seconds (default is 600 seconds).
environmentdict;
default is {}
Force some environment variables to be set to be passed to the process. The value can be None to remove the environment variable.
quietbool;
default is True
If stdout and stderr should be printed to the terminal.
working_directorystring;
default is ""
Working directory for command execution.
Can be relative to the repository root or absolute.
The default is the repository root.
extract
Parameters
ParameterDescriptionarchivestring; or Label; or path;
required
path to the archive that will be unpacked, relative to the repository directory.
outputstring; or Label; or path;
default is ''
path to the directory where the archive will be unpacked, relative to the repository directory.
strip_prefixstring;
default is ''
a directory prefix to strip from the extracted files. Many archives contain a
top-level directory that contains all files in the archive. Instead of needing to
specify this prefix over and over in the build_file, this field can be
used to strip it from extracted files.
For compatibility, this parameter may also be used under the deprecated name
stripPrefix.
rename_filesdict;
default is {}
An optional dict specifying files to rename during the extraction. Archive entries with names exactly matching a key will be renamed to the value, prior to any directory prefix adjustment. This can be used to extract archives that contain non-Unicode filenames, or which have files that would extract to the same path on case-insensitive filesystems.
watch_archivestring;
default is 'auto'
whether to watch the archive file. Can be the string ‘yes’, ‘no’, or ‘auto’. Passing ‘yes’ is equivalent to immediately invoking the watch() method; passing ‘no’ does not attempt to watch the file; passing ‘auto’ will only attempt to watch the file when it is legal to do so (see watch() docs for more information.
file
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
Path of the file to create, relative to the repository directory.
contentstring;
default is ''
The content of the file to create, empty by default.
executablebool;
default is True
Set the executable flag on the created file, true by default.
legacy_utf8bool;
default is False
No-op. This parameter is deprecated and will be removed in a future version of Bazel.
getenv
name as a string if exists, or default if it doesn’t.
When building incrementally, any change to the value of the variable named by name will cause this repository to be re-fetched.
Parameters
ParameterDescriptionnamestring;
required
Name of desired environment variable.
defaultstring; or None;
default is None
Default value to return if name is not found.
May return None.
name
original_name instead to get the name that was originally specified as the name when this repository rule was instantiated.
original_name
name attribute when this repository rule was instantiated. This name is not necessarily unique among external repositories. Use name instead to get the canonical name of the external repository.
os
patch
Parameters
ParameterDescriptionpatch_filestring; or Label; or path;
required
The patch file to apply, it can be label, relative path or absolute path. If it’s a relative path, it will resolve to the repository directory.
stripint;
default is 0
Strip the specified number of leading components from file names.
watch_patchstring;
default is 'auto'
Whether to watch the patch file. Can be the string ‘yes’, ‘no’, or ‘auto’. Passing ‘yes’ is equivalent to immediately invoking the watch() method; passing ‘no’ does not attempt to watch the file; passing ‘auto’ will only attempt to watch the file when it is legal to do so (see watch() docs for more information.
path
repository_ctx, a relative path will resolve relative to the repository directory. If it is a module_ctx, a relative path will resolve relative to a temporary working directory for this module extension. If the path is a label, it will resolve to the path of the corresponding file. Note that remote repositories and module extensions are executed during the analysis phase and thus cannot depends on a target result (the label should point to a non-generated file). If path is a path, it will return that path as is.
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
string, Label or path from which to create a path from.
read
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
Path of the file to read from.
watchstring;
default is 'auto'
Whether to watch the file. Can be the string ‘yes’, ‘no’, or ‘auto’. Passing ‘yes’ is equivalent to immediately invoking the watch() method; passing ‘no’ does not attempt to watch the file; passing ‘auto’ will only attempt to watch the file when it is legal to do so (see watch() docs for more information.
rename
src to dst. Parent directories are created as needed. Fails if the destination path
already exists. Both paths must be located within the repository.
Parameters
ParameterDescriptionsrcstring; or Label; or path;
required
The path of the existing file or directory to rename, relative
to the repository directory.
dststring; or Label; or path;
required
The new name to which the file or directory will be renamed to,
relative to the repository directory.
repo_metadata
Parameters
ParameterDescriptionreproduciblebool;
default is False
States that this repo can be reproducibly refetched; that is, if it were fetched another time with exactly the same input attributes, repo rule definition, watched files and environment variables, etc., then exactly the same output would be produced. This property needs to hold even if other untracked conditions change, such as information from the internet, the path of the workspace root, output from running arbitrary executables, etc. If set to True, this allows the fetched repo contents to be cached across workspaces.
Note that setting this to True does not guarantee caching in the repo contents cache; for example, local repo rules are never cached.
attrs_for_reproducibilitydict;
default is {}
If reproducible is False, this can be specified to tell Bazel which attributes of the original repo rule to change to make it reproducible.
report_progress
Parameters
ParameterDescriptionstatusstring;
default is ''
string describing the current status of the fetch progress.
symlink
Parameters
ParameterDescriptiontargetstring; or Label; or path;
required
The path that the symlink should point to.
link_namestring; or Label; or path;
required
The path of the symlink to create.
template
template. Every occurrence in template of a key of substitutions will be replaced by the corresponding value. The result is written in path. An optional executable argument (default to true) can be set to turn on or off the executable bit.
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
Path of the file to create, relative to the repository directory.
templatestring; or Label; or path;
required
Path to the template file.
substitutionsdict;
default is {}
Substitutions to make when expanding the template.
executablebool;
default is True
Set the executable flag on the created file, true by default.
watch_templatestring;
default is 'auto'
Whether to watch the template file. Can be the string ‘yes’, ‘no’, or ‘auto’. Passing ‘yes’ is equivalent to immediately invoking the watch() method; passing ‘no’ does not attempt to watch the file; passing ‘auto’ will only attempt to watch the file when it is legal to do so (see watch() docs for more information.
watch
path.readdir() instead.
Note that attempting to watch paths inside the repo currently being fetched, or inside the working directory of the current module extension, will result in an error. A module extension attempting to watch a path outside the current Bazel workspace will also result in an error.
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
Path of the file to watch.
watch_tree
Parameters
ParameterDescriptionpathstring; or Label; or path;
required
Path of the directory tree to watch.
which
path of the corresponding program or None if there is no such program in the path.
Parameters
ParameterDescriptionprogramstring;
required
Program to find in the path.
May return None.