vscode-bazel icon indicating copy to clipboard operation
vscode-bazel copied to clipboard

Bazel queries fail after first bazel build

Open warriorstar-orion opened this issue 3 years ago • 5 comments

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

  1. Clone repro repo. Do not run any bazel commands yet!
  2. code .
  3. ⌘P BUILD ↵
  4. ⌘⇧P Bazel: Build Target ↵ At this point, the target //:main should now be in the command palette dropdown list. Press .
  5. The bazel Terminal should be selected, with a successful bazel build displayed.
  6. 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"
  ]
}

warriorstar-orion avatar Nov 18 '20 04:11 warriorstar-orion

Same scenario, same error here.

kylecordes avatar Nov 18 '20 21:11 kylecordes

I am seeing a similar issue

jinfwhuang avatar Dec 11 '20 17:12 jinfwhuang

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.

lorenz avatar Feb 12 '21 14:02 lorenz

@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.

siedentop avatar Aug 01 '21 17:08 siedentop

@coeuvre Could you have a look at this one, when you have time? 😊

philwo avatar Aug 10 '21 09:08 philwo

See also #216 & #261.

vorburger avatar Feb 17 '23 23:02 vorburger

Duplicate of #216

cameron-martin avatar Jan 23 '24 11:01 cameron-martin