Bazel only downloads external dependencies that are needed for building your target? That's not exactly true.
Problem
Bazel fetches unneeded dependencies due to load statements.
Reproduce
Considering the following example:
Repo A is your main repo, which depends on some library in repo B. Repo B depends on a test rule in repo C for testing the its library.
In A/BUILD:
cc_binary(
name = "bin",
srcs = ["main.cc"],
deps = ["@B//:lib"]
)
In B/BUILD:
load("@C-dev//:def.bzl", "my_cc_test")
cc_library(
name = "lib",
srcs = ["lib.cc"],
)
my_cc_test(
name = "lib_test",
srcs = ["lib_test.cc"],
deps = [
":lib",
"@C-dev//:test",
],
)
Although C is only a dev dependency of B, in order to build //:bin A has to declare C as a dependency in WORKSPACE and Bazel will fetch C at build time.
The root cause is load("@C-dev//:def.bzl", "my_cc_test") being in the same package as @B//:lib, in the loading phase, Bazel has to fetch C to correctly parse the BUILD file.
A full repo case is here: https://github.com/meteorcloudy/my_tests/tree/master/dev_deps_test
Bazel only downloads external dependencies that are needed for building your target? That's not exactly true.
Problem
Bazel fetches unneeded dependencies due to load statements.
Reproduce
Considering the following example:
Repo A is your main repo, which depends on some library in repo B. Repo B depends on a test rule in repo C for testing the its library.
In A/BUILD:
In B/BUILD:
Although C is only a dev dependency of B, in order to build
//:binA has to declare C as a dependency in WORKSPACE and Bazel will fetch C at build time.The root cause is
load("@C-dev//:def.bzl", "my_cc_test")being in the same package as@B//:lib, in the loading phase, Bazel has to fetch C to correctly parse the BUILD file.A full repo case is here: https://github.com/meteorcloudy/my_tests/tree/master/dev_deps_test