How to query which target produces particular file?

767 views
Skip to first unread message

Konstantin

unread,
Dec 19, 2022, 8:14:27 PM12/19/22
to bazel-discuss
In Bazel 6 cquery got  --output=files to find which files are produced by particular target. This is great, but I wonder how to answer the opposite question - find the target which produces particular file? Any ideas?

Thank you!
Konstantin

Tobias Werth

unread,
Dec 20, 2022, 3:18:48 AM12/20/22
to Konstantin, bazel-discuss
You can use bazel aquery with the outputs filter for this.

Example:

$ bazel cquery --output=files //src:package-zip_jdk_minimal 2> /dev/null
bazel-out/k8-fastbuild/bin/src/package_jdk_minimal.zip
$ bazel aquery 'outputs(".*k8-fastbuild/bin/src/package_jdk_minimal.zip", deps(//src:bazel))'
INFO: Analyzed target //src:bazel (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
action 'Executing genrule //src:package-zip_jdk_minimal'
  Mnemonic: Genrule
  Target: //src:package-zip_jdk_minimal
  Configuration: k8-fastbuild
  Execution platform: //:default_host_platform
  ActionKey: dada34bdce343bf25d8847c80b0063be22e869709938ab4648169edfc6135db3
  Inputs: [bazel-out/k8-fastbuild/bin/src/embedded_tools_jdk_minimal.zip, bazel-out/k8-fastbuild/bin/src/install_base_key_jdk_minimal, bazel-out/k8-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar, bazel-out/k8-fastbuild/bin/src/main/java/net/starlark/java/eval/libcpu_profiler.so, bazel-out/k8-fastbuild/bin/src/main/tools/build-runfiles, bazel-out/k8-fastbuild/bin/src/main/tools/daemonize, bazel-out/k8-fastbuild/bin/src/main/tools/linux-sandbox, bazel-out/k8-fastbuild/bin/src/main/tools/process-wrapper, bazel-out/k8-fastbuild/bin/src/platforms.zip, bazel-out/k8-fastbuild/bin/tools/osx/xcode-locator, bazel-out/k8-opt-exec-EDC14992/bin/src/package-bazel-on-host-platform.sh, external/bazel_tools/tools/genrule/genrule-setup.sh]
  Outputs: [bazel-out/k8-fastbuild/bin/src/package_jdk_minimal.zip]
  Command Line: (exec /bin/bash \
    -c \
    'source external/bazel_tools/tools/genrule/genrule-setup.sh; bazel-out/k8-opt-exec-EDC14992/bin/src/package-bazel-on-host-platform.sh bazel-out/k8-fastbuild/bin/src/package_jdk_minimal.zip  bazel-out/k8-fastbuild/bin/src/embedded_tools_jdk_minimal.zip bazel-out/k8-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar bazel-out/k8-fastbuild/bin/src/install_base_key_jdk_minimal bazel-out/k8-fastbuild/bin/src/platforms.zip bazel-out/k8-fastbuild/bin/src/main/java/net/starlark/java/eval/libcpu_profiler.so bazel-out/k8-fastbuild/bin/src/main/tools/build-runfiles bazel-out/k8-fastbuild/bin/src/main/tools/process-wrapper bazel-out/k8-fastbuild/bin/src/main/tools/linux-sandbox bazel-out/k8-fastbuild/bin/tools/osx/xcode-locator bazel-out/k8-fastbuild/bin/src/main/tools/daemonize')
# Configuration: 148f986585b9a72c066d5ebb0aefbb9163f15f0fb55c220bb9390742d4a32468
# Execution platform: //:default_host_platform


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/511eddec-2b42-4234-8fe2-b1ab521f8d53n%40googlegroups.com.


--

Google Germany GmbH

Erika-Mann-Straße 33

80636 München


Geschäftsführer: Paul Manicle, Liana Sebastian

Registergericht und -nummer: Hamburg, HRB 86891

Sitz der Gesellschaft: Hamburg


Diese E-Mail ist vertraulich. Falls Sie diese fälschlicherweise erhalten haben sollten, leiten Sie diese bitte nicht an jemand anderes weiter, löschen Sie alle Kopien und Anhänge davon und lassen Sie mich bitte wissen, dass die E-Mail an die falsche Person gesendet wurde. 

     

This e-mail is confidential. If you received this communication by mistake, please don't forward it to anyone else, please erase all copies and attachments, and please let me know that it has gone to the wrong person.

Konstantin

unread,
Dec 20, 2022, 10:38:25 AM12/20/22
to bazel-discuss
Oh, I see - "outputs" filter with aquery. Thank you, Tobias! I saw "-output=files" in cquery and for that reason limited my search for the answer to cquery while naturally aquery is more suitable for inputs/outputs discovery.
Reply all
Reply to author
Forward
0 new messages