Skip to main content

ConfiguredTargetNode

ConfiguredTargetNode.attrs_eager

def ConfiguredTargetNode.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.

Right now, it is not recommended to use this method. Instead, use get_attr and get_attrs methods. We will deprecate this method in the future.

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

ConfiguredTargetNode.attrs_lazy

def ConfiguredTargetNode.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.

Right now, it is not recommended to use this method. Instead, use get_attr and get_attrs methods. We will deprecate this method in the future.

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)

ConfiguredTargetNode.buildfile_path

ConfiguredTargetNode.buildfile_path: bxl.FileNode

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)

ConfiguredTargetNode.deps

def ConfiguredTargetNode.deps(
) -> list[bxl.ConfiguredTargetNode]

Gets all deps for this target. The result is a list of ConfiguredTargetNode.

Sample usage:

def _impl_get_deps(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.deps())

ConfiguredTargetNode.get_attr

def ConfiguredTargetNode.get_attr(
key: str,
/,
)

Gets the attribute from the configured target node. If the attribute is unset, returns the default value. If the attribute is not defined by the rule, returns None. It will not return special attribute (attribute that start with 'buck.' in `buck2 cquery -A`` command).

Sample usage:

def _impl_attributes(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.get_attr('my_attr'))

ConfiguredTargetNode.get_attrs

def ConfiguredTargetNode.get_attrs(
) -> dict[str, typing.Any]

Gets the all attributes (not include speical attributes) from the configured target node. For attributes that are not explicitly set, the default value is returned.

Sample usage:

def _impl_attributes(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.get_attrs())

ConfiguredTargetNode.get_source

def ConfiguredTargetNode.get_source(
path: str,
ctx: bxl.Context,
) -> 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)

ConfiguredTargetNode.has_attr

def ConfiguredTargetNode.has_attr(
key: str,
/,
) -> bool

Check if rule has the attribute.

Known attribute is always set explicitly or to default value (otherwise target would not be created) For special attributes, it will return False

Sample usage:

def _impl_has_attr(ctx):
    target_node = ctx.uquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.has_attr('my_attr'))

ConfiguredTargetNode.label

ConfiguredTargetNode.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)

ConfiguredTargetNode.oncall

ConfiguredTargetNode.oncall: None | str

Gets the target's special attr oncall

Sample usage:

def _impl_get_oncall(ctx):
    target_node = ctx.cquery().eval("//foo:bar")[0]
    ctx.output.print(target_node.oncall)

ConfiguredTargetNode.resolved_attrs_eager

def ConfiguredTargetNode.resolved_attrs_eager(
ctx: bxl.Context,
)

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.

Right now, it is not recommended to use this method. Instead, use get_attr and get_attrs methods. We will deprecate this method in the future.

Sample usage:

def _impl_resolved_attrs_eager(ctx):
    node = ctx.cquery().owner("cell//path/to/TARGETS")[0]
    attrs = node.resolved_attrs_eager(ctx) # cache once
    ctx.output.print(attrs)
    # do more stuff with attrs

ConfiguredTargetNode.resolved_attrs_lazy

def ConfiguredTargetNode.resolved_attrs_lazy(
ctx: bxl.Context,
) -> bxl.LazyResolvedAttrs

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.

Right now, it is not recommended to use this method. Instead, use get_attr and get_attrs methods. We will deprecate this method in the future.

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)

ConfiguredTargetNode.rule_kind

ConfiguredTargetNode.rule_kind: str

Gets the targets' corresponding rule's kind which is one of - normal (with no special properties) - configured (usable in a configuration context) - toolchain (only usable as a toolchain dep)

Sample usage:

def _impl_rule_kind(ctx):
    node = ctx.configured_targets("my_cell//bin:the_binary")
    ctx.output.print(node.rule_kind)

ConfiguredTargetNode.rule_type

ConfiguredTargetNode.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)

ConfiguredTargetNode.sources

def ConfiguredTargetNode.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())

ConfiguredTargetNode.unwrap_forward

def ConfiguredTargetNode.unwrap_forward(
) -> bxl.ConfiguredTargetNode

Skip incoming transition forward node. If a target is a forward node, which is created by applying incoming configuration transition, return the transition target, otherwise return itself. This is is particularly useful when you don't care about 'forward' node.

Example usage:

def _impl_unwrap_forward(ctx):
    node = ctx.configured_targets("my_cell//bin:the_binary")
    actual_node = node.unwrap_forward()