Skip to content

proposal: cmd/go: add way to force ignoring vendor directory #39247

Closed
@DavidGamba

Description

@DavidGamba

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions