Aquery Environment
Functions
- all_actions: Obtain all the actions declared within the analysis of a given target.
- all_outputs: Obtain the actions for all the outputs provided by the
DefaultInfofor the targets passed - allbuildfiles: Target build file with transitive imports.
- allpaths: All dependency paths.
- attrfilter: Rule attribute filtering.
- attrregexfilter: Rule attribute filtering with regex.
- buildfile: Target build file.
- configuration_deps: A filter function that can be used in the query expression of
depsquery function. - deps: Find the dependencies of the targets in the given target universe.
- except: Computes the arguments that are in argument A but not in argument B.
- exec_deps: A filter function that can be used in the query expression of
depsquery function. - filter: Filter targets or files by regex.
- first_order_deps: A filter function that can be used in the query expression of
depsquery function. - inputs: Non-transitive inputs.
- intersect: Computes the set intersection over the given arguments.
- kind: Filter targets by rule type.
- labels: Not implemented.
- nattrfilter: Negative rule attribute filtering, opposite of
attrfilter. - owner: Targets owning the given file.
- rbuildfiles: Build file reverse dependencies.
- rdeps: Find the reverse dependencies of the targets in the given target universe.
- somepath: Shortest dependency path between two sets of targets.
- target_deps: A filter function that can be used in the query expression of
depsquery function. - targets_in_buildfile: Targets in build file.
- testsof: Tests of specified targets.
- toolchain_deps: A filter function that can be used in the query expression of
depsquery function. - union: Computes the set union over the given arguments.
all_actions(targets: target expression)
Obtain all the actions declared within the analysis of a given target.
This operation only makes sense on a target literal (it is a simple passthrough when passed an action).
all_outputs(targets: target expression)
Obtain the actions for all the outputs provided by the DefaultInfo for the targets passed
as input. This includes both the default_outputs and other_outputs.
This operation only makes sense on a target literal (it does nothing if passed something else).
allbuildfiles(universe: target expression)
Target build file with transitive imports.
For each target in the provided target expression, returns the build file where the target is defined, along with all transitive imports of that file.
For example:
$ buck2 uquery 'allbuildfiles(//foo:bar)'
foo/BUCK
foo/defs_dependent_on_utils.bzl
baz/utils.bzl
allpaths(from: target expression, to: target expression, captured_expr: ?query expression)
All dependency paths.
Generates a graph of paths between the target expressions from and to, based on the dependencies between nodes.
For example:
$ buck2 uquery "allpaths('//foo:bar', '//foo/bar/lib:baz')"
returns the dependency graph rooted at the target node //foo:bar, including all target nodes that transitively depend on //foo/bar/lib:baz.
Arguments from and to can themselves be expressions, for example:
$ buck2 uquery "allpaths(kind(java_library, '//...'), '//foo:bar')"
shows all the paths between any target with rule type java_library in the repository and the target //foo:bar.
We recommend using it with the --output-format=dot parameter to generate a Graphviz DOT file that can then be rendered as an image.
$ buck2 uquery "allpaths(//buck2:buck2, //buck2/app/buck2_validation:buck2_validation)" --output-format=dot > result.dot
$ dot -Tpng result.dot -o image.png
produces the following image:
attrfilter(attr: string, value: string, targets: target expression)
Rule attribute filtering.
Evaluates the given target expression and filters the resulting build targets to those where the specified attribute contains the specified value. In this context, the term attribute refers to an argument in a build rule, such as name, headers, srcs, or deps.
- If the attribute is a single value, say
name, it is compared to the specified value, and the target is returned if they match. - If the attribute is a list, the target is returned if that list contains the specified value.
- If the attribute is a dictionary, the target is returned if the value exists in either the keys or the values of the dictionary.
For example:
$ buck2 uquery "attrfilter(deps, '//buck2/app/buck2_validation:buck2_validation', '//...')"
//buck2/app/buck2:buck2-bin
//buck2/app/buck2_server:buck2_server
//buck2/app/buck2_server:buck2_server-unittest
returns targets that contain //buck2/app/buck2_validation:buck2_validation target in their deps attribute.
attrregexfilter(attr: string, value: string, targets: target expression)
Rule attribute filtering with regex.
Similar to the attrfilter function except that it takes a regular expression as the second argument.
For example:
$ buck2 uquery "attrregexfilter(deps, '.+validation$', '//...')"
//buck2/app/buck2:buck2-bin
//buck2/app/buck2_server:buck2_server
//buck2/app/buck2_server:buck2_server-unittest
returns targets whose deps attribute contains at least one target suffixed with 'validation'.
buildfile(targets: target expression)
Target build file.
For each target in the provided target expression, returns the build file where the target is defined.
For example:
$ buck2 uquery 'buildfile(//buck2:buck2)'
buck2/BUCK
In order to find the build file associated with a source file, combine the owner operator with buildfile. Examples:
$ buck2 uquery "buildfile(//buck2/app/buck2_action_impl_tests:buck2_action_impl_tests)"
and
$ buck2 uquery "buildfile(owner(app/buck2_action_impl_tests/src/context.rs))"
both return buck2/app/buck2_action_impl_tests/TARGETS.
configuration_deps()
A filter function that can be used in the query expression of deps query function.
Returns the output of deps function for configuration dependencies (that appear as conditions in selects).
Example:
buck2 cquery "deps('//foo:bar', 1, configuration_deps())"
deps(targets: target expression, depth: integer, captured_expr: ?query expression)
Find the dependencies of the targets in the given target universe.
The first parameter targets is a specific target or target pattern. It specifies the targets to find dependencies for.
The second argument depth is an optional integer literal specifying an upper bound on the depth of the search. A value of one (1) specifies that buck query should return only direct dependencies. If the depth parameter is omitted, the search is unbounded.
The third argument captured_expr is an optional filter expression that controls the
traversal. The expression is evaluated for each node and returns the child nodes to recurse
on when collecting transitive dependencies. Available filters are configuration_deps(),
exec_deps(), first_order_deps(), target_deps(), and toolchain_deps().
The first_order_deps() operator returns a set that contains the first-order dependencies
of the current node. It can be combined with other filter functions, for example,
kind(java_library, first_order_deps()) to make the deps traversal only traverse
java_library targets. The first_order_deps() operator can only be used as an argument
passed to deps().
The returned values include the nodes from the targets argument itself.
For example following uquery:
$ buck2 uquery "deps(//buck2:buck2, 1)"
returns all targets that //buck2:buck2 depends on directly.
except(left: any value, right: any value)
Computes the arguments that are in argument A but not in argument B.
Can be used with the - symbol. This operator is NOT commutative.
The parser treats this operator as left-associative and of equal precedence, so we recommend that you use parentheses if you need to ensure a specific order of evaluation. A parenthesized expression resolves to the value of the expression it encloses.
Example:
buck2 aquery "deps('//foo:bar') except deps('//baz:lib')" is the same as
buck2 aquery "deps('//foo:bar') - deps('//baz:lib')"
Both return the targets that //foo:bar depends on and that //baz:lib does NOT depend on.