Context
The bxl context that the top level bxl implementation receives as parameter. This context contains all the core bxl functions to query, build, create actions, etc.
Context.analysis
def Context.analysis(
labels: ConfiguredTargetLabel | Label | bxl.ConfiguredTargetNode | target_set | list[ConfiguredTargetLabel | Label | bxl.ConfiguredTargetNode],
*,
skip_incompatible: bool = True,
) -> None | bxl.AnalysisResult | dict[Label, bxl.AnalysisResult]
Runs analysis on the given configured labels, accepting an optional target_platform which is the target platform configuration used to resolve configurations of any unconfigured target nodes, and an optional skip_incompatible boolean that indicates whether to skip analysis of nodes that are incompatible with the target platform. The target_platform is either a string that can be parsed as a target label, or a target label.
The given labels is a providers expression of configured targets, which is either:
- a single target node or label, configured
- a single sub target label, configured
- a list of the two options above.
- targetset of configured target labels
This returns either a single analysis_result if the given labels argument is "singular",
or a dict keyed by sub target labels of analysis if the given labels argument
is list-like
Context.aquery
def Context.aquery(
target_platform: None | TargetLabel | str = ...,
) -> bxl.AqueryContext
Returns the aqueryctx that holds all the aquery functions. This function takes an optional parameter target_platform, which is the target platform configuration used to configured any unconfigured target nodes.
The target_platform is a target label, or a string that is a target label.
Context.audit
def Context.audit(
) -> bxl.AuditContext
Returns the audit_ctx that holds all the audit functions.
Context.build
def Context.build(
labels: ConfiguredTargetLabel | Label | ProvidersLabel | TargetLabel | bxl.ConfiguredTargetNode | bxl.UnconfiguredTargetNode | str | target_set | target_set | list[ConfiguredTargetLabel | Label | ProvidersLabel | TargetLabel | bxl.ConfiguredTargetNode | bxl.UnconfiguredTargetNode | str],
target_platform: None | TargetLabel | str = ...,
*,
materializations: str = "default",
) -> dict[Label, bxl.BuildResult]
Runs a build on the given labels, accepting an optional target_platform which is the target platform configuration used to resolve configurations. Note that when build() is called, the artifacts are materialized without needing to additionally call ensure() on them.
The given labels is a providers expression, which is either:
- a single string that is a
target pattern. - a single target node or label, configured or unconfigured
- a single provider label, configured or unconfigured
- a list of the two options above.
materializations can be one of:
- "default"
- defer to the configuration settings to decide whether to materialize or not
- "materialize"
- force materialization of build results at the end of the build.
- "skip"
- skip materialization of the build results
This returns a dict keyed by sub target labels mapped to bxl_build_results if the
given labels argument is list-like.
This function is not available on the bxl_ctx when called from dynamic_output.
Context.bxl_actions
def Context.bxl_actions(
*,
exec_deps: None | ProvidersLabel | TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[ProvidersLabel | TargetLabel | bxl.UnconfiguredTargetNode | str] = None,
toolchains: None | ProvidersLabel | TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[ProvidersLabel | TargetLabel | bxl.UnconfiguredTargetNode | str] = None,
target_platform: None | TargetLabel | str = ...,
exec_compatible_with: None | TargetLabel | bxl.UnconfiguredTargetNode | str | target_set | list[TargetLabel | bxl.UnconfiguredTargetNode | str] = None,
) -> bxl.Actions
Returns the bxl actions to create and register actions for this bxl function. This will have the execution platform resolved according to the execution deps and toolchains you pass into this function. You'll be able to access the analysis action factory of the correct execution platform, toolchains, and execution deps of the corresponding configuration via this context.
Actions created by bxl will not be built by default. Instead, they are marked to be built
by ctx.output.ensure(artifact) on the output module of the bxl_ctx. Only artifacts
marked by ensure will be built.
Sample usage:
def _impl_write_action(ctx):
bxl_actions = ctx.bxl_actions()
output = bxl_actions.actions.write("my_output", "my_content")
ensured = ctx.output.ensure(output)
ctx.output.print(ensured)
There are several optional named parameters:
exec_deps - These are dependencies you wish to access as executables for creating the action.
This is usually the same set of targets one would pass to rule's attr.exec_dep.
toolchains - The set of toolchains needed for the actions you intend to create.
target_platform - The intended target platform for your toolchains
exec_compatible_with - Explicit list of configuration nodes (like platforms or constraints)
that these actions are compatible with. This is the 'exec_compatible_with' attribute of a target.
If you passed in exec_deps or toolchains, you can access the resolved dependencies using the exec_deps
and toolchains attributes on the bxl_actions, which both return a dict of unconfigured subtarget labels
and their configured/resolved dependency objects.
Note that the keys of exec_deps and toolchains must be unconfigured subtarget labels (providers_labels),
and not unconfigured target labels. You can use ctx.unconfigured_sub_targets(...) or with_sub_target() on
target_label to create the label.
def _impl_run_action(ctx):
my_exec_dep = ctx.unconfigured_sub_targets("foo//bar:baz") # has some provider that you would use in the action
bxl_actions = ctx.bxl_actions(exec_deps = [my_exec_dep]) # call once, reuse wherever needed
output = bxl_actions.actions.run(
[
"python3",
bxl_actions.exec_deps[my_exec_dep][RunInfo], # access resolved exec_deps on the `bxl_actions`
out.as_output(),
],
category = "command",
local_only = True,
)
ctx.output.ensure(output)
When called from a dynamic_output, bxl_actions() cannot be configured with a different execution
platform resolution from the parent BXL.