Can bazel print a hierarchy of the build rules?

315 Views Asked by At

Bazel rules can compose other bazel rules. For example:

def cpp_library(name,deps=[]):

    explicit_cpp_file = name + ".cpp"
    explicit_hpp_file = name + ".hpp"

    native.cc_library(
        name = name,
        srcs = [explicit_cpp_file],
        hdrs = [explicit_hpp_file],
        deps = deps,
    )

Here we see that the cpp_library uses native.cc_library.
Is there a way to use a bazel query to print this relationship information?

You can imagine the difficulty of wanting to know which rules are used by which other rules as a project grows in size and many rules are available.

1

There are 1 best solutions below

0
On

You can get this information through bazel query with --output. --output build will show the rules after macros have been run. --output graph will show the relationships between rules, e.g.

bazel query //some/package --output graph | xdot

(or e.g. | dot -Tpng > /tmp/dep.png)

See https://docs.bazel.build/versions/master/query.html#output-formats