Bazel queries fail after first bazel build
Hello, thank you for all your hard work.
Pertinent info:
$ code --version
1.51.1
e5a624b788d92b8d34d1392e4c4d9789406efe8f
x64
$ code --list-extensions --show-versions
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
% uname -a
Darwin eikthyrnir.local 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64
% bazel --version
bazel 3.7.0-homebrew
I believe this is a minimum reproduction example: https://github.com/warriorstar-orion/bugs_vscode_bazelbuild_queryfailure
- Clone repro repo. Do not run any bazel commands yet!
-
code . -
⌘P BUILD ↵ -
⌘⇧P Bazel: Build Target ↵At this point, the target//:mainshould now be in the command palette dropdown list. Press↵. - The bazel Terminal should be selected, with a successful bazel build displayed.
- Repeat step 3. This time, instead of suggesting the target, an error occurs:
Command 'Bazel: Build Target' resulted in an error (Command failed: /usr/local/bin/bazel --output_base=/var/folders/mh/x76pfqyn4pl55v0yx9vl5bxw0000gn/T/765b26eaf589953e453ebb38850465f7 query kind('.* rule', ...) --output=proto Loading: 0 packages loaded ERROR: error loading package 'bazel-test_workspace/external/bazel_tools/third_party/def_parser': Label '//tools/python:private/defs.bzl' is invalid because 'tools/python' is not a package; perhaps you meant to put the colon here: '//:tools/python/private/defs.bzl'? Loading: 6 packages loaded currently loading: bazel-test_workspace/external/local_config_cc ... (4 packages) Loading: 6 packages loaded currently loading: bazel-test_workspace/external/local_config_cc ... (4 packages) )
Removing bazel-* from the workspace will cause the query to succeed. My first hunch was that VSCode was trying to build something in them unintentionally, but the following settings failed to help:
{
"bazel.pathsToIgnore": [
"bazel-bin",
"bazel-out",
"bazel-test_workspace",
"bazel-testlogs"
]
}
Same scenario, same error here.
I am seeing a similar issue
As a workaround you can set "bazel.queriesShareServer": true` in your settings.json. The issue stems from the extension setting a custom output_base which Bazel chokes on. Setting this option reuses the existing output_base which works fine.
@allevato or @philwo could you (or any other contributor) please take a look? (I pinged you because you have the most commits and the most recent commits, respectively.)
- This seems to affect a few folks: 6 likes on this topic + https://github.com/bazelbuild/vscode-bazel/issues/216 + https://github.com/bazelbuild/vscode-bazel/issues/219
- The solution/workaround by @lorenz does work.
- The Bazel extension is near useless with this issue present.
Many thanks for the extension and for hopefully taking a look.
@coeuvre Could you have a look at this one, when you have time? 😊
See also #216 & #261.
Duplicate of #216