bazelbuild / bazelbuild/bazel

local_repository's "bazel-<subrepo>" symlink causes @subrepo//... to fail

Open
#4,284 8 comments 0 reactions 0 assignees View on GitHub
not stale 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 problem / feature request / question:

Suppose I have a top-level workspace named `toprepo`, and it pulls in a `local_repository` named `subrepo`.

If the `subrepo` directory contains Bazel's convenience symlinks (bazel-out, bazel-bin, etc.), then most of them don't cause any problems; but the `bazel-subrepo` one does cause a problem.

If you are in `toprepo`, then the expression `@subrepo//...` will navigate into the `bazel-subrepo` symlink, looking for `BUILD` files, and it will get confused.

### If possible, provide a minimal example to reproduce the problem:

In `~/toprepo`, put these files:

`WORKSPACE`:

```python
workspace(name = "toprepo")

local_repository(
name = "subrepo",
path = "../subrepo")
```

`BUILD`: empty file

In `~/subrepo`, put these files:

`WORKSPACE`:

```python
workspace(name = "subrepo")
```

`BUILD`:

```python
sh_test(
name = "subtest",
srcs = ["foo.sh"]
)
```

`foo.sh`:

```bash
#!/usr/bin/env bash
echo hi from foo.sh
```

Then: starting in `toprepo`: `bazel test @subrepo//...`

Result: It works (runs one test).

Now go into `subrepo` and do `bazel test //...`

Result: It works (runs the same test), but also, the convenience symlinks have now been created: bazel-subrepo, bazel-bin, etc.

Now go back to `toprepo` and run tests again: `bazel test @subrepo//...`

Result: Error messages:

```
ERROR: error loading package '@subrepo//bazel-subrepo/external/bazel_tools/src/main/protobuf': Extension file not found. Unable to load package for '@subrepo//tools/build_rules:utilities.bzl': BUILD file not found on package path
ERROR: error loading package '@subrepo//bazel-subrepo/external/bazel_tools/src/main/protobuf': Extension file not found. Unable to load package for '@subrepo//tools/build_rules:utilities.bzl': BUILD file not found on package path
INFO: Elapsed time: 0.116s
FAILED: Build did NOT complete successfully (12 packages loaded)
currently loading: @subrepo//bazel-subrepo/external/bazel_tools/src/main/protobuf ... (4 packages)
ERROR: Couldn't start the build. Unable to run tests
```

It seems that subrepo's `bazel-subrepo` symlink is the only one that is causing a problem. If you delete that one symlink, but leave all the others, the problem goes away.

### Environment info
* Operating System: macOS 10.12.6 (Sierra)
* Bazel version (output of `bazel info release`): 0.8.1

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue using the WORKSPACE and BUILD files in the described toprepo/subrepo setup. Run `bazel test @subrepo//...` before and after running `bazel test //...` in subrepo, then inspect how the generated `bazel-subrepo` convenience symlink affects package traversal. Done means the external-repository test succeeds even when that symlink exists.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.