golang/go

No go files in package: when running go run with vendor folder

coderste opened this issue · 3 comments

What version of Go are you using (go version)?

$ go version
go version go1.12.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/shi03/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/shi03/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.6/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/shi03/code/projects/gs/common-api/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/dc/pxx2c5t503jdfy7c29qrlmp9nkvqm9/T/go-build575521762=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a file with

//go:generate go run github.com/99designs/gqlgen

At the top which will run a package to generate some files for me. I'm running all this within a docker container using Go Mods but it's in vendor mode.

Inside the docker container I have GOFLAGS=-mod=vendor to run all commands by using the vendor folder

The issues here lies with when I try to run go generate ./... inside the docker container. It returns the error:

package github.com/99designs/gqlgen: no Go files in /code/project/vendor/github.com/99designs/gqlgen

I'm assuming when the go generate -mod=vendor ./... command tries to run go run -mod=vendor github.com/99designs/gqlgen it can't find no Go files within the package.

What did you expect to see?

I expected for the go run command to work when vendoring packages.

What did you see instead?

The command didn't work it just returned:

package github.com/99designs/gqlgen: no Go files in /code/project/vendor/github.com/99designs/gqlgen

I believe this relates to #27227

Per https://blog.golang.org/generate:

if the containing package is intended for import by go get, once the file is generated (and tested!) it must be checked into the source code repository to be available to clients.

go mod vendor vendors in only those packages that are needed to build (using go build) and test (using go test) the packages in the main module. So it is expected that go generate does not work in general with -mod=vendor.

Duplicate of #29516