bazelbuild / bazelbuild/bazel

C++ tests with runtime dependencies fail when added as external workspaces

Open
#11,139 4 comments 0 reactions 0 assignees View on GitHub
P2 team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the problem:

Bazel test runtime dependencies (`data`) in external workspaces don't have the correct working directory and therefore fail.

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

- Checkout https://github.com/TheButlah/reproduce-bug-test-runtime-cwd
- CD into `my_external`.
- Try doing `bazel test //:my_test --test_output=all`. Everything works (the data depenency is visible), although the CWD is very strange: `"/private/var/tmp/_bazel_ryan.butler/b8bd6028f9dacc41fb57dadfd4bf3745/sandbox/darwin-sandbox/31/execroot/my_external/bazel-out/darwin-fastbuild/bin/my_test.runfiles/my_external"`.
- CD back to the toplevel folder.
- Try running `bazel test @my_external//:my_test --test_output=all`. **The test fails, and the CWD has changed**: `"/private/var/tmp/_bazel_ryan.butler/e334708500f476733ae32f1e45380340/sandbox/darwin-sandbox/13/execroot/__main__/bazel-out/darwin-fastbuild/bin/external/my_external/my_test.runfiles/__main__"`

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

>MacOS 10.15

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

> release 3.0.0

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

> git@github.com:TheButlah/reproduce-bug-test-runtime-cwd.git
94c31717c3d1ca88320f4773152f3edc37629854
94c31717c3d1ca88320f4773152f3edc37629854

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

>No

### Any other information, logs, or outputs that you want to share?
Running flatbuffers tests also fails when added as an external repository, but that seems like a much more complicated example to reproduce.

Contributor guide

Open the contributing guide

Research direction

Start by checking out the linked reproduce-bug-test-runtime-cwd repository and run the two `bazel test` commands described for `//:my_test` and `@my_external//:my_test`. Compare the working directories and runtime data visibility in both cases, then use the external-workspace test path as the regression case. Done means the external invocation can access its runtime dependency with the expected working-directory behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
build-system, testing
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.