Search code examples
bazelbazel-query

bazel query to list targets dependent on file


Given a file name, I would like to determine all *_test rules which depend on that file.

Is there any way to query this information from Bazel, either through bazel query or through some other means?


Solution

  • bazel query 'rdeps(tests(//...), //build_tests:gflags.cc)'. tests(//...) gives you all the *_test rules, and rdeps gives you reverse dependencies of its second argument within the first argument.