'Running bazel query without downloading external dependencies

Given a rather big repository built with bazel and tons of third party dependencies in multiple languages (including heavy docker containers), I have the following problem:

running Bazel queries triggers the downloading of many of these dependencies, resulting in slow query performance. Hence, the question:

Is there a way to run bazel query without having to download the dependencies?

Typical query: bazel query 'kind("source file", deps(//...) except deps(//3rdparty/...))

I'm aware of the caching options, which I mostly use, but depending on the languages, things can still be slow.



Solution 1:[1]

After asking on Bazel's Slack channel, the response (from Sahin Yort) is not encouraging:

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.

I'll be looking into other ways to speed things up: a likely culprit for the slowness is probably the action/analysis cache being invalidated due to some flags changing.

Solution 2:[2]

If you only need to parse the AST without resolving dependencies, you can use buildozer instead:

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

It also supports -output_json for machine readable output

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Vladislav Ivanov