bazelbuild / bazelbuild/bazel

bzlmod doesn't exclude bazel-* from ellipsis by default in submodules

Open
#24,190 0 comments 0 reactions 0 assignees View on GitHub
area-Bzlmod help wanted P2 team-ExternalDeps type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

If you run bazel build ... in a root module it will by default exclude the standard symlink dirs that get created by bazel (bazel-bin, bazel-out, etc.). If you cd into a submodule and do this it will create the symlink dirs and will work fine there, but if you go back to the root module and try to build everything in a submodule (bazel build @submodule//...) it will likely fail because it will go into the bazel-out dirs that were created by running directly in the submodule and find many broken build files. Errors like
```
Unable to find package for @@[unknown repo]
```
Adding these bazel- dirs into .bazelignore in the submodule will cause it to behave as it does when bazel is called from under the directory of the submodule.

### Which category does this issue belong to?

_No response_

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

Clone rules_python repo locally and cd into the directory in examples/bzlmod. Run this, should succeed
```
examples/bzlmod$ bazel build @our_other_module//...
```
cd into other_module and open the MODULE.bazel and uncomment the local_path_override. Build the other module from this dir
```
examples/bzlmod/other_module$ bazel build ...
```
cd back to the bzlmod dir and build @our_other_module//... again now, should error
```
examples/bzlmod$ bazel build @our_other_module//...
ERROR: infinite symlink expansion detected
[start of symlink chain]
.../execroot/_main/external/rules_python~
.../external/rules_python~
examples/bzlmod/other_module/bazel-other_module/external/rules_python~
[end of symlink chain]
ERROR: Infinite symlink expansion, for bazel-other_module/external/rules_python~, skipping: Infinite symlink expansion
WARNING: Target pattern parsing failed.
ERROR: Skipping '@our_other_module//...': error loading package under directory '': error loading package '@@other_module~//bazel-other_module/external/rules_python~~pip~other_module_pip/absl_py': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@other_module~]//lib:selects.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@other_module~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@other_module~'.
ERROR: error loading package under directory '': error loading package '@@other_module~//bazel-other_module/external/rules_python~~pip~other_module_pip/absl_py': Unable to find package for @@[unknown repo 'bazel_skylib' requested from @@other_module~]//lib:selects.bzl: The repository '@@[unknown repo 'bazel_skylib' requested from @@other_module~]' could not be resolved: No repository visible as '@bazel_skylib' from repository '@@other_module~'.
INFO: Elapsed time: 0.095s
INFO: 0 processes.

```
you can create a .bazelignore in the submodule with the following and the error will go away
```
bazel-bin
bazel-other_module
bazel-out
bazel-testlogs
```

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

Ubuntu 24.04

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

release 7.3.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 HEAD` ?

_No response_

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

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

_No response_

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

_No response_

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from examples/bzlmod by building @our_other_module//..., then build ... inside other_module after uncommenting the local_path_override in MODULE.bazel. Compare the submodule's .bazelignore behavior and the generated bazel-bin, bazel-other_module, bazel-out, and bazel-testlogs paths. Done means the root-module build excludes these directories and succeeds without symlink expansion or unknown-repository errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.