function Query.eval
The query system provides a programmatic interface for analyzing build dependencies and target relationships. Queries are constructed using a chain API and are lazily evaluated only when
.eval() is explicitly called.
The entry point is ctx.bazel.query(), which returns a query for creating initial
query expressions. Most operations operate on query objects, which represent
sets of targets that can be filtered, transformed, and combined.
Example
flags: - Command flags to pass tobazel query(between the expression and--output). Callers that runqueryalongsidebuild/testunder--ignore_all_rc_filesMUST forward the rc-expanded command flags here, so the query resolves external repositories the same way the build does (e.g. an rc-set--noenable_bzlmod/--enable_workspace). Omitting them lets the query diverge from the build and fail on repos the build can see. Accepts the samestr | (str, version-constraint)shape asctx.bazel.build/.test; version-gated flags are filtered against the running Bazel version identically.announce_version: - Print anINFO: Bazel <version>line before spawning. Resolved from the--announce-bazel-versiontask flag.announce_command: - Print anINFO: Spawning: <command>line before spawning. Resolved from the--announce-bazel-commandtask flag. Both mirror thectx.bazel.build/.testdisclosure.
function Query.raw
Replaces the query
expression with a raw query expression string.
This escape hatch allows direct use of the underlying query language for complex cases,
while still supporting further chaining.

