Back to Bazel

Target

docs/versions/7.0.0/rules/lib/builtins/Target.mdx

9.1.02.5 KB
Original Source
<html devsite> <head> <meta name="project_path" value="/_project.yaml"> <meta name="book_path" value="/versions/7.0.0/_book.yaml"> </head> <body> <h1 class="page-title" id="modules.Target">Target</h1>

{% dynamic setvar source_file "src/main/java/com/google/devtools/build/lib/starlarkbuildapi/core/TransitiveInfoCollectionApi.java" %} {% dynamic setvar version "7.0.0" %} {% dynamic setvar original_path "/rules/lib/builtins/Target" %} {% include "_buttons.html" %}

<!-- {% raw %} -->

The BUILD target for a dependency. Appears in the fields of <code><a href='../builtins/ctx.html#attr'>ctx.attr</a></code> corresponding to <a href='https://bazel.build/versions/7.0.0/extending/rules#dependency_attributes'>dependency attributes</a> (<code><a href='../toplevel/attr.html#label'>label</a></code> or <code><a href='../toplevel/attr.html#label_list'>label_list</a></code>). Has the following fields:

<ul> <li><h3 id='modules.Target.label'>label</h3> <code><a href='../builtins/Label.html'>Label</a> Target.label</code>

The identifier of the target.</li>

<li><h3 id='modules.Target.files'>files</h3> <code><a href='../builtins/depset.html'>depset</a> Target.files </code>

The set of <code><a href='../builtins/File.html'>File</a></code>s in the default outputs for this target. Equivalent to <code><a href='../providers/DefaultInfo.html#files'>target[DefaultInfo].files</a></code>.</li>

<li><h3 id='modules.Target.aspect_ids'>aspect_ids</h3> <code><a href='../core/list.html'>list</a> Target.aspect_ids </code>

The list of <code><a href='../builtins/ctx.html#aspect_ids'>aspect_ids</a></code> applied to this target.</li>

<li><h3 id='modules.Target.providers'>Providers</h3> The <a href='https://bazel.build/versions/7.0.0/extending/rules#providers'>providers</a> of a rule target can be accessed by type using index notation (<code>target[DefaultInfo]</code>). The presence of providers can be checked using the <code>in</code> operator (<code>SomeInfo in target</code>).

If the rule's implementation function returns a <code><a href='../builtins/struct.html'>struct</a></code> instead of a list of <code><a href='../builtins/Provider.html'>Provider</a></code> instances, the struct's fields can be accessed via the corresponding fields of the <code>Target</code> (<code>target.some_legacy_info</code>). This behavior <a href='https://bazel.build/versions/7.0.0/extending/rules#migrating_from_legacy_providers'>is deprecated</a>.</li>

</ul> </body> </html> <!-- {% endraw %} -->