LazyContext
LazyContext.analysis
def LazyContext.analysis(
label: bxl.ConfiguredTargetNode | configured_target_label | label,
/,
) -> bxl.Lazy
Analyze a target lazily. This will return a lazy operation that can be evaluated later. The target should be a ConfiguredTargetLabel, a ConfiguredProvidersLabel, or a ConfiguredTargetNode.
Example:
def _impl(ctx):
target = ctx.configured_targets("cell//path/to:target")
analysis_result = ctx.lazy.analysis(target).resolve()
(analysis_result, err) = ctx.lazy.analysis(target).try_resolve()
LazyContext.build_artifact
def LazyContext.build_artifact(
artifact: artifact,
/,
) -> bxl.Lazy
Build the given artifact, but it will not materialize the artifact. If the artifact need to be materialized, call ctx.output.ensure
for the resolved value to defer materialization of the artifact.
Attention: This api does not accept declared artifact. If you want to materialize a declared artifact, use ctx.output.ensure
.
LazyContext.configured_target_node
def LazyContext.configured_target_node(
expr: bxl.ConfiguredTargetNode | bxl.UnconfiguredTargetNode | configured_target_label | str | target_label,
/,
*,
target_platform: None | str | target_label = ...,
modifiers: list[str] = [],
) -> bxl.Lazy
Gets the configured target node for the expr
. If given a string target pattern, it will resolve to a target set of configured target nodes. it also accepts an optional target_platform
and an optional modifers list which is used to resolve configurations of any unconfigured target nodes. The target_platform
is either a string that can be parsed as a target label, or a target label.
The given expr
is either:
- a single string that is a target ot a target pattern.
- a single target node or label, configured or unconfigured
Note that this function does not accept ConfiguredProviderLabel
(which is a configured provider label), since this
is the label of a subtarget. You can get the underlying configured target label on the Label
using configured_targets()
(ex: my_label.configured_target()
).
This returns either a target set of ConfiguredTargetNode
s if the given expr
is a target pattern string,
else a single ConfiguredTargetNode
.
When the given a target pattern (returns the target set), for the incompatible targets, it will print the warning message of these incompatible targets.
Else (returns a single ConfiguredTargetNode
), it will raise an error if incompatible when resolve. Use Lazy.catch()
to catch the error.
Example:
def _impl(ctx):
# returns a single `ConfiguredTargetNode`
node = ctx.lazy.configured_target_node("cell//path/to:target").resolve()
# returns a target set of `ConfiguredTargetNode`s
target_set = ctx.lazy.configured_target_node("cell//path/to:").resolve()
LazyContext.cquery
def LazyContext.cquery(
*,
target_platform: None | str | target_label = ...,
modifiers: list[str] = [],
) -> LazyCqueryContext
Gets the lazy cquery context.
LazyContext.join
def LazyContext.join(
lazy0: bxl.Lazy,
lazy1: bxl.Lazy,
/,
) -> bxl.Lazy
Join two lazy operations into a single operation that can be evaluated.
Example:
def _impl(ctx):
...
joined = ctx.lazy.join(ctx.lazy.analysis(t1), ctx.lazy.analysis(t2))
(res1, res2) = joined.resolve()
ctx.output.print(res1)
ctx.output.print(res2)
LazyContext.join_all
def LazyContext.join_all(
operations: list[bxl.Lazy],
/,
) -> bxl.Lazy
Join a list of lazy operations into a single operation that can be evaluated. This is useful when you want to evaluate multiple operations in parallel. Using .try_resolve()
can catch errors for the individual operations.
Example:
def _impl(ctx):
...
joined = ctx.lazy.join_all([ctx.lazy.analysis(t) for t in targets])
analysis_results = joined.resolve()
ctx.output.print(analysis_results)
LazyContext.unconfigured_target_node
def LazyContext.unconfigured_target_node(
expr: bxl.UnconfiguredTargetNode | str | target_label,
/,
) -> bxl.Lazy
Gets the unconfigured target node(s) for the expr
The given expr
is either:
- a single string that is a target ot a target pattern.
- a single unconfigured target node or label
This returns either a target set of UnconfiguredTargetNode
s if the given expr
is a target pattern string,
else a single UnconfiguredTargetNode
.