`bazel build ...` failed when a sub folder contains another bazel project and has been built firstly
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the bug:
[Bazel document](https://bazel.build/concepts/build-ref#workspace) says that a bazel project in a sub folder will be ignored.
However, I found it's not always true.
I have a bazel project with a sub folder contains another bazel project. The build `bazel build ...` failed if the bazel project in the sub folder was built first.
> bazel build ...
ERROR: Skipping '...': error loading package under directory '': error loading package 'foo/bazel-foo/external/bazel_tools/src/main/protobuf': Label '//third_party/grpc/bazel:cc_grpc_library.bzl' is invalid because 'third_party/grpc/bazel' is not a package; perhaps you meant to put the colon here: '//:third_party/grpc/bazel/cc_grpc_library.bzl'?
WARNING: Target pattern parsing failed.
ERROR: error loading package under directory '': error loading package 'foo/bazel-foo/external/bazel_tools/src/main/protobuf': Label '//third_party/grpc/bazel:cc_grpc_library.bzl' is invalid because 'third_party/grpc/bazel' is not a package; perhaps you meant to put the colon here: '//:third_party/grpc/bazel/cc_grpc_library.bzl'?
INFO: Elapsed time: 0.485s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (5 packages loaded)
currently loading: foo/bazel-foo/external/bazel_tools/src/main/protobuf
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
1. issue `bazel build ...` in folder foo, should succeed
2. issue `bazel build ...` in root folder, should fail
```shell
tree .
.
├── BUILD
├── empty.cc
├── foo
│ ├── BUILD
│ ├── empty.cc
│ └── WORKSPACE
└── WORKSPACE
```
### Which operating system are you running Bazel on?
Ubuntu
### What is the output of `bazel info release`?
release 6.2.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_
### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.
_No response_
### Have you found anything relevant by searching the web?
Not found a similar issue on github issues.
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Reproduce the issue from the provided tree using the root and foo BUILD and WORKSPACE files: run `bazel build ...` in foo first, then from the root. Compare the package-loading behavior and the reported external bazel_tools path; done means the root build succeeds after the nested project has been built.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100