Skip to main content

cquery

This document provides an overview of the commands and options available under buck2 cquery.

buck2 cquery

Perform queries on the configured target graph

The configured target graph includes information about the configuration (platforms) and transitions involved in building targets. In the configured graph, selects are fully resolved. The same target may appear in multiple different configurations (when printed, the configuration is after the target in parentheses).

A user can specify a --target-universe flag to control how literals are resolved. When provided, any literals will resolve to all matching targets within the universe (which includes the targets passed as the universe and all transitive deps of them). When not provided, we implicitly set the universe to be rooted at every target literal in the cquery.

Run buck2 docs cquery or https://buck2.build/docs/users/query/cquery/ for more documentation about the functions available in cquery expressions.

Examples:

Print all the attributes of a target

buck2 cquery //java/com/example/app:amazing --output-all-attributes

List the deps of a target (special characters in a target will require quotes):

buck2 cquery 'deps("//java/com/example/app:amazing+more")'

Usage: buck2 cquery [OPTIONS] <QUERY> [QUERY_ARGS]...

Arguments:

  • <QUERY> the query to evaluate

  • <QUERY_ARGS> list of literals for a multi-query (one containing %s or %Ss)

Options:

  • -A, --output-all-attributes Output all attributes, equivalent of --output-attribute ''.

    Avoid using this flag in automation because it may be expensive to produce certain attributes, and because it makes harder to track which special attributes are used.

  • -B, --output-basic-attributes Output basic attributes, namely those the user can supply, plus rule type and package name

  • -a, --output-attribute <ATTRIBUTE> Regular expressions to match attributes. Regular expressions are used in "search" mode, so for example empty string matches all attributes including special attributes.

    When using in automation, please specify the regular expression to match the attribute precisely, for example --output-attribute '^headers$' to make it easier to track which special attributes are used.

  • --output-attributes <ATTRIBUTE> Deprecated: Use --output-attribute instead.

    List of space-separated attributes to output, --output-attributes attr1 attr2.

  • --json Output in JSON format

  • --dot Output in Graphviz Dot format

  • --dot-compact Output in a more compact format than Graphviz Dot

  • --output-format <dot|dot_compact|json|starlark|html> Output format (default: list).

    dot - dot graph format.

    dot_compact - compact alternative to dot format.

    json - JSON format.

    starlark - targets are printed like starlark code that would produce them. html - html file containing interactive target graph.

    • Possible values:
      • dot
      • json
      • dot_compact
      • starlark
      • html
  • --show-providers Show the providers of the query result instead of the attributes and labels

  • -u, --target-universe <TARGET_UNIVERSE> Comma separated list of targets to construct a configured target universe.

    When the option is specified, command targets are be resolved in this universe. Additionally, --target-platforms= and --modifier= flags are be used to configure the universe targets, not the command targets.

    This argument is particularly recommended on most non-trivial cqueries. In the absence of this argument, buck2 will use the target literals in your cquery expression as the value for this argument, which may not be what you want.

  • --target-platforms <PLATFORM> Configuration target (one) to use to configure targets

  • -m, --modifier <VALUE> A configuration modifier to configure all targets on the command line. This may be a constraint value target.

  • -c, --config <SECTION.OPTION=VALUE> List of config options

  • --config-file <PATH> List of config file paths

  • --fake-host <HOST>

    • Possible values:
      • default
      • linux
      • macos
      • windows
  • --fake-arch <ARCH>

    • Possible values:
      • default
      • aarch64
      • x8664
  • --fake-xcode-version <VERSION-BUILD> Value must be formatted as: version-build (e.g., 14.3.0-14C18 or 14.1-14B47b)

  • --reuse-current-config Re-uses any --config values (inline or via modefiles) if there's a previous command, otherwise the flag is ignored.

    If there is a previous command and --reuse-current-config is set, then the old config is used, ignoring any overrides.

    If there is no previous command but the flag was set, then the flag is ignored, the command behaves as if the flag was not set at all.

  • --exit-when-different-state Used for exiting a concurrent command when a different state is detected

  • --preemptible <PREEMPTIBLE> Used to configure when this command could be preempted by another command for the same isolation dir.

    Normally, when you run two commands - from different terminals, say - buck2 will attempt to run them in parallel. However, if the two commands are based on different state, that is they either have different configs or different filesystem states, buck2 cannot run them in parallel. The default behavior in this case is to block the second command until the first completes.

    • Possible values:
      • never: (default) When another command starts that cannot run in parallel with this one, block that command
      • always: When another command starts, interrupt this command, even if they could run in parallel. There is no good reason to use this other than that it provides slightly nicer superconsole output
      • ondifferentstate: When another command starts that cannot run in parallel with this one, interrupt this command
  • --disable-starlark-types Disable runtime type checking in Starlark interpreter.

    This option is not stable, and can be used only locally to diagnose evaluation performance problems.

  • --stack Record or show target call stacks.

    Starlark call stacks will be included in duplicate targets error.

    If a command outputs targets (like targets command), starlark call stacks will be printed after the targets.

  • --console <super|simple|...> Which console to use for this command

    • Default value: auto
    • Possible values:
      • auto
      • none
      • simple
      • simplenotty
      • simpletty
      • super
  • --ui <UI> Configure additional superconsole ui components.

    Accepts a comma-separated list of superconsole components to add. Possible values are:

    dice - shows information about evaluated dice nodes debugevents - shows information about the flow of events from buckd

    These components can be turned on/off interactively. Press 'h' for help when superconsole is active.

    • Possible values:
      • dice
      • debugevents
      • io: I/O panel
      • re: RE panel
  • --no-interactive-console Disable console interactions

  • --event-log <PATH> Write events to this log file

  • --write-build-id <PATH> Write command invocation id into this file

  • --unstable-write-invocation-record <PATH> Write the invocation record (as JSON) to this path. No guarantees whatsoever are made regarding the stability of the format

  • --command-report-path <PATH> Write the command report to this path. A command report is always written to buck-out/v2/&lt;uuid&gt;/command_report even without this flag

  • --profile-mode <PROFILE_MODE> Profile target loading.

    When this option is enabled, Buck will profile every BUCK file loaded during the query and merge the results into a single profile. The command may return cached profile data if BUCK files were not invalidated.

    • Possible values:
      • time-flame
      • heap-allocated
      • heap-retained
      • heap-flame-allocated
      • heap-flame-retained
      • heap-summary-allocated
      • heap-summary-retained
      • statement
      • bytecode
      • bytecode-pairs
      • typecheck
      • coverage
      • none
  • --profile-output <PROFILE_OUTPUT> Where to write profile output