blob: cc1523b4328b2d824c75120ebaf87811e635ca0a [file] [log] [blame]
<html devsite>
<head>
<meta name="project_path" value="/_project.yaml">
<meta name="book_path" value="/versions/6.1.0/_book.yaml">
</head>
<body>
<h1 class="page-title" id="modules.rule_attributes">rule_attributes</h1>
<!-- {% raw %} -->
Information about attributes of a rule an aspect is applied to.
<h2>Members</h2>
<ul>
<li>
<a href="#attr">attr</a>
</li>
<li>
<a href="#executable">executable</a>
</li>
<li>
<a href="#file">file</a>
</li>
<li>
<a href="#files">files</a>
</li>
<li>
<a href="#kind">kind</a>
</li>
</ul>
<h2 id="attr">attr</h2>
<p><pre class="rule-signature"><a class="anchor" href="struct.html">struct</a> rule_attributes.attr</pre></p>
A struct to access the values of the <a href='https://bazel.build/versions/6.1.0/rules/rules#attributes'>attributes</a>. The values are provided by the user (if not, a default value is used). The attributes of the struct and the types of their values correspond to the keys and values of the <a href='globals.html#rule.attrs'><code>attrs</code> dict</a> provided to the <a href='globals.html#rule'><code>rule</code> function</a>. <a href="https://github.com/bazelbuild/examples/blob/main/rules/attributes/printer.bzl">See example of use</a>.
<h2 id="executable">executable</h2>
<p><pre class="rule-signature"><a class="anchor" href="struct.html">struct</a> rule_attributes.executable</pre></p>
A <code>struct</code> containing executable files defined in <a href='attr.html#label'>label type attributes</a> marked as <a href='attr.html#label.executable'><code>executable=True</code><a>. The struct fields correspond to the attribute names. Each value in the struct is either a <a href='File.html'><code>File</code></a> or <code>None</code>. If an optional attribute is not specified in the rule then the corresponding struct value is <code>None</code>. If a label type is not marked as <code>executable=True</code>, no corresponding struct field is generated. <a href="https://github.com/bazelbuild/examples/blob/main/rules/actions_run/execute.bzl">See example of use</a>.
<h2 id="file">file</h2>
<p><pre class="rule-signature"><a class="anchor" href="struct.html">struct</a> rule_attributes.file</pre></p>
A <code>struct</code> containing files defined in <a href='attr.html#label'>label type attributes</a> marked as <a href='attr.html#label.allow_single_file'><code>allow_single_file</code></a>. The struct fields correspond to the attribute names. The struct value is always a <a href='File.html'><code>File</code></a> or <code>None</code>. If an optional attribute is not specified in the rule then the corresponding struct value is <code>None</code>. If a label type is not marked as <code>allow_single_file</code>, no corresponding struct field is generated. It is a shortcut for:<pre class=language-python>list(ctx.attr.&lt;ATTR&gt;.files)[0]</pre>In other words, use <code>file</code> to access the (singular) <a href="https://bazel.build/versions/6.1.0/rules/rules#requesting_output_files">default output</a> of a dependency. <a href="https://github.com/bazelbuild/examples/blob/main/rules/expand_template/hello.bzl">See example of use</a>.
<h2 id="files">files</h2>
<p><pre class="rule-signature"><a class="anchor" href="struct.html">struct</a> rule_attributes.files</pre></p>
A <code>struct</code> containing files defined in <a href='attr.html#label'>label</a> or <a href='attr.html#label_list'>label list</a> type attributes. The struct fields correspond to the attribute names. The struct values are <code>list</code> of <a href='File.html'><code>File</code></a>s. It is a shortcut for:<pre class=language-python>[f for t in ctx.attr.&lt;ATTR&gt; for f in t.files]</pre> In other words, use <code>files</code> to access the <a href="https://bazel.build/versions/6.1.0/rules/rules#requesting_output_files">default outputs</a> of a dependency. <a href="https://github.com/bazelbuild/examples/blob/main/rules/depsets/foo.bzl">See example of use</a>.
<h2 id="kind">kind</h2>
<p><pre class="rule-signature"><a class="anchor" href="string.html">string</a> rule_attributes.kind</pre></p>
The kind of a rule, such as 'cc_library'
</body>
</html>
<!-- {% endraw %} -->