bazel-contrib / bazel-contrib/rules_go

go_test: better diagnostic needed for test dependency cycle

Open
#2,808 11 comments 0 reactions 0 assignees View on GitHub
enhancement go
Dominant language
Go
Stars
1.5k
Forks
760
Avg merge
1d 11h
Merged PRs (30d)
12

Description

### What version of rules_go are you using?

0.24.9, but I've also checked 0.25.1 and determined that this doesn't fix the bug.

### What version of gazelle are you using?

`493b9adf67665beede36502c2094496af9f245a3`, but as above I've checked with 0.22.3 and that didn't fix it.

### What version of Bazel are you using?

`bazel 3.7.1-homebrew`

### Does this issue reproduce with the latest releases of all the above?

Yes for the first two, but I didn't check with the latest Bazel.

### What operating system and processor architecture are you using?

macOS 10.15.7, `x86_64`

### Any other potentially useful information about your toolchain?

Nothing to note.

### What did you do?

The error can be reproduced at the latest `master` of https://github.com/cockroachdb/cockroach (as of this writing, `39893f8b75243932263e55cfce9e056673be245a`) with `bazel test pkg/util/uuid:uuid_test`. (Sorry, I wasn't able to isolate a smaller repro yet. 😬) Running this command generates the error I've pasted below, namely, the `pkg/testutils/skip` package isn't being linked with the test sources.

I've verified that the `importpath`s and dependencies all seem correct. Nonetheless, running with `--sandbox_debug --verbose_failures` demonstrates that the `skip` package isn't even being passed to the compiler:

```
(cd /private/var/tmp/_bazel_ricky/be70b24e7357091e16c49d70921b7985/sandbox/darwin-sandbox/10379/execroot/cockroach && \
exec env - \
APPLE_SDK_PLATFORM=MacOSX \
APPLE_SDK_VERSION_OVERRIDE=11.1 \
CGO_ENABLED=1 \
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
GOARCH=amd64 \
GOOS=darwin \
GOPATH='' \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=external/local_config_cc:/bin:/usr/bin \
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
TMPDIR=/var/folders/tk/7wfswg457lqbj05wtbm4ldpm0000gp/T/ \
XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
/usr/bin/sandbox-exec -f /private/var/tmp/_bazel_ricky/be70b24e7357091e16c49d70921b7985/sandbox/darwin-sandbox/10379/sandbox.sb /var/tmp/_bazel_ricky/install/87029e13053f87e11688f60f380161fb/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src pkg/util/uuid/codec.go -src pkg/util/uuid/generator.go -src pkg/util/uuid/sql.go -src pkg/util/uuid/uuid.go -src pkg/util/uuid/uuid_wrapper.go -src pkg/util/uuid/benchmark_fast_test.go -src pkg/util/uuid/codec_test.go -src pkg/util/uuid/generator_test.go -src pkg/util/uuid/sql_test.go -src pkg/util/uuid/uuid_test.go -arc 'github.com/cockroachdb/cockroach/pkg/util/timeutil=github.com/cockroachdb/cockroach/pkg/util/timeutil=bazel-out/darwin-fastbuild/bin/pkg/util/timeutil/timeutil.x' -arc 'github.com/cockroachdb/errors=github.com/cockroachdb/errors=bazel-out/darwin-fastbuild/bin/external/com_github_cockroachdb_errors/errors.x' -arc 'github.com/cockroachdb/cockroach/pkg/util/syncutil=github.com/cockroachdb/cockroach/pkg/util/syncutil=bazel-out/darwin-fastbuild/bin/pkg/util/syncutil/syncutil.x' -arc 'github.com/cockroachdb/cockroach/pkg/util/uint128=github.com/cockroachdb/cockroach/pkg/util/uint128=bazel-out/darwin-fastbuild/bin/pkg/util/uint128/uint128.x' -importpath github.com/cockroachdb/cockroach/pkg/util/uuid -p github.com/cockroachdb/cockroach/pkg/util/uuid -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/darwin-fastbuild/bin/pkg/util/uuid/uuid_test.internal.recompileinternal.a -x bazel-out/darwin-fastbuild/bin/pkg/util/uuid/uuid_test.internal.recompileinternal.x -testfilter exclude -gcflags '' -asmflags '') sandbox-exec failed: error executing command
(cd /private/var/tmp/_bazel_ricky/be70b24e7357091e16c49d70921b7985/sandbox/darwin-sandbox/10379/execroot/cockroach && \
exec env - \
APPLE_SDK_PLATFORM=MacOSX \
APPLE_SDK_VERSION_OVERRIDE=11.1 \
CGO_ENABLED=1 \
DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer \
GOARCH=amd64 \
GOOS=darwin \
GOPATH='' \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=external/local_config_cc:/bin:/usr/bin \
SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk \
TMPDIR=/var/folders/tk/7wfswg457lqbj05wtbm4ldpm0000gp/T/ \
XCODE_VERSION_OVERRIDE=12.4.0.12D4e \
/usr/bin/sandbox-exec -f /private/var/tmp/_bazel_ricky/be70b24e7357091e16c49d70921b7985/sandbox/darwin-sandbox/10379/sandbox.sb /var/tmp/_bazel_ricky/install/87029e13053f87e11688f60f380161fb/process-wrapper '--timeout=0' '--kill_delay=15' bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src pkg/util/uuid/codec.go -src pkg/util/uuid/generator.go -src pkg/util/uuid/sql.go -src pkg/util/uuid/uuid.go -src pkg/util/uuid/uuid_wrapper.go -src pkg/util/uuid/benchmark_fast_test.go -src pkg/util/uuid/codec_test.go -src pkg/util/uuid/generator_test.go -src pkg/util/uuid/sql_test.go -src pkg/util/uuid/uuid_test.go -arc 'github.com/cockroachdb/cockroach/pkg/util/timeutil=github.com/cockroachdb/cockroach/pkg/util/timeutil=bazel-out/darwin-fastbuild/bin/pkg/util/timeutil/timeutil.x' -arc 'github.com/cockroachdb/errors=github.com/cockroachdb/errors=bazel-out/darwin-fastbuild/bin/external/com_github_cockroachdb_errors/errors.x' -arc 'github.com/cockroachdb/cockroach/pkg/util/syncutil=github.com/cockroachdb/cockroach/pkg/util/syncutil=bazel-out/darwin-fastbuild/bin/pkg/util/syncutil/syncutil.x' -arc 'github.com/cockroachdb/cockroach/pkg/util/uint128=github.com/cockroachdb/cockroach/pkg/util/uint128=bazel-out/darwin-fastbuild/bin/pkg/util/uint128/uint128.x' -importpath github.com/cockroachdb/cockroach/pkg/util/uuid -p github.com/cockroachdb/cockroach/pkg/util/uuid -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/darwin-fastbuild/bin/pkg/util/uuid/uuid_test.internal.recompileinternal.a -x bazel-out/darwin-fastbuild/bin/pkg/util/uuid/uuid_test.internal.recompileinternal.x -testfilter exclude -gcflags '' -asmflags '')
```

I haven't identified the exact source of the failure yet, but this does seem to be related in some way to the indirect dependency that the test has on `pkg/util:util_go_proto`. To demonstrate this, you can see [this commit](https://github.com/rickystewart/cockroach/commit/d776c02ffbff59f79e735e98a4cc7de8a5a3ab8d), which strips out a bunch of unnecessary stuff, and still reproduces the failure. *However*, commenting out the `embed = [":util_go_proto"],` line in `pkg/util/BUILD.bazel` suddenly causes the test to pass.

### What did you expect to see?

No build failure.

### What did you see instead?

The error looks like this:

```
cockroach$ bazel test pkg/util/uuid:all
INFO: Analyzed 2 targets (1 packages loaded, 58 targets configured).
INFO: Found 1 target and 1 test target...
ERROR: /Users/ricky/go/src/github.com/cockroachdb/cockroach/pkg/util/uuid/BUILD.bazel:22:8: GoCompilePkg pkg/util/uuid/uuid_test.internal.recompileinternal.a failed (Exit 1): builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src pkg/util/uuid/codec.go -src pkg/util/uuid/generator.go -src pkg/util/uuid/sql.go -src ... (remaining 37 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox builder failed: error executing command bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix darwin_amd64 -src pkg/util/uuid/codec.go -src pkg/util/uuid/generator.go -src pkg/util/uuid/sql.go -src ... (remaining 37 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
compilepkg: missing strict dependencies:
/private/var/tmp/_bazel_ricky/be70b24e7357091e16c49d70921b7985/sandbox/darwin-sandbox/10223/execroot/cockroach/pkg/util/uuid/codec_test.go: import of "github.com/cockroachdb/cockroach/pkg/testutils/skip"
No dependencies were provided.
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure with `bazel test pkg/util/uuid:uuid_test` from the reported CockroachDB setup, then compare it with the `embed = [":util_go_proto"]` line in `pkg/util/BUILD.bazel`. Inspect the `go_test` dependency analysis and the reported `compilepkg: missing strict dependencies` output. Done means a test dependency cycle produces a clearer diagnostic instead of the misleading missing-dependency error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
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.