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

proposal: Update go.mod to indicate mod=mod and ignore vendor dir #39247

Open
DavidGamba opened this issue May 25, 2020 · 2 comments
Open

proposal: Update go.mod to indicate mod=mod and ignore vendor dir #39247

DavidGamba opened this issue May 25, 2020 · 2 comments
Labels
Projects
Milestone

Comments

@DavidGamba
Copy link

@DavidGamba DavidGamba commented May 25, 2020

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

$ go version
go version go1.14.3 linux/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
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/david/.cache/go-build"
GOENV="/home/david/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY="github.com/DavidGamba"
GONOSUMDB="github.com/DavidGamba"
GOOS="linux"
GOPATH="/home/david/go"
GOPRIVATE="github.com/DavidGamba"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/david/opt/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/david/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/david/my-repo/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build183891728=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Create a new monorepo dir:

mkdir mod-mod && cd mod-mod
go mod init github.com/DavidGamba/mod-mod

  1. Create a vendor directory that is a third party vendor dir, not Go code vendor.

mkdir vendor && touch vendor/hello

  1. Create a main.go file with an external import, and try build it:
$ go build
main.go:9:2: cannot find package "." in:
        /home/david/test/mod-mod/vendor/github.com/DavidGamba/go-getoptions
$ go build -mod=mod
go: finding module for package github.com/DavidGamba/go-getoptions
go: found github.com/DavidGamba/go-getoptions in github.com/DavidGamba/go-getoptions v0.19.0

Common workarounds don't work.

$ cd vendor
$ go mod init github.com/DavidGamba/mod-mod/vendor
go: creating new go.mod: module github.com/DavidGamba/mod-mod/vendor
$ cd ..
$ go build
go: inconsistent vendoring in /home/david/test/mod-mod:
        github.com/DavidGamba/go-getoptions@v0.19.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt

run 'go mod vendor' to sync, or use -mod=mod or -mod=readonly to ignore the vendor directory

What did you expect to see?

An option to tell go to always run in mod mode so it ignores the vendor directory used by other code in the monorepo. The option should be persisted in the go.mod file so there is no need to pass it to the command line every time and so other tools like gopls know about it.

What did you see instead?

vendor mode is assumed wrongly due to the presence of a vendor/ directory.

@gopherbot gopherbot added this to the Proposal milestone May 25, 2020
@gopherbot gopherbot added the Proposal label May 25, 2020
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented May 25, 2020

have you considered setting GOFLAGS="-mod=mod"?

@DavidGamba
Copy link
Author

@DavidGamba DavidGamba commented May 25, 2020

The problem with GOFLAGS is that only applies for my environment and each executable in our project can be built with plain go build unless we do a release build were we insert the metadata with -ldflags in our build system.

It is a workaround every developer will be forced to apply which I suppose it is OK but it would be better if the go.mod file had that information.

@rsc rsc added this to Incoming in Proposals Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Incoming
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.