Tracing Dependencies in Bazel
A few weeks ago, I worked on splitting one of the biggest module that sometimes when we have changes on that module, become a bottleneck when compiling.
While working on it, I also curious about its dependency, also who else depend on this module. Luckily Bazel provide us with a command to query and visualize dependency tree.
By default, Bazel can output query in graph format, to visualize it you need a program called graphviz
which you can install using brew
Here are some query I learned:
To query dependencies on a module:
bazelisk query --noimplicit_deps 'kind(rule, deps(//ios/Shop/Shop:Shop))' --output=graph | dot -Tsvg > ~/Desktop/test.svg
Next if we want to know the dependencies relation between two modules
[bazelisk query "allpaths(//ios/ProductReview/ProductReview, //ios/ATCService/ATCService)" --output=graph | dot -Tsvg > ~/Desktop/test-allpaths.svg]()
Last is we can query which modules, depend on Shop
module
bazelisk query "rdeps(//ios/Tokopedia, //ios/Shop/Shop)" --output=graph | dot -Tsvg > ~/Desktop/test-allpaths.svg