blob: ae33af921925fd4715e45b793f50641f51ae36d7 [file]
<html devsite>
<head>
<meta name="project_path" value="/_project.yaml">
<meta name="book_path" value="/versions/6.0.0/_book.yaml">
</head>
<body>
<h1 class="page-title" id="modules.native">native</h1>
<!-- {% raw %} -->
A built-in module to support native rules and other package helper functions. All native rules appear as functions in this module, e.g. <code>native.cc_library</code>. Note that the native module is only available in the loading phase (i.e. for macros, not for rule implementations). Attributes will ignore <code>None</code> values, and treat them as if the attribute was unset.<br>The following functions are also available:
<h2>Members</h2>
<ul>
<li>
<a href="#existing_rule">existing_rule</a>
</li>
<li>
<a href="#existing_rules">existing_rules</a>
</li>
<li>
<a href="#exports_files">exports_files</a>
</li>
<li>
<a href="#glob">glob</a>
</li>
<li>
<a href="#package_group">package_group</a>
</li>
<li>
<a href="#package_name">package_name</a>
</li>
<li>
<a href="#repository_name">repository_name</a>
</li>
<li>
<a href="#subpackages">subpackages</a>
</li>
</ul>
<h2 id="existing_rule">existing_rule</h2>
<p><pre class="rule-signature">unknown native.existing_rule(name)</pre></p>
Returns an immutable dict-like object that describes the attributes of a rule instantiated in this thread's package, or <code>None</code> if no rule instance of that name exists.<p>Here, an <em>immutable dict-like object</em> means a deeply immutable object <code>x</code> supporting dict-like iteration, <code>len(x)</code>, <code>name in x</code>, <code>x[name]</code>, <code>x.get(name)</code>, <code>x.items()</code>, <code>x.keys()</code>, and <code>x.values()</code>.<p>If the <code>--noincompatible_existing_rules_immutable_view</code> flag is set, instead returns a new mutable dict with the same content.<p>The result contains an entry for each attribute, with the exception of private ones (whose names do not start with a letter) and a few unrepresentable legacy attribute types. In addition, the dict contains entries for the rule instance's <code>name</code> and <code>kind</code> (for example, <code>'cc_binary'</code>).<p>The values of the result represent attribute values as follows:<ul><li>Attributes of type str, int, and bool are represented as is.</li><li>Labels are converted to strings of the form <code>':foo'</code> for targets in the same package or <code>'//pkg:name'</code> for targets in a different package.</li><li>Lists are represented as tuples, and dicts are converted to new, mutable dicts. Their elements are recursively converted in the same fashion.</li><li><code>select</code> values are returned with their contents transformed as described above.</li><li>Attributes for which no value was specified during rule instantiation and whose default value is computed are excluded from the result. (Computed defaults cannot be computed until the analysis phase.).</li></ul><p>If possible, avoid using this function. It makes BUILD files brittle and order-dependent. Also, beware that it differs subtly from the two other conversions of rule attribute values from internal form to Starlark: one used by computed defaults, the other used by <code>ctx.attr.foo</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="existing_rule.name">
<code>name</code>
</td>
<td>
required<br/>
The name of the target.
</td>
</tr>
</tbody>
</table>
<h2 id="existing_rules">existing_rules</h2>
<p><pre class="rule-signature">unknown native.existing_rules()</pre></p>
Returns an immutable dict-like object describing the rules so far instantiated in this thread's package. Each entry of the dict-like object maps the name of the rule instance to the result that would be returned by <code>existing_rule(name)</code>.<p>Here, an <em>immutable dict-like object</em> means a deeply immutable object <code>x</code> supporting dict-like iteration, <code>len(x)</code>, <code>name in x</code>, <code>x[name]</code>, <code>x.get(name)</code>, <code>x.items()</code>, <code>x.keys()</code>, and <code>x.values()</code>.<p>If the <code>--noincompatible_existing_rules_immutable_view</code> flag is set, instead returns a new mutable dict with the same content.<p><em>Note: If possible, avoid using this function. It makes BUILD files brittle and order-dependent. Furthermore, if the </em><code>--noincompatible_existing_rules_immutable_view</code><em> flag is set, this function may be very expensive, especially if called within a loop.</em>
<h2 id="exports_files">exports_files</h2>
<p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> native.exports_files(srcs, visibility=None, licenses=None)</pre></p>
Specifies a list of files belonging to this package that are exported to other packages.
<!-- 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="exports_files.srcs">
<code>srcs</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
required<br/>
The list of files to export.
</td>
</tr>
<tr>
<td id="exports_files.visibility">
<code>visibility</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a>; or <a class="anchor" href="globals.html#None">None</a></code>;
default = None<br/>
A visibility declaration can to be specified. The files will be visible to the targets specified. If no visibility is specified, the files will be visible to every package.
</td>
</tr>
<tr>
<td id="exports_files.licenses">
<code>licenses</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s; or <a class="anchor" href="globals.html#None">None</a></code>;
default = None<br/>
Licenses to be specified.
</td>
</tr>
</tbody>
</table>
<h2 id="glob">glob</h2>
<p><pre class="rule-signature"><a class="anchor" href="list.html">sequence</a> native.glob(include=[], exclude=[], exclude_directories=1, allow_empty=unbound)</pre></p>
Glob returns a new, mutable, sorted list of every file in the current package that:<ul>
<li>Matches at least one pattern in <code>include</code>.</li>
<li>Does not match any of the patterns in <code>exclude</code> (default <code>[]</code>).</li></ul>
If the <code>exclude_directories</code> argument is enabled (set to <code>1</code>), files of type directory will be omitted from the results (default <code>1</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="glob.include">
<code>include</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
default = []<br/>
The list of glob patterns to include.
</td>
</tr>
<tr>
<td id="glob.exclude">
<code>exclude</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
default = []<br/>
The list of glob patterns to exclude.
</td>
</tr>
<tr>
<td id="glob.exclude_directories">
<code>exclude_directories</code>
</td>
<td>
default = 1<br/>
A flag whether to exclude directories or not.
</td>
</tr>
<tr>
<td id="glob.allow_empty">
<code>allow_empty</code>
</td>
<td>
default = unbound<br/>
Whether we allow glob patterns to match nothing. If `allow_empty` is False, each individual include pattern must match something and also the final result must be non-empty (after the matches of the `exclude` patterns are excluded).
</td>
</tr>
</tbody>
</table>
<h2 id="package_group">package_group</h2>
<p><pre class="rule-signature"><a class="anchor" href="globals.html#None">None</a> native.package_group(name, packages=[], includes=[])</pre></p>
This function defines a set of packages and assigns a label to the group. The label can be referenced in <code>visibility</code> attributes.
<!-- 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="package_group.name">
<code>name</code>
</td>
<td>
required<br/>
The unique name for this rule.
</td>
</tr>
<tr>
<td id="package_group.packages">
<code>packages</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
default = []<br/>
A complete enumeration of packages in this group.
</td>
</tr>
<tr>
<td id="package_group.includes">
<code>includes</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
default = []<br/>
Other package groups that are included in this one.
</td>
</tr>
</tbody>
</table>
<h2 id="package_name">package_name</h2>
<p><pre class="rule-signature"><a class="anchor" href="string.html">string</a> native.package_name()</pre></p>
The name of the package being evaluated. For example, in the BUILD file <code>some/package/BUILD</code>, its value will be <code>some/package</code>. If the BUILD file calls a function defined in a .bzl file, <code>package_name()</code> will match the caller BUILD file package. This function is equivalent to the deprecated variable <code>PACKAGE_NAME</code>.
<h2 id="repository_name">repository_name</h2>
<p><pre class="rule-signature"><a class="anchor" href="string.html">string</a> native.repository_name()</pre></p>
The name of the repository the rule or build extension is called from. For example, in packages that are called into existence by the WORKSPACE stanza <code>local_repository(name='local', path=...)</code> it will be set to <code>@local</code>. In packages in the main repository, it will be set to <code>@</code>. This function is equivalent to the deprecated variable <code>REPOSITORY_NAME</code>.
<h2 id="subpackages">subpackages</h2>
<p><pre class="rule-signature"><a class="anchor" href="list.html">sequence</a> native.subpackages(include, exclude=[], allow_empty=False)</pre></p>
Returns a new mutable list of every direct subpackage of the current package, regardless of file-system directory depth. List returned is sorted and contains the names of subpackages relative to the current package. It is advised to prefer using the methods in bazel_skylib.subpackages module rather than calling this function directly.
<!-- 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="subpackages.include">
<code>include</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
required<br/>
The list of glob patterns to include in subpackages scan.
</td>
</tr>
<tr>
<td id="subpackages.exclude">
<code>exclude</code>
</td>
<td>
<code><a class="anchor" href="list.html">sequence</a> of <a class="anchor" href="string.html">string</a>s</code>;
default = []<br/>
The list of glob patterns to exclude from subpackages scan.
</td>
</tr>
<tr>
<td id="subpackages.allow_empty">
<code>allow_empty</code>
</td>
<td>
default = False<br/>
Whether we fail if the call returns an empty list. By default empty list indicates potential error in BUILD file where the call to subpackages() is superflous. Setting to true allows this function to succeed in that case.
</td>
</tr>
</tbody>
</table>
</body>
</html>
<!-- {% endraw %} -->