Querying Last updated July 6, 2022

Configured Graph Queries

cquery "cquery is a variant of query that correctly handles select() and build options' effects on the build graph."

Action Graph Queries

Examples:

PPX processing involves "hidden" actions that run a PPX to transform source files. These actions are a side-effect of building targets (ocaml_module or ocaml_signature) that undergo PPX transformation, but aquery will show them:

.../demos_obazl/rules_ocaml]$ bazel aquery ns/topdown/ppx:Blue
INFO: Analyzed target //ns/topdown/ppx:Blue (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
action 'Writing script ns/topdown/ppx/Blue_ppx.sh'
  Mnemonic: FileWrite                                                                  (1)
  Target: //ns/topdown/ppx:Blue
  Configuration: darwin-fastbuild
  Execution platform: @local_config_platform//:host
  ActionKey: e97323d347578da30c04c0bbaf0ee6df47984ca53994ed684df3be9ea426a0f9
  Inputs: []
  Outputs: [bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/Blue_ppx.sh]

action 'ppx_transform ocaml_module: demos//ns/topdown/ppx:Blue'
  Mnemonic: OCamlPpxTransform                                                         (1)
  Target: //ns/topdown/ppx:Blue
  Configuration: darwin-fastbuild
  Execution platform: @local_config_platform//:host
  ActionKey: bee23a7eacaf95dbdfd5590474d6feab927496e1e934fa40e1a8d754ed20015c
  Inputs: [bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/Blue_ppx.sh, bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/ppx.exe, bazel-out/darwin-fastbuild/internal/_middlemen/ns_Stopdown_Sppx_Sppx.exe-runfiles, ns/topdown/ppx/blue.ml]
  Outputs: [bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.ml]
  Command Line: (exec bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/Blue_ppx.sh \
    -o \
    ../bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.ml \
    -impl \
    ns/topdown/ppx/blue.ml)
# Configuration: f980a41ed8e8fc07b34c21c148caeaaeea788b6ece312887882afc3763631455
# Execution platform: @local_config_platform//:host

action 'sys>sys compiling ocaml_module: demos//ns/topdown/ppx:Blue'
  Mnemonic: CompileOCamlModule                                                        (1)
  Target: //ns/topdown/ppx:Blue
  Configuration: darwin-fastbuild
  Execution platform: @local_config_platform//:host
  ActionKey: cb0b4b940adbaa21e77b289d2b57d8b34d7513de905936a8670c616041f98dfa
  Inputs: [bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.ml, external/ocaml/bin/ocamlopt.opt]
  Outputs: [bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.cmi, bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.cmx, bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.o]
  Command Line: (exec external/ocaml/bin/ocamlopt.opt \
    -keep-locs \
    -noassert \
    -short-paths \
    -strict-formats \
    -strict-sequence \
    -w \
    @1..3@5..28@30..39@43@46..47@49..57@61..62-40 \
    -I \
    bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl \
    -c \
    -impl \
    bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.ml \
    -o \
    bazel-out/darwin-fastbuild/bin/ns/topdown/ppx/__obazl/Blue.cmx)
# Configuration: f980a41ed8e8fc07b34c21c148caeaaeea788b6ece312887882afc3763631455
# Execution platform: @local_config_platform//:host
1 Each action has a Mnemonic.

You can filter aquery by mnemonics. In this demo (ns/topdown/ppx), an ocaml_ns_library target named color lists three submodules, each of which is PPX-transformed. That means the example above is a little misleading, since it builds ns/topdown/ppx:Blue independent of the namespace. When you build ns/topdown/ppx:color, each submodule will not only be preprocessed by a PPX, but also renamed. The following aquery will show this:

...azl/demos_obazl/rules_ocaml]$ bazel aquery 'mnemonic("OCamlPpxTransform", deps(ns/topdown/ppx:color))'
INFO: Analyzed target //ns/topdown/ppx:color (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
WARNING: Targets were missing from graph: [ConfiguredTargetKey{label=@ocaml//toolchain/adapters/local:ncnc, config=BuildConfigurationValue.Key[31e6065273d39a7233241ad2738425079768663b03b77650e19688c9f47e747f]}]
WARNING: Targets were missing from graph: [ConfiguredTargetKey{label=@ocaml//toolchain/adapters/local:ncnc, config=BuildConfigurationValue.Key[33036bf992ae1cd9400769abcf7b91b3cfa72b954d6c3660ef1958c812d92cf2]}]
action 'ppx_transform ocaml_module: demos//ns/topdown/ppx:Red'
  Mnemonic: OCamlPpxTransform
  Target: //ns/topdown/ppx:Red
  Configuration: darwin-fastbuild-ST-2386c8310427
  Execution platform: @local_config_platform//:host
  ActionKey: 0198e3f7633f19b056cb5a8fecd8886a8bc7f3911d670626a35e288bfa051a98
  Inputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Red_ppx.sh, bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/ppx.exe, bazel-out/darwin-fastbuild-ST-2386c8310427/internal/_middlemen/ns_Stopdown_Sppx_Sppx.exe-runfiles, ns/topdown/ppx/red.ml]
  Outputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Red.ml]
  Command Line: (exec bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Red_ppx.sh \ (1)
    -o \
    ../bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Red.ml \  (3)
    -impl \
    ns/topdown/ppx/red.ml)             (2)
# Configuration: 31e6065273d39a7233241ad2738425079768663b03b77650e19688c9f47e747f
# Execution platform: @local_config_platform//:host

action 'ppx_transform ocaml_module: demos//ns/topdown/ppx:Green'
  Mnemonic: OCamlPpxTransform
  Target: //ns/topdown/ppx:Green
  Configuration: darwin-fastbuild-ST-2386c8310427
  Execution platform: @local_config_platform//:host
  ActionKey: 6c45a135981e2753eb67ddf97a63d7e13caea275e386d1e8e051a64598adc246
  Inputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Green_ppx.sh, bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/ppx.exe, bazel-out/darwin-fastbuild-ST-2386c8310427/internal/_middlemen/ns_Stopdown_Sppx_Sppx.exe-runfiles, ns/topdown/ppx/green.ml]
  Outputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Green.ml]
  Command Line: (exec bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Green_ppx.sh \
    -o \
    ../bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Green.ml \
    -impl \
    ns/topdown/ppx/green.ml)
# Configuration: 31e6065273d39a7233241ad2738425079768663b03b77650e19688c9f47e747f
# Execution platform: @local_config_platform//:host

action 'ppx_transform ocaml_module: demos//ns/topdown/ppx:Blue'
  Mnemonic: OCamlPpxTransform
  Target: //ns/topdown/ppx:Blue
  Configuration: darwin-fastbuild-ST-2386c8310427
  Execution platform: @local_config_platform//:host
  ActionKey: 44fd9066b7d6c9e0b74de9eb13f0e0d7a440825bf104662d368f5da7af3ac1b5
  Inputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Blue_ppx.sh, bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/ppx.exe, bazel-out/darwin-fastbuild-ST-2386c8310427/internal/_middlemen/ns_Stopdown_Sppx_Sppx.exe-runfiles, ns/topdown/ppx/blue.ml]
  Outputs: [bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Blue.ml]
  Command Line: (exec bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/Blue_ppx.sh \
    -o \
    ../bazel-out/darwin-fastbuild-ST-2386c8310427/bin/ns/topdown/ppx/__obazl/Color__Blue.ml \
    -impl \
    ns/topdown/ppx/blue.ml)
# Configuration: 31e6065273d39a7233241ad2738425079768663b03b77650e19688c9f47e747f
# Execution platform: @local_config_platform//:host
1 The shell script (written by a previous FileWrite action) runs the ppx executable.
2 Input is the original file.
3 Output is transformed and renamed.

This shows that PPX processing and renaming are accomplished by the same OCamlPpxTransform action.

The mnemonic argument supports regexes; the following aquery would show all of the actions whose mnemonic includes OCaml:

bazel aquery 'mnemonic(".OCaml.", deps(ns/topdown/ppx:ppx.exe))'

The (rather lengthy) output shows the following actions: CompileOCamlPpxModule, CompileOCamlNsResolver, LinkOCamlPpxExecutable, CompileOCamlModule, and OCamlPpxTransform.

Without filtering the action for all dependencies would be shown:

bazel aquery 'deps(ns/topdown/ppx:color)'

This would include actions with mnemonic ocaml_import (since the PPX executable depends on @ppxlib//:ppxlib and all of its dependencies, imported from OPAM), a Genrule action (since the PPX executable depends on a file created by a genrule target), some FileWrite actions (to generate the source file compiled by the CompileOCamlNsResolver action, and write the shell scripts used by the OCamlPpxTransform action to run the PPX executable), and a large number of actions generated by Bazel itself, to generate toolchains, configure runfiles, etc.