`glob` is unable to exclude recursive symlinks from evaluation
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 75
Description
### Description of the problem / feature request:
`glob` throws an evaluation error when it detects an infinite recursion in a
directory traversal. However, it detects this recursion even if the specific
subpath leading to that recursion is excluded via the `exclude=[]` argument.
This means that recursive symlinks cannot be ignored in glob expressions,
even if they occur in subtrees that bazel does not need to be evaluating.
It may also suggest that unnecessary directory tree evaluation is being
performed when using glob expressions.
Consider the following structure:
```
.
├── BUILD.bazel
├── foo
│ ├── bar -> ../
│ └── payload.txt
└── WORKSPACE
```
The following glob expression will fail to evaluate, even though several wildcards
are provided to `exclude=[]` indicating that the `foo/bar` symlink doesn't need to be followed.
```
filegroup(
name = "broken",
srcs = glob(
include = ["**"],
exclude = [
"foo/bar",
"foo/bar*",
"foo/bar/**",
],
),
)
```
```
$ bazel build //:broken
INFO: Invocation ID: a302280d-4f28-4bcc-be3c-9cfe92159c6f
ERROR: infinite symlink expansion detected
[start of symlink chain]
/home/user/bazel-issue-13950
/home/user/bazel-issue-13950/foo/bar
[end of symlink chain]
ERROR: Skipping '//:broken': no such package '': Symlink issue while evaluating globs: Infinite symlink expansion: /home/user/bazel-issue-13950/foo/bar- > /home/user/bazel-issue-13950
WARNING: Target pattern parsing failed.
ERROR: no such package '': Symlink issue while evaluating globs: Infinite symlink expansion: /home/user/bazel-issue-13950/foo/bar- > /home/user/bazel-issue-13950
INFO: Elapsed time: 0.328s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
```
### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
I have created a minimal example here:
https://github.com/psigen/bazel-issue-13950
### What operating system are you running Bazel on?
Ubuntu 20.04
### What's the output of `bazel info release`?
```
$ bazel info release
INFO: Invocation ID: e8c5b931-7292-4f74-a908-d496639b920d
release 4.2.1
```
### Have you found anything relevant by searching the web?
I have not found references to this specific issue
- bugs around being unable to exclude subdirectories
- documentation indicating that this behavior is expected
Contributor guide
Assessment
This issue has not been assessed yet.