Skip to main content

Bxl APIs

ctarget_set

def ctarget_set(
nodes: list[bxl.ConfiguredTargetNode] = ...,
) -> target_set

Creates a target set from a list of configured nodes.

Sample usage:

def _impl_ctarget_set(ctx):
    targets = bxl.ctarget_set([cnode_a, cnode_b])
    ctx.output.print(type(targets))
    ctx.output.print(len(targets))

dynamic_actions

def dynamic_actions(
,
impl: typing.Callable[", actions: actions, **kwargs: typing.Any", list[provider]],
attrs: dict[str, DynamicAttrType],
) -> DynamicActionCallable

Create new bxl dynamic action callable. Returned object will be callable, and the result of calling it can be passed to ctx.actions.dynamic_output_new.


fail_no_stacktrace

def fail_no_stacktrace(*args) -> None

file_set

def file_set() -> file_set

Creates an empty file set for configured nodes.

Sample usage:

def _impl_file_set(ctx):
    files = file_set()
    ctx.output.print(type(files))
    ctx.output.print(len(files))

get_path_without_materialization

def get_path_without_materialization(
this: artifact,
ctx: bxl.Context,
/,
*,
abs: bool = False,
) -> str

The output path of an artifact-like (source, build, declared). Takes an optional boolean to print the absolute or relative path. Note that this method returns an artifact path without asking for the artifact to be materialized (i.e. it may not actually exist on the disk yet).

This is a risky function to call because you may accidentally pass this path to further BXL actions that expect the artifact to be materialized. If this happens, the BXL script will error out. If you want the path without materialization for other uses that don’t involve passing them into further actions, then it’s safe.

Sample usage:

def _impl_get_path_without_materialization(ctx):
    owner = ctx.cquery().owner("cell//path/to/file")[0]
    artifact = owner.get_source("cell//path/to/file", ctx)
    source_artifact_project_rel_path = get_path_without_materialization(artifact, ctx)
    ctx.output.print(source_artifact_project_rel_path) # Note this artifact is NOT ensured or materialized

get_paths_without_materialization

def get_paths_without_materialization(
cmd_line: CellPath | artifact | cell_root | cmd_args | label | output_artifact | project_root | resolved_macro | str | tagged_command_line | target_label | transitive_set_args_projection | write_json_cli_args | RunInfo,
ctx: bxl.Context,
/,
*,
abs: bool = False,
)

The output paths of a cmd_args() inputs. The output paths will be returned as a list. Takes an optional boolean to print the absolute or relative path. Note that this method returns an artifact path without asking for the artifact to be materialized, (i.e. it may not actually exist on the disk yet).

This is a risky function to call because you may accidentally pass this path to further BXL actions that expect the artifact to be materialized. If this happens, the BXL script will error out. If you want the path without materialization for other uses that don’t involve passing them into further actions, then it’s safe.

Sample usage:

def _impl_get_paths_without_materialization(ctx):
    node = ctx.configured_targets("root//bin:the_binary")
    providers = ctx.analysis(node).providers()
    path = get_paths_without_materialization(providers[RunInfo], abs=True) # Note this artifact is NOT ensured or materialized
    ctx.output.print(path)

main

def main(
*,
impl: typing.Callable,
cli_args: dict[str, bxl.CliArgs],
doc: str = "",
)

now

def now() -> instant

Creates an Instant at the current time.

Sample usage:

def _impl_elapsed_millis(ctx):
    instant = now()
    time_a = instant.elapsed_millis()
    # do something that takes a long time
    time_b = instant.elapsed_millis()

    ctx.output.print(time_a)
    ctx.output.print(time_b)

This function is only accessible through Bxl.


utarget_set

def utarget_set(
nodes: list[bxl.UnconfiguredTargetNode] = ...,
) -> target_set

Creates a target set from a list of unconfigured nodes.

Sample usage:

def _impl_utarget_set(ctx):
    targets = bxl.utarget_set([unode_a, unode_b])
    ctx.output.print(type(targets))
    ctx.output.print(len(targets))