docs/versions/7.1.0/rules/lib/builtins/repository_ctx.mdx
{% dynamic setvar source_file "src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryContext.java" %} {% dynamic setvar version "7.1.0" %} {% dynamic setvar original_path "/rules/lib/builtins/repository_ctx" %} {% include "_buttons.html" %}
<!-- {% raw %} -->The context of the repository rule containing helper functions and information about attributes. You get a repository_ctx object as an argument to the <code>implementation</code> function when you create a repository rule.
<h2>Members</h2> <ul> <li> <a href="#attr">attr</a> </li> <li> <a href="#delete">delete</a> </li> <li> <a href="#download">download</a> </li> <li> <a href="#download_and_extract">download_and_extract</a> </li> <li> <a href="#execute">execute</a> </li> <li> <a href="#extract">extract</a> </li> <li> <a href="#file">file</a> </li> <li> <a href="#getenv">getenv</a> </li> <li> <a href="#name">name</a> </li> <li> <a href="#os">os</a> </li> <li> <a href="#patch">patch</a> </li> <li> <a href="#path">path</a> </li> <li> <a href="#read">read</a> </li> <li> <a href="#report_progress">report_progress</a> </li> <li> <a href="#symlink">symlink</a> </li> <li> <a href="#template">template</a> </li> <li> <a href="#watch">watch</a> </li> <li> <a href="#watch_tree">watch_tree</a> </li> <li> <a href="#which">which</a> </li> <li> <a href="#workspace_root">workspace_root</a> </li> </ul> <h2 id="attr">attr</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> repository_ctx.attr</pre></p>
A struct to access the values of the attributes. The values are provided by the user (if not, a default value is used).
<h2 id="delete">delete</h2>
<p><pre class="rule-signature"><a class="anchor" href="../core/bool.html">bool</a> repository_ctx.delete(path)</pre></p>
Deletes a file or a directory. Returns a bool, indicating whether the file or directory was actually deleted by this call.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="delete.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
Path of the file to delete, relative to the repository directory, or absolute. Can be a path or a string.
</td>
</tr>
</tbody>
</table>
<h2 id="download">download</h2>
<p><pre class="rule-signature">unknown repository_ctx.download(url, output='', sha256='', executable=False, allow_fail=False, canonical_id='', auth={}, headers={}, *, integrity='', block=True)</pre></p>
Downloads a file to the output path for the provided url and returns a struct containing <code>success</code>, a flag which is <code>true</code> if the download completed successfully, and if successful, a hash of the file with the fields <code>sha256</code> and <code>integrity</code>.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="download.url">
<code>url</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or Iterable of <a class="anchor" href="../core/string.html">string</a>s;
required
List of mirror URLs referencing the same file.
</td>
</tr>
<tr>
<td id="download.output">
<code>output</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
default is <code>''</code>
path to the output file, relative to the repository directory.
</td>
</tr>
<tr>
<td id="download.sha256">
<code>sha256</code>
</td>
<td>
default is <code>''</code>
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.
</td>
</tr>
<tr>
<td id="download.executable">
<code>executable</code>
</td>
<td>
default is <code>False</code>
set the executable flag on the created file, false by default.
</td>
</tr>
<tr>
<td id="download.allow_fail">
<code>allow_fail</code>
</td>
<td>
default is <code>False</code>
If set, indicate the error in the return value instead of raising an error for failed downloads
</td>
</tr>
<tr>
<td id="download.canonical_id">
<code>canonical_id</code>
</td>
<td>
default is <code>''</code>
If set, restrict cache hits to those cases where the file was added to the cache with the same canonical id
</td>
</tr>
<tr>
<td id="download.auth">
<code>auth</code>
</td>
<td>
default is <code>{}</code>
An optional dict specifying authentication information for some of the URLs.
</td>
</tr>
<tr>
<td id="download.headers">
<code>headers</code>
</td>
<td>
default is <code>{}</code>
An optional dict specifying http headers for all URLs.
</td>
</tr>
<tr>
<td id="download.integrity">
<code>integrity</code>
</td>
<td>
default is <code>''</code>
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.
</td>
</tr>
<tr>
<td id="download.block">
<code>block</code>
</td>
<td>
default is <code>True</code>
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.
</td>
</tr>
</tbody>
</table>
<h2 id="download_and_extract">download_and_extract</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/struct.html">struct</a> repository_ctx.download_and_extract(url, output='', sha256='', type='', stripPrefix='', allow_fail=False, canonical_id='', auth={}, headers={}, *, integrity='', rename_files={})</pre></p>
Downloads a file to the output path for the provided url, extracts it, and returns a struct containing <code>success</code>, a flag which is <code>true</code> if the download completed successfully, and if successful, a hash of the file with the fields <code>sha256</code> and <code>integrity</code>.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="download_and_extract.url">
<code>url</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or Iterable of <a class="anchor" href="../core/string.html">string</a>s;
required
List of mirror URLs referencing the same file.
</td>
</tr>
<tr>
<td id="download_and_extract.output">
<code>output</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
default is <code>''</code>
path to the directory where the archive will be unpacked, relative to the repository directory.
</td>
</tr>
<tr>
<td id="download_and_extract.sha256">
<code>sha256</code>
</td>
<td>
default is <code>''</code>
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.
</td>
</tr>
<tr>
<td id="download_and_extract.type">
<code>type</code>
</td>
<td>
default is <code>''</code>
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", "tar", "tar.gz", "tgz", "tar.xz", "txz", ".tar.zst", ".tzst", "tar.bz2", ".tbz", ".ar", or ".deb" here.
</td>
</tr>
<tr>
<td id="download_and_extract.stripPrefix">
<code>stripPrefix</code>
</td>
<td>
default is <code>''</code>
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 <code>build_file</code>, this field can be used to strip it from extracted files. </td> </tr> <tr> <td id="download_and_extract.allow_fail"> <code>allow_fail</code> </td> <td> default is <code>False</code>
If set, indicate the error in the return value instead of raising an error for failed downloads
</td>
</tr>
<tr>
<td id="download_and_extract.canonical_id">
<code>canonical_id</code>
</td>
<td>
default is <code>''</code>
If set, restrict cache hits to those cases where the file was added to the cache with the same canonical id
</td>
</tr>
<tr>
<td id="download_and_extract.auth">
<code>auth</code>
</td>
<td>
default is <code>{}</code>
An optional dict specifying authentication information for some of the URLs.
</td>
</tr>
<tr>
<td id="download_and_extract.headers">
<code>headers</code>
</td>
<td>
default is <code>{}</code>
An optional dict specifying http headers for all URLs.
</td>
</tr>
<tr>
<td id="download_and_extract.integrity">
<code>integrity</code>
</td>
<td>
default is <code>''</code>
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.
</td>
</tr>
<tr>
<td id="download_and_extract.rename_files">
<code>rename_files</code>
</td>
<td>
default is <code>{}</code>
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.
</td>
</tr>
</tbody>
</table>
<h2 id="execute">execute</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/exec_result.html">exec_result</a> repository_ctx.execute(arguments, timeout=600, environment={}, quiet=True, working_directory="")</pre></p>
Executes the command given by the list of arguments. The execution time of the command is limited by <code>timeout</code> (in seconds, default 600 seconds). This method returns an <code>exec_result</code> structure containing the output of the command. The <code>environment</code> map can be used to override some environment variables to be passed to the process.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="execute.arguments">
<code>arguments</code>
</td>
<td>
required
List of arguments, the first element should be the path to the program to execute.
</td>
</tr>
<tr>
<td id="execute.timeout">
<code>timeout</code>
</td>
<td>
default is <code>600</code>
maximum duration of the command in seconds (default is 600 seconds).
</td>
</tr>
<tr>
<td id="execute.environment">
<code>environment</code>
</td>
<td>
default is <code>{}</code>
force some environment variables to be set to be passed to the process.
</td>
</tr>
<tr>
<td id="execute.quiet">
<code>quiet</code>
</td>
<td>
default is <code>True</code>
If stdout and stderr should be printed to the terminal.
</td>
</tr>
<tr>
<td id="execute.working_directory">
<code>working_directory</code>
</td>
<td>
default is <code>""</code>
Working directory for command execution.
Can be relative to the repository root or absolute. </td> </tr> </tbody> </table>
<h2 id="extract">extract</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.extract(archive, output='', stripPrefix='', *, rename_files={}, watch_archive='auto')</pre></p>
Extract an archive to the repository directory.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="extract.archive">
<code>archive</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path to the archive that will be unpacked, relative to the repository directory.
</td>
</tr>
<tr>
<td id="extract.output">
<code>output</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
default is <code>''</code>
path to the directory where the archive will be unpacked, relative to the repository directory.
</td>
</tr>
<tr>
<td id="extract.stripPrefix">
<code>stripPrefix</code>
</td>
<td>
default is <code>''</code>
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 <code>build_file</code>, this field can be used to strip it from extracted files. </td> </tr> <tr> <td id="extract.rename_files"> <code>rename_files</code> </td> <td> default is <code>{}</code>
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.
</td>
</tr>
<tr>
<td id="extract.watch_archive">
<code>watch_archive</code>
</td>
<td>
default is <code>'auto'</code>
whether to <a href="#watch">watch</a> the archive file. Can be the string 'yes', 'no', or 'auto'. Passing 'yes' is equivalent to immediately invoking the <a href="#watch"><code>watch()</code></a> 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 <code>watch()</code> docs for more information.
</td>
</tr>
</tbody>
</table>
<h2 id="file">file</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.file(path, content='', executable=True, legacy_utf8=True)</pre></p>
Generates a file in the repository directory with the provided content.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="file.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path of the file to create, relative to the repository directory.
</td>
</tr>
<tr>
<td id="file.content">
<code>content</code>
</td>
<td>
default is <code>''</code>
the content of the file to create, empty by default.
</td>
</tr>
<tr>
<td id="file.executable">
<code>executable</code>
</td>
<td>
default is <code>True</code>
set the executable flag on the created file, true by default.
</td>
</tr>
<tr>
<td id="file.legacy_utf8">
<code>legacy_utf8</code>
</td>
<td>
default is <code>True</code>
encode file content to UTF-8, true by default. Future versions will change the default and remove this parameter.
</td>
</tr>
</tbody>
</table>
<h2 id="getenv">getenv</h2>
<p><pre class="rule-signature"><a class="anchor" href="../core/string.html">string</a> repository_ctx.getenv(name, default=None)</pre></p>
Returns the value of an environment variable <code>name</code> as a string if exists, or <code>default</code> if it doesn't.<p>When building incrementally, any change to the value of the variable named by <code>name</code> will cause this repository to be re-fetched.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="getenv.name">
<code>name</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>;
required
name of desired environment variable
</td>
</tr>
<tr>
<td id="getenv.default">
<code>default</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <code>None</code>;
default is <code>None</code>
Default value to return if `name` is not found
</td>
</tr>
</tbody>
</table>
May return <code>None</code>.
<h2 id="name">name</h2>
<p><pre class="rule-signature"><a class="anchor" href="../core/string.html">string</a> repository_ctx.name</pre></p>
The name of the external repository created by this rule.
<h2 id="os">os</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/repository_os.html">repository_os</a> repository_ctx.os</pre></p>
A struct to access information from the system.
<h2 id="patch">patch</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.patch(patch_file, strip=0, *, watch_patch='auto')</pre></p>
Apply a patch file to the root directory of external repository. The patch file should be a standard <a href="https://en.wikipedia.org/wiki/Diff#Unified_format">unified diff format</a> file. The Bazel-native patch implementation doesn't support fuzz match and binary patch like the patch command line tool.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="patch.patch_file">
<code>patch_file</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
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.
</td>
</tr>
<tr>
<td id="patch.strip">
<code>strip</code>
</td>
<td>
default is <code>0</code>
strip the specified number of leading components from file names.
</td>
</tr>
<tr>
<td id="patch.watch_patch">
<code>watch_patch</code>
</td>
<td>
default is <code>'auto'</code>
whether to <a href="#watch">watch</a> the patch file. Can be the string 'yes', 'no', or 'auto'. Passing 'yes' is equivalent to immediately invoking the <a href="#watch"><code>watch()</code></a> 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 <code>watch()</code> docs for more information.
</td>
</tr>
</tbody>
</table>
<h2 id="path">path</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/path.html">path</a> repository_ctx.path(path)</pre></p>
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.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="path.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
string, label or path from which to create a path from
</td>
</tr>
</tbody>
</table>
<h2 id="read">read</h2>
<p><pre class="rule-signature"><a class="anchor" href="../core/string.html">string</a> repository_ctx.read(path, *, watch='auto')</pre></p>
Reads the content of a file on the filesystem.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="read.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path of the file to read from.
</td>
</tr>
<tr>
<td id="read.watch">
<code>watch</code>
</td>
<td>
default is <code>'auto'</code>
whether to <a href="#watch">watch</a> the file. Can be the string 'yes', 'no', or 'auto'. Passing 'yes' is equivalent to immediately invoking the <a href="#watch"><code>watch()</code></a> 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 <code>watch()</code> docs for more information.
</td>
</tr>
</tbody>
</table>
<h2 id="report_progress">report_progress</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.report_progress(status='')</pre></p>
Updates the progress status for the fetching of this repository or module extension
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="report_progress.status">
<code>status</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>;
default is <code>''</code>
string describing the current status of the fetch progress
</td>
</tr>
</tbody>
</table>
<h2 id="symlink">symlink</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.symlink(target, link_name)</pre></p>
Creates a symlink on the filesystem.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="symlink.target">
<code>target</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
The path that the symlink should point to.
</td>
</tr>
<tr>
<td id="symlink.link_name">
<code>link_name</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
The path of the symlink to create.
</td>
</tr>
</tbody>
</table>
<h2 id="template">template</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.template(path, template, substitutions={}, executable=True, *, watch_template='auto')</pre></p>
Generates a new file using a <code>template</code>. Every occurrence in <code>template</code> of a key of <code>substitutions</code> will be replaced by the corresponding value. The result is written in <code>path</code>. An optional<code>executable</code> argument (default to true) can be set to turn on or offthe executable bit.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="template.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path of the file to create, relative to the repository directory.
</td>
</tr>
<tr>
<td id="template.template">
<code>template</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path to the template file.
</td>
</tr>
<tr>
<td id="template.substitutions">
<code>substitutions</code>
</td>
<td>
default is <code>{}</code>
substitutions to make when expanding the template.
</td>
</tr>
<tr>
<td id="template.executable">
<code>executable</code>
</td>
<td>
default is <code>True</code>
set the executable flag on the created file, true by default.
</td>
</tr>
<tr>
<td id="template.watch_template">
<code>watch_template</code>
</td>
<td>
default is <code>'auto'</code>
whether to <a href="#watch">watch</a> the template file. Can be the string 'yes', 'no', or 'auto'. Passing 'yes' is equivalent to immediately invoking the <a href="#watch"><code>watch()</code></a> 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 <code>watch()</code> docs for more information.
</td>
</tr>
</tbody>
</table>
<h2 id="watch">watch</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.watch(path)</pre></p>
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.<p>"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 <em>not</em> include changes to any files under the directory if the path is a directory. For that, use <a href="path.html#readdir"><code>path.readdir()</code></a> instead.<p>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.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="watch.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path of the file to watch.
</td>
</tr>
</tbody>
</table>
<h2 id="watch_tree">watch_tree</h2>
<p><pre class="rule-signature"><code>None</code> repository_ctx.watch_tree(path)</pre></p>
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.<p>Note that attempting to watch paths inside the repo currently being fetched will result in an error.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="watch_tree.path">
<code>path</code>
</td>
<td>
<a class="anchor" href="../core/string.html">string</a>; or <a class="anchor" href="../builtins/Label.html">Label</a>; or <a class="anchor" href="../builtins/path.html">path</a>;
required
path of the directory tree to watch.
</td>
</tr>
</tbody>
</table>
<h2 id="which">which</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/path.html">path</a> repository_ctx.which(program)</pre></p>
Returns the path of the corresponding program or None if there is no such program in the path.
<!-- hide-from-toc is a class used by DevSite for the public Bazel site
(https://developers.google.com/devsite/reference/styles/headings#hide_headings_from_the_toc) -->
<h3 class="hide-from-toc">Parameters</h3>
<table class="table table-bordered table-condensed table-params">
<colgroup>
<col class="col-param">
<col class="param-description">
</colgroup>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td id="which.program">
<code>program</code>
</td>
<td>
required
Program to find in the path.
</td>
</tr>
</tbody>
</table>
May return <code>None</code>.
<h2 id="workspace_root">workspace_root</h2>
<p><pre class="rule-signature"><a class="anchor" href="../builtins/path.html">path</a> repository_ctx.workspace_root</pre></p>
The path to the root workspace of the bazel invocation.