I have a "file.py" and "other_file.py" that are both somehow a part of bazel run my:target
. Is there a way to tell in the dependency tree would target of "file.py" depend on target of "other_file.py", or vise-versa, or would they both have a common ancestor.
You can use bazel query
for this: https://bazel.build/query/guide
E.g. for:
py_binary(
name = "main",
srcs = ["main.py"],
deps = ["file", "other_file"],
)
py_library(
name = "file",
srcs = ["file.py"],
deps = [":other_file"],
)
py_library(
name = "other_file",
srcs = ["other_file.py"],
)
bazel query --notool_deps --noimplicit_deps "deps(main)" --output graph | dot -Tpng > /tmp/graph.png
produces
To do the reverse:
bazel query --notool_deps --noimplicit_deps "rdeps(//..., other_file.py)" --output graph | dot -Tpng > /tmp/rdeps_graph.png