target_node
type
target_node.attrs_eager
def target_node.attrs_eager()
Returns a struct of all the attributes of this target node. The structs fields are the attributes names, and the values are [StarlarkConfiguredAttr
].
If you need to access many or all attrs on the same node, then this is the preferred way. Otherwise,
using attrs_lazy()
would be a better option for only accessing only a few attrs, although this really
depends on what kind of attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
attrs_eager()
each time you need to access the attrs.
Sample usage:
def _impl_attrs_eager(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.attrs_eager() # cache once
ctx.output.print(attrs)
# do more stuff with attrs
target_node.attrs_lazy
def target_node.attrs_lazy() -> lazy_attrs
Returns a lazy_attrs
object that you can call get()
on that gets an attr one at a time.
If you need to access only few attrs on the same node, then this is the preferred way. Otherwise,
using attrs_eager()
would be a better option for accessing many or all attrs, although this really
depends on what kind of attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
attrs_lazy()
each time to get the lazy_attrs
object. Note that if the get()
is None
,
then any methods called on None
will result in an error.
Sample usage:
def _impl_attrs_lazy(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.attrs_lazy() # cache once
ctx.output.print(attrs.get("some_attributes").value())
ctx.output.print(attrs.get("some_attribute").label)
target_node.buildfile_path
target_node.buildfile_path: file_node
Gets the buildfile path from the configured target node.
Sample usage:
def _impl_label(ctx):
target_node = ctx.cquery().eval("owner('path/to/file')")[0]
ctx.output.print(target_node.buildfile_path)
target_node.get_source
def target_node.get_source(path: str, ctx: bxl_ctx) -> None | artifact
Gets the source Artifact
that corresponds to the given path
given a context. The path should be the project relative path to the file, or an absolute path.
Sample usage:
def _impl_get_source(ctx):
owner = ctx.cquery().owner("project/relative/path/to/file")[0]
artifact = owner.sources()[0]
ctx.output.print(artifact)
target_node.label
target_node.label: configured_target_label
Gets the configured target label of this target node.
Note that you cannot get a non-configured label from a configured target node because the configured target node is not uniquely identified a non-configured label, only by the configured target label.
Sample usage:
def _impl_label(ctx):
node = ctx.configured_targets("my_cell//bin:the_binary")
ctx.output.print(node.label)
target_node.resolved_attrs_eager
def target_node.resolved_attrs_eager(ctx: bxl_ctx)
Returns a struct of all the resolved attributes of this target node. The structs fields are the attributes names, and the values are the underlying Starlark values of the attributes.
If you need to access many or all resolved attrs on the same node, then this is the preferred way. Otherwise,
using resolved_attrs_lazy()
would be a better option for accessing only a few resolved attrs, although this really
depends on what kind of resolved attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
resolved_attrs_eager()
each time you need all the resolved attrs.
Sample usage:
def _impl_resolved_attrs_eager(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.resolved_attrs_eager() # cache once
ctx.output.print(attrs)
# do more stuff with attrs
target_node.resolved_attrs_lazy
def target_node.resolved_attrs_lazy(ctx: bxl_ctx) -> lazy_resolved_attrs
Returns a lazy_resolved_attrs
object that you can call get()
on that gets a resolved attr one at a time.
If you need to access only few resolved attrs on the same node, then this is the preferred way. Otherwise,
using resolved_attrs_eager()
would be a better option for accessing many or all resolved attrs, although this really
depends on what kind of resolved attrs are on the node. Benchmarking performance will give you the best
indication on which method to use.
You should store the result of this function call for further usage in the code rather than calling
resolved_attrs_lazy()
each time to get the lazy_resolved_attrs
object. Note that if the get()
is None
,
then any methods called on None
will result in an error.
Sample usage:
def _impl_resolved_attrs_lazy(ctx):
node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
attrs = node.resolved_attrs_lazy(ctx) # cache once
ctx.output.print(attrs.get("some_attributes").value())
ctx.output.print(attrs.get("some_attribute").label)
target_node.rule_type
target_node.rule_type: str
Gets the targets' corresponding rule's name. This is the fully qualified rule name including the import path.
Sample usage:
def _impl_rule_type(ctx):
node = ctx.configured_targets("my_cell//bin:the_binary")
ctx.output.print(node.rule_type)
target_node.sources
def target_node.sources() -> list[artifact]
Returns a List of all the sources used by this node.
Sample usage:
def _impl_sources(ctx):
node = ctx.configured_targets("my_cell//bin:the_binary")
ctx.output.print(node.sources())