Closed as not planned
Closed as not planned
Description
Per conversation here:
#25922 (comment)
it seems like managing tools dependencies with tools.go
is still a best practice
The behavior of go list changed in 1.21, seems like in this commit by @matloob:
a5c7928
and it is now failing with "is a program, not an importable package", error. See below:
What version of Go are you using (go version
)?
$ go version go version devel go1.21-a5c79283f7 Mon Apr 10 20:27:52 2023 +0000 linux/amd64
Does this issue reproduce with the latest release?
Yes, reproducible on 1.21
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE='' GOARCH='amd64' GOBIN='' GOCACHE='/home/abozhenko/.cache/go-build' GOENV='/home/abozhenko/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/abozhenko/go/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/home/abozhenko/go' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/usr/local/go' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.21.0' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/home/abozhenko/code/tower/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2829969153=/tmp/go-build -gno-record-gcc-switches'
What did you do?
cat << EOF > tools.go
//go:build tools
package tools
// Manage tool dependencies via go.mod.
//
// https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module
// https://github.com/golang/go/issues/25922
import (
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway"
_ "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2"
_ "google.golang.org/grpc/cmd/protoc-gen-go-grpc"
_ "google.golang.org/protobuf/cmd/protoc-gen-go"
_ "github.com/envoyproxy/protoc-gen-validate"
_ "github.com/vektra/mockery/v2"
)
EOF
# Note that this step is needed to reproduce the bug. If go.mod/go.sum are absent, go list will not give a error.
go mod init test
go mod tidy
What did you expect to see?
Previous versions produced a list, that can be used by go install
:
$/usr/local/go1.20.7/bin/go list -f '{{join .Imports " "}}' tools.go
github.com/envoyproxy/protoc-gen-validate github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2 github.com/vektra/mockery/v2 google.golang.org/grpc/cmd/protoc-gen-go-grpc google.golang.org/protobuf/cmd/protoc-gen-go
What did you see instead?
Now it gives an error:
$ go list -f '{{join .Imports " "}}' tools.go
tools.go:17:2: import "github.com/envoyproxy/protoc-gen-validate" is a program, not an importable package
Running with -e
flag
go list -e -f '{{join .Imports " "}}' tools.go
Does produce expected list of packages, but I am not sure if this is a right thing to do here.