bazelbuild / bazelbuild/bazel

`glob` does not see sources in a `.bazelignore` directory

Open
#12,034 10 comments 1 reaction 0 assignees View on GitHub
P2 team-OSS type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

When using [`glob`](https://docs.bazel.build/versions/master/be/functions.html#glob) on a directory that is specified in [`.bazelignore`](https://docs.bazel.build/versions/master/guide.html#bazelignore), I would expect `glob` to still give me a list of all sources in this directory.

### Feature requests: what underlying problem are you trying to solve with this feature?

My expectations of `.bazelignore` is that Bazel will ignore the directories specified as potential packages such that `BUILD`/`BUILD.bazel` files can live in them and Bazel will ignore them.

#### Example
I've created an example of this: [repro.zip](https://github.com/bazelbuild/bazel/files/5157964/repro.zip)
```
├── BUILD.bazel
├── WORKSPACE.bazel
├── failures
│ └── BUILD.bazel
└── lib
├── BUILD.bazel
├── WORKSPACE.bazel
├── bar
├── baz
└── foo

2 directories, 8 files
```

##### Current State
With the following `.bazelignore` file, I'm able to build my target `:parent` but am not seeing the results I'd expect
```
failures
lib
```

Below is the an example of the unexpected results
```command
bazel run :parent
```
```output
[]
```

`:parent` is a [`genrule`]() target with the following implementation
```python
my_glob = glob(["lib/**/*"])

genrule(
name = "parent",
outs = ["parent.sh"],
cmd = """\
cat > "$@" << EOF
#!/bin/bash
echo "{}"
EOF
""".format(my_glob),
executable = True,
)
```

##### Expected Behavior
With both `.bazelignore` and `BUILD.bazel` files in the ignored directory, I still expect to see the source files in said directory:
```command
bazel run :parent
```
```output
[lib/BUILD.bazel, lib/WORKSPACE.bazel, lib/bar, lib/baz, lib/foo]
```

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

Not sure if this is a bug or not but a repro has been given in the section above

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

MacOS/Linux

### What's the output of `bazel info release`?

```
release 3.4.1
```

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

NA

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

NA

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

#10428 seems relevant

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

NA

Contributor guide

Open the contributing guide

Research direction

Start by unpacking the attached repro.zip and running bazel run :parent with the shown .bazelignore, BUILD.bazel, WORKSPACE.bazel, and glob setup. Compare the empty output with the expected source list, then trace the glob and .bazelignore behavior until the ignored directory's sources are handled as described; the repro should produce the expected list when done.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.