Skip to main content

cqueryctx type

The context for performing cquery operations in bxl. The functions offered on this ctx are the same behaviour as the query functions available within cquery command.

Query results are target_sets of target_nodes, which supports iteration, indexing, len(), set addition/subtraction, and equals().

cqueryctx.allpaths

def cqueryctx.allpaths(
from: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node],
to: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The allpaths query for computing all dependency paths.


cqueryctx.attrfilter

def cqueryctx.attrfilter(
attr: str,
value: str,
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The attrfilter query for rule attribute filtering.


cqueryctx.attrregexfilter

def cqueryctx.attrregexfilter(
attribute: str,
value: str,
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The attrregexfilter query for rule attribute filtering with regex.

Sample usage:

def _impl_attrregexfilter(ctx):
filtered = ctx.cquery().attrregexfilter("foo", "he.lo", "bin/kind/...")
ctx.output.print(filtered)

cqueryctx.buildfile

def cqueryctx.buildfile(
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> file_set

Find the build file(s) that defines a target or a target set.

Sample usage:

def _buildfile_impl(ctx):
owner = ctx.cquery().owner(["bin/TARGET", "bin/kind"])
result = ctx.cquery().buildfile(owner)
ctx.output.print(result)

cqueryctx.deps

def cqueryctx.deps(
universe: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node],
depth: None | int = None,
filter: None | str = None
) -> target_set

The deps query for finding the transitive closure of dependencies.

Sample usage:

def _impl_deps(ctx):
result = ctx.cquery().deps("root//bin:the_binary", 1)
ctx.output.print(result)

cqueryctx.eval

def cqueryctx.eval(
query: str,
query_args: None | target_set | list[str] = None,
target_universe: None | list[str] | tuple[str, ...] = None
)

Evaluates some general query string. query_args can be a target_set of unconfigured nodes, or a list of strings. Returns a dict of target labels mapped to their target_set results if query_args was passed in, otherwise returns a single target_set.

Sample usage:

def _impl_eval(ctx):
result1 = ctx.cquery().eval("inputs(root//bin:the_binary)")
ctx.output.print(result1)

result2 = ctx.cquery().eval("inputs(%s)", query_args = ["cell//path/to/file:target"])
ctx.output.print(result2)

cqueryctx.filter

def cqueryctx.filter(
regex: str,
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The filter query for filtering targets by name.

Sample usage:

def _impl_filter(ctx):
result = ctx.cquery().filter(".*the_binary", "root//...")
ctx.output.print(result)

cqueryctx.inputs

def cqueryctx.inputs(
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> file_set

The inputs query for finding input files.

Sample usage:

def _impl_inputs(ctx):
result = ctx.cquery().inputs("root//bin:the_binary")
ctx.output.print(result)

cqueryctx.kind

def cqueryctx.kind(
regex: str,
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The kind query for filtering targets by rule type.

Sample usage:

def _impl_kind(ctx):
kind = ctx.cquery().kind(".*1", "bin/kind/...")
ctx.output.print(kind)

cqueryctx.owner

def cqueryctx.owner(
files: file_set | str | list[str] | tuple[str, ...],
universe: None | configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node] = None
) -> target_set

The owner query for finding targets that own specified files. Note that if you do not pass in a cell path (where the format is <cell>//path/to/file), the path is resolved against the cell that the BXL script lives in. If you need to evaluate a file path that lives in a different cell, you must pass in the fully qualified cell path.

Sample usage:

def _owner_impl(ctx):
owner = ctx.cquery().owner("bin/TARGETS.fixture", "foo//target/universe/...")
ctx.output.print(owner)

cqueryctx.rdeps

def cqueryctx.rdeps(
universe: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node],
from: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node],
depth: int = _
) -> target_set

The rdeps query for finding the transitive closure of reverse dependencies.

Sample usage:

def _impl_rdeps(ctx):
result = ctx.cquery().rdeps("root//bin:the_binary", "//lib:file1", 100)
ctx.output.print(result)

cqueryctx.somepath

def cqueryctx.somepath(
from: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node],
to: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

cqueryctx.testsof

def cqueryctx.testsof(
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The testsof query for listing the tests of the specified targets.


cqueryctx.testsof_with_default_target_platform

def cqueryctx.testsof_with_default_target_platform(
targets: configured_target_label | str | target_label | target_node | target_set | target_set | unconfigured_target_node | list[configured_target_label | str | target_label | target_node | unconfigured_target_node]
) -> target_set

The testsof query for listing the tests of the specified targets. Performs default target platform resolution under the hood for the tests found.