What version of rules_go are you using?
v0.28.0
What version of gazelle are you using?
v0.23.0
What version of Bazel are you using?
4.2.1
Does this issue reproduce with the latest releases of all the above?
They are the latest releases
What operating system and processor architecture are you using?
linux/amd64
Any other potentially useful information about your toolchain?
What did you do?
When import github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto in tests, bazel will complain about package name mismatch:
external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_extractfields.pb.go:3:9: package mwitkow_testproto; expected testproto
external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_validator.pb.go:3:9: package mwitkow_testproto; expected testproto
This is a minimal reproducible example:
initial files:
go.mod:
module test
go 1.17
require github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
require (
github.com/golang/protobuf v1.4.3 // indirect
golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect
golang.org/x/text v0.3.3 // indirect
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
)
main.go:
package main
import (
"fmt"
)
func main() {
fmt.Println("vim-go")
}
main_test.go:
package main
import (
"testing"
pb "github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto"
)
func TestDummy(t *testing.T) {
var _ = pb.RegisterTestServiceServer
}
WORKSPACE:
workspace(name = "test")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
GO_VERSION = "1.17.1"
# For rules_go
RULES_GO_VERSION = "v0.28.0"
http_archive(
name = "io_bazel_rules_go",
sha256 = "8e968b5fcea1d2d64071872b12737bbb5514524ee5f0a4f54f5920266c261acb",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/%s/rules_go-%s.zip" % (RULES_GO_VERSION, RULES_GO_VERSION),
"https://github.com/bazelbuild/rules_go/releases/download/%s/rules_go-%s.zip" % (RULES_GO_VERSION, RULES_GO_VERSION),
],
)
# For gazelle
GAZELLE_VERSION = "v0.23.0"
http_archive(
name = "bazel_gazelle",
sha256 = "62ca106be173579c0a167deb23358fdfe71ffa1e4cfdddf5582af26520f1c66f",
urls = [
"https://storage.googleapis.com/bazel-mirror/github.com/bazelbuild/bazel-gazelle/releases/download/%s/bazel-gazelle-%s.tar.gz" % (GAZELLE_VERSION, GAZELLE_VERSION),
"https://github.com/bazelbuild/bazel-gazelle/releases/download/%s/bazel-gazelle-%s.tar.gz" % (GAZELLE_VERSION, GAZELLE_VERSION),
],
)
load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
go_rules_dependencies()
go_register_toolchains(version = GO_VERSION)
gazelle_dependencies()
load("//:external.bzl", "go_dependencies")
# gazelle:repository_macro external.bzl%go_dependencies
go_dependencies()
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
git_repository(
name = "com_google_protobuf",
# actual: tag = "v3.14.0",
commit = "2514f0bd7da7e2af1bed4c5d1b84f031c4d12c10",
remote = "https://github.com/protocolbuffers/protobuf",
shallow_since = "1605300819 -0800",
)
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
protobuf_deps()
BUILD.bazel:
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix test
gazelle(name = "gazelle")
external.bzl:
def go_dependencies(): pass
Then run the following commands to populate the files:
$ go mod tidy
$ bazel run //:gazelle -- update-repos -from_file=go.mod -prune -to_macro=external.bzl%go_dependencies
$ bazel run //:gazelle -- fix
go test works:
$ go test
PASS
ok test 0.003s
but bazel test //:test_test does not:
$ bazel test //:test_test --sandbox_debug
INFO: Analyzed target //:test_test (0 packages loaded, 0 targets configured).
INFO: Found 1 test target...
ERROR: /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/BUILD.bazel:19:11: GoCompilePkg external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/testproto.a failed: (Exit 1): linux-sandbox failed: error executing command
(cd /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test && \
exec env - \
CGO_ENABLED=1 \
GOARCH=amd64 \
GOOS=linux \
GOPATH='' \
GOROOT=external/go_sdk \
GOROOT_FINAL=GOROOT \
PATH=/usr/bin:/bin \
TMPDIR=/tmp \
/home/fishy/.cache/bazel/_bazel_fishy/install/ee8d7e4b6774884ed2cd0aece6fc9fda/linux-sandbox -t 15 -w /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test -w /tmp -w /dev/shm -D -- bazel-out/host/bin/external/go_sdk/builder compilepkg -sdk external/go_sdk -installsuffix linux_amd64 -src bazel-out/k8-fastbuild/bin/external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/mwitkow_testproto_go_proto_/github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto/test.pb.go -src external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_extractfields.pb.go -src external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_validator.pb.go -arc 'github.com/golang/protobuf/proto=github.com/golang/protobuf/proto=bazel-out/k8-fastbuild/bin/external/com_github_golang_protobuf/proto/proto.x' -arc 'google.golang.org/protobuf/proto=google.golang.org/protobuf/proto=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/proto/proto.x' -arc 'google.golang.org/protobuf/reflect/protoreflect=google.golang.org/protobuf/reflect/protoreflect=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/reflect/protoreflect/protoreflect.x' -arc 'google.golang.org/protobuf/runtime/protoiface=google.golang.org/protobuf/runtime/protoiface=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/runtime/protoiface/protoiface.x' -arc 'google.golang.org/protobuf/runtime/protoimpl=google.golang.org/protobuf/runtime/protoimpl=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/runtime/protoimpl/protoimpl.x' -arc 'google.golang.org/protobuf/types/descriptorpb=google.golang.org/protobuf/types/descriptorpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/descriptorpb/descriptorpb.x' -arc 'google.golang.org/protobuf/types/known/anypb=google.golang.org/protobuf/types/known/anypb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/anypb/anypb.x' -arc 'google.golang.org/protobuf/types/known/apipb=google.golang.org/protobuf/types/known/apipb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/apipb/apipb.x' -arc 'google.golang.org/protobuf/types/known/durationpb=google.golang.org/protobuf/types/known/durationpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/durationpb/durationpb.x' -arc 'google.golang.org/protobuf/types/known/emptypb=google.golang.org/protobuf/types/known/emptypb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/emptypb/emptypb.x' -arc 'google.golang.org/protobuf/types/known/fieldmaskpb=google.golang.org/protobuf/types/known/fieldmaskpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/fieldmaskpb/fieldmaskpb.x' -arc 'google.golang.org/protobuf/types/known/sourcecontextpb=google.golang.org/protobuf/types/known/sourcecontextpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/sourcecontextpb/sourcecontextpb.x' -arc 'google.golang.org/protobuf/types/known/structpb=google.golang.org/protobuf/types/known/structpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/structpb/structpb.x' -arc 'google.golang.org/protobuf/types/known/timestamppb=google.golang.org/protobuf/types/known/timestamppb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/timestamppb/timestamppb.x' -arc 'google.golang.org/protobuf/types/known/typepb=google.golang.org/protobuf/types/known/typepb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/typepb/typepb.x' -arc 'google.golang.org/protobuf/types/known/wrapperspb=google.golang.org/protobuf/types/known/wrapperspb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/known/wrapperspb/wrapperspb.x' -arc 'google.golang.org/protobuf/types/pluginpb=google.golang.org/protobuf/types/pluginpb=bazel-out/k8-fastbuild/bin/external/org_golang_google_protobuf/types/pluginpb/pluginpb.x' -arc 'google.golang.org/grpc=google.golang.org/grpc=bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/grpc.x' -arc 'google.golang.org/grpc/codes=google.golang.org/grpc/codes=bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/codes/codes.x' -arc 'google.golang.org/grpc/status=google.golang.org/grpc/status=bazel-out/k8-fastbuild/bin/external/org_golang_google_grpc/status/status.x' -arc 'golang.org/x/net/context=golang.org/x/net/context=bazel-out/k8-fastbuild/bin/external/org_golang_x_net/context/context.x' -importpath github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto -p github.com/grpc-ecosystem/go-grpc-middleware/testing/testproto -package_list bazel-out/host/bin/external/go_sdk/packages.txt -o bazel-out/k8-fastbuild/bin/external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/testproto.a -x bazel-out/k8-fastbuild/bin/external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/testproto.x -gcflags '' -asmflags '')
1632937200.103469910: src/main/tools/linux-sandbox.cc:152: calling pipe(2)...
1632937200.103489794: src/main/tools/linux-sandbox.cc:171: calling clone(2)...
1632937200.103624986: src/main/tools/linux-sandbox.cc:180: linux-sandbox-pid1 has PID 142268
1632937200.103670020: src/main/tools/linux-sandbox-pid1.cc:447: Pid1Main started
1632937200.103760408: src/main/tools/linux-sandbox.cc:197: done manipulating pipes
1632937200.103798470: src/main/tools/linux-sandbox-pid1.cc:189: working dir: /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test
1632937200.103808083: src/main/tools/linux-sandbox-pid1.cc:221: writable: /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test
1632937200.103812853: src/main/tools/linux-sandbox-pid1.cc:221: writable: /tmp
1632937200.103817025: src/main/tools/linux-sandbox-pid1.cc:221: writable: /dev/shm
1632937200.103852624: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /
1632937200.103857943: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /dev
1632937200.103861579: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /dev/pts
1632937200.103864975: src/main/tools/linux-sandbox-pid1.cc:292: remount rw: /dev/shm
1632937200.103868471: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /dev/mqueue
1632937200.103871514: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /dev/hugepages
1632937200.103875039: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /run
1632937200.103878408: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /run/lock
1632937200.103881968: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /run/user/1000
1632937200.103885657: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys
1632937200.103888768: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/kernel/security
1632937200.103894017: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/fs/cgroup
1632937200.103897968: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/fs/pstore
1632937200.103916805: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/firmware/efi/efivars
1632937200.103921807: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/fs/bpf
1632937200.103925266: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/kernel/debug
1632937200.103928767: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/kernel/tracing
1632937200.103932468: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/kernel/config
1632937200.103936045: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /sys/fs/fuse/connections
1632937200.103940417: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /proc
1632937200.103943816: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /proc/sys/fs/binfmt_misc
1632937200.103948705: src/main/tools/linux-sandbox-pid1.cc:313: remount(nullptr, /proc/sys/fs/binfmt_misc, nullptr, 2101281, nullptr) failure (Operation not permitted) ignored
1632937200.103954992: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /proc/sys/fs/binfmt_misc
1632937200.103958586: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /boot
1632937200.103962061: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /boot/efi
1632937200.103965452: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /home/fishy/.mnt/gdrive
1632937200.103973659: src/main/tools/linux-sandbox-pid1.cc:292: remount ro: /home/fishy/GoogleDrive/rclone
1632937200.103977799: src/main/tools/linux-sandbox-pid1.cc:292: remount rw: /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test
1632937200.103981364: src/main/tools/linux-sandbox-pid1.cc:292: remount rw: /home/fishy/.cache/bazel/_bazel_fishy/66988687ae8da86da8a81c193b210e82/sandbox/linux-sandbox/1826/execroot/test
1632937200.103984673: src/main/tools/linux-sandbox-pid1.cc:292: remount rw: /tmp
1632937200.103987843: src/main/tools/linux-sandbox-pid1.cc:292: remount rw: /dev/shm
1632937200.104011643: src/main/tools/linux-sandbox-pid1.cc:376: calling fork...
1632937200.104082268: src/main/tools/linux-sandbox-pid1.cc:406: child started with PID 2
external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_extractfields.pb.go:3:9: package mwitkow_testproto; expected testproto
external/com_github_grpc_ecosystem_go_grpc_middleware/testing/testproto/test.manual_validator.pb.go:3:9: package mwitkow_testproto; expected testproto
compilepkg: error running subcommand external/go_sdk/pkg/tool/linux_amd64/compile: exit status 2
1632937200.124095073: src/main/tools/linux-sandbox-pid1.cc:423: wait returned pid=2, status=0x100
1632937200.124105378: src/main/tools/linux-sandbox-pid1.cc:441: child exited normally with code 1
1632937200.124323157: src/main/tools/linux-sandbox.cc:233: child exited normally with code 1
Target //:test_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.160s, Critical Path: 0.03s
INFO: 2 processes: 2 internal.
FAILED: Build did NOT complete successfully
//:test_test FAILED TO BUILD
FAILED: Build did NOT complete successfully
This seems to only break in test files (I tried to remove main_test.go and import it in main.go instead and didn't trigger the problem)
What did you expect to see?
What did you see instead?
What version of rules_go are you using?
v0.28.0What version of gazelle are you using?
v0.23.0What version of Bazel are you using?
4.2.1Does this issue reproduce with the latest releases of all the above?
They are the latest releases
What operating system and processor architecture are you using?
linux/amd64
Any other potentially useful information about your toolchain?
What did you do?
When import
github.com/grpc-ecosystem/go-grpc-middleware/testing/testprotoin tests, bazel will complain about package name mismatch:This is a minimal reproducible example:
initial files:
go.mod:main.go:main_test.go:WORKSPACE:BUILD.bazel:external.bzl:Then run the following commands to populate the files:
go testworks:but
bazel test //:test_testdoes not:This seems to only break in test files (I tried to remove
main_test.goand import it inmain.goinstead and didn't trigger the problem)What did you expect to see?
What did you see instead?