repository_ctx
The context of the repository rule containing helper functions and information about attributes. You get a repository_ctx object as an argument to theimplementation
function when you create a repository rule.
Members
attr
struct repository_ctx.attrA struct to access the values of the attributes. The values are provided by the user (if not, a default value is used).
download
struct repository_ctx.download(url, output='', sha256='', executable=False)Downloads a file to the output path for the provided url and returns a struct containing a hash of the file with the field
sha256
.
Parameters
Parameter | Description |
---|---|
url
|
List of mirror URLs referencing the same file. |
output
|
path to the output file, relative to the repository directory. |
sha256
|
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. |
executable
|
set the executable flag on the created file, false by default. |
download_and_extract
struct repository_ctx.download_and_extract(url, output='', sha256='', type='', stripPrefix='')Downloads a file to the output path for the provided url, extracts it, and returns a struct containing a hash of the downloaded file with the field
sha256
.
Parameters
Parameter | Description |
---|---|
url
|
List of mirror URLs referencing the same file. |
output
|
path to the directory where the archive will be unpacked, relative to the repository directory. |
sha256
|
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. |
type
|
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", "tar.gz", "tgz", "tar.bz2", or "tar.xz" here. |
stripPrefix
|
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 |
execute
exec_result repository_ctx.execute(arguments, timeout=600, environment={}, quiet=True)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
Parameter | Description |
---|---|
arguments
|
List of arguments, the first element should be the path to the program to execute. |
timeout
|
maximum duration of the command in seconds (default is 600 seconds). |
environment
|
force some environment variables to be set to be passed to the process. |
quiet
|
If stdout and stderr should be printed to the terminal. |
extract
None repository_ctx.extract(archive, output='', stripPrefix='')Extract an archive to the repository directory.
Parameters
Parameter | Description |
---|---|
archive
|
path to the archive that will be unpacked, relative to the repository directory. |
output
|
path to the directory where the archive will be unpacked, relative to the repository directory. |
stripPrefix
|
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 |
file
None repository_ctx.file(path, content='', executable=True)Generates a file in the repository directory with the provided content.
Parameters
Parameter | Description |
---|---|
path
|
path of the file to create, relative to the repository directory. |
content
|
the content of the file to create, empty by default. |
executable
|
set the executable flag on the created file, true by default. |
name
string repository_ctx.nameThe name of the external repository created by this rule.
os
repository_os repository_ctx.osA struct to access information from the system.
path
path repository_ctx.path(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
Parameter | Description |
---|---|
path
|
string, label or path from which to create a path from |
report_progress
None repository_ctx.report_progress(status)Updates the progress status for the fetching of this repository
Parameters
Parameter | Description |
---|---|
status
|
string describing the current status of the fetch progress |
symlink
None repository_ctx.symlink(from, to)Creates a symlink on the filesystem.
Parameters
Parameter | Description |
---|---|
from
|
path to which the created symlink should point to. |
to
|
path of the symlink to create, relative to the repository directory. |
template
None repository_ctx.template(path, template, substitutions={}, executable=True)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 optionalexecutable
argument (default to true) can be set to turn on or offthe executable bit.
Parameters
Parameter | Description |
---|---|
path
|
path of the file to create, relative to the repository directory. |
template
|
path to the template file. |
substitutions
|
substitutions to make when expanding the template. |
executable
|
set the executable flag on the created file, true by default. |
which
path repository_ctx.which(program)Returns the path of the corresponding program or None if there is no such program in the path.
Parameters
Parameter | Description |
---|---|
program
|
Program to find in the path. |
None
.