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: cmd/go: add way to force ignoring vendor directory #39247

Closed
DavidGamba opened this issue May 25, 2020 · 5 comments
Closed

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

DavidGamba opened this issue May 25, 2020 · 5 comments

Comments

@DavidGamba
Copy link

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
@seankhliao
Copy link
Member

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

@DavidGamba
Copy link
Author

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 (old) Jun 10, 2020
@rsc
Copy link
Contributor

rsc commented Jul 14, 2021

This seems similar to #37724. Like in that issue, the simplest answer is probably to put your Go code in a subdirectory of the repo, adjacent to vendor/ instead of as a parent of it.

@rsc rsc changed the title proposal: Update go.mod to indicate mod=mod and ignore vendor dir proposal: cmd/go: add way to force ignoring vendor directory Jul 14, 2021
@DavidGamba
Copy link
Author

@rsc Thanks for taking the time to respond, I appreciate having a clear path forward vs not knowing if this is a workflow that is planned for in the future.

As you commented in the liked issue:

There are already two ways to do this: a dummy go.mod or putting
your assets and Go code in sibling subdirectories of the repo root.
Both of those are feasible today, in contrast to adding an ignore directive.

In the case of the vendor dir, the dummy go.mod doesn't work but putting the go.mod in a sibling dir will certainly work.
Adding GOFLAGS="-mod=mod" also works.

I'll close this issue since this one is not reason alone to add ignore directives to the go.mod file.

@rsc rsc moved this from Incoming to Declined in Proposals (old) Aug 18, 2021
@rsc
Copy link
Contributor

rsc commented Aug 18, 2021

This proposal has been declined as retracted.
— rsc for the proposal review group

@rsc rsc moved this from Declined to Active in Proposals (old) Aug 18, 2021
@rsc rsc moved this from Active to Declined in Proposals (old) Aug 25, 2021
@golang golang locked and limited conversation to collaborators Aug 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

4 participants