运行 不下载外部依赖的bazel查询

Running bazel query without downloading external dependencies

鉴于使用 bazel 构建的相当大的存储库和大量多种语言的第三方依赖项(包括大量 docker 容器),我遇到以下问题:

运行ning Bazel 查询会触发下载 许多 这些依赖项,从而导致查询性能降低。因此,问题:

有没有办法 运行 bazel query 而无需下载依赖项?

典型查询:bazel query 'kind("source file", deps(//...) except deps(//3rdparty/...))

我知道我主要使用的缓存选项,但根据语言的不同,速度可能仍然很慢。

在 Bazel 的 Slack 频道上询问后,(来自 Sahin Yort)的回应并不令人鼓舞:

I don’t believe that’s possible due to nature of workspace files. loads from a workspace leads to fetch of the given workspace because has to expand the workspaces in order to know their targets. at that point, it is up to the repository rule to fetch whatever it needs to fetch eagerly or lazily. workspace rules usually expand BUILD files using various patterns. eg running a executable or using expand_template. i have little faith in that it is possible to get what you want.

我将研究其他方法来加快速度:速度缓慢的罪魁祸首可能是 action/analysis 缓存因某些标志更改而失效。

如果只需要解析AST而不解析依赖,可以使用buildozer代替:

buildozer "print srcs" "//some:target"

它还支持 -output_json 机器可读输出