Skip to main content
The context of the module extension containing helper functions and information about pertinent tags across the dependency graph. You get a module_ctx object as an argument to the implementation function when you create a module extension.

Members

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

extension_metadata

Constructs an opaque object that can be returned from the module extension’s implementation function to provide metadata about the repositories generated by the extension to Bazel.

Parameters

extract

Extract an archive to the repository directory.

Parameters

facts

The JSON-like dict returned by a previous execution of this extension in the facts parameter of extension\_metadata or else {}. This is useful for extensions that want to preserve universally true facts such as the hashes of artifacts in an immutable repository. Note that the returned value may have been created by a different version of the extension, which may have used a different schema.

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.

is_dev_dependency

Returns whether the given tag was specified on the result of a use_extension call with devDependency = True.

Parameters

modules

A list of all the Bazel modules in the external dependency graph that use this module extension, each of which is a bazel_module object that exposes all the tags it specified for this extension. The iteration order of this dictionary is guaranteed to be the same as breadth-first search starting from the root module.

os

A struct to access information from the system.

path

Returns a path from a string, label or path. If the path is relative, it will resolve relative to the repository directory. If the path is a label, it will resolve to the path of the corresponding file. Note that remote repositories 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

report_progress

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

Parameters

root_module_has_non_dev_dependency

Whether the root module uses this extension as a non-dev dependency.

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

which

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

Parameters

May return None.