bazelbuild / bazelbuild/bazel

Bazel query over packages doesn't work for the second run

Open
#17,922 1 comment 1 reaction 0 assignees View on GitHub
team-Core type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

Bazel command `/usr/bin/bazel --output_base=/tmp/8b13635fb2af02d5f5b0554bd1e20b22 query ...:* --output=package` (it's a run from the vscode-bazel extension) fails if the directory contains bazel-* folders.
Error:
```
Command failed: /usr/bin/bazel --output_base=/tmp/8b13635fb2af02d5f5b0554bd1e20b22 query ...:* --output=package
Loading: 0 packages loaded
ERROR: error loading package under directory '': error loading package 'bazel-bazel-dir/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: 3 packages loaded
currently loading: bazel-bazel-dir/external/bazel_tools/src/conditions ... (2 packages)
```

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

1. Create a workspace file:
```
workspace(name = "build_bazel_vscode_bazel")
```
2. Create several packages in the workspace
3. Run the command: `bazel query ...:* --output=package`. You will see created packages.
4. Run `ls | grep bazel-`. You will see output like:
```
bazel-bazel-dir
bazel-bin
bazel-out
bazel-testlogs
```
5. Run the command: `bazel query ...:* --output=package` again to see the error above.

### Which operating system are you running Bazel on?

osx

### What is the output of `bazel info release`?

release 6.1.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Have you found anything relevant by searching the web?

no

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the report with a workspace file and several packages: run `bazel query ...:* --output=package`, create or observe the `bazel-*` directories, then run the same query again. Start at the Bazel query entry point and compare both runs; done means the second query completes and lists the packages without the reported loading error.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.