Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go list in 1.21 gives an error import _ is a program, not an importable package #62228

Closed
alexbozhenko opened this issue Aug 23, 2023 · 1 comment

Comments

@alexbozhenko
Copy link
Contributor

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.

@seankhliao
Copy link
Member

Duplicate of #61857

@seankhliao seankhliao marked this as a duplicate of #61857 Aug 23, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants