Skip to main content
The context of the repository rule containing helper functions and information about attributes. You get a repository_ctx object as an argument to the implementation function when you create a repository rule.

Members

attr

A struct to access the values of the attributes. The values are provided by the user (if not, a default value is used).

delete

Deletes a file or a directory. Returns a bool, indicating whether the file or directory was actually deleted by this call.

Parameters

download

Downloads a file to the output path for the provided url and returns a struct containing 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

download_and_extract

Downloads a file to the output path for the provided url, extracts it, and returns a struct containing 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

execute

Executes the command given by the list of arguments. The execution time of the command is limited by 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

extract

Extract an archive to the repository directory.

Parameters

file

Generates a file in the repository directory with the provided content.

Parameters

getenv

Returns the value of an environment variable 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

May return None.

name

The canonical name of the external repository created by this rule. This name is guaranteed to be unique among all external repositories, but its exact format is not specified. Use original_name instead to get the name that was originally specified as the name when this repository rule was instantiated.

original_name

The name that was originally specified as the 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

A struct to access information from the system.

patch

Apply a patch file to the root directory of external repository. The patch file should be a standard unified diff format file. The Bazel-native patch implementation doesn’t support fuzz match and binary patch like the patch command line tool.

Parameters

path

Returns a path from a string, label, or path. If this context is a 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

read

Reads the content of a file on the filesystem.

Parameters

rename

Renames the file or directory from 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

repo_metadata

Constructs an opaque object that can be returned from the repo rule’s implementation function to provide metadata about its reproducibility.

Parameters

report_progress

Updates the progress status for the fetching of this repository or module extension.

Parameters

Creates a symlink on the filesystem.

Parameters

template

Generates a new file using a 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

watch

Tells Bazel to watch for changes to the given path, whether or not it exists, or whether it’s a file or a directory. Any changes to the file or directory will invalidate this repository or module extension, and cause it to be refetched or re-evaluated next time. “Changes” include changes to the contents of the file (if the path is a file); if the path was a file but is now a directory, or vice versa; and if the path starts or stops existing. Notably, this does not include changes to any files under the directory if the path is a directory. For that, use 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

watch_tree

Tells Bazel to watch for changes to any files or directories transitively under the given path. Any changes to the contents of files, the existence of files or directories, file names or directory names, will cause this repo to be refetched. Note that attempting to watch paths inside the repo currently being fetched will result in an error.

Parameters

which

Returns the path of the corresponding program or None if there is no such program in the path.

Parameters

May return None.

workspace_root

The path to the root workspace of the bazel invocation.