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

cmd/go: -mod flag doesn't work with module-mode go get #44760

Open
shmsr opened this issue Mar 3, 2021 · 5 comments
Open

cmd/go: -mod flag doesn't work with module-mode go get #44760

shmsr opened this issue Mar 3, 2021 · 5 comments

Comments

@shmsr
Copy link
Contributor

@shmsr shmsr commented Mar 3, 2021

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

$ go version

go version go1.16 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

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/subhamsarkar/Library/Caches/go-build"
GOENV="/Users/subhamsarkar/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/subhamsarkar/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/subhamsarkar/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/subhamsarkar/project/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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wz/k505z2bd7rnbbv_611swlj4h0000gp/T/go-build2354586914=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Inside a module, go get didn't accept the mod flag which is against what's mentioned in https://golang.org/ref/mod#build-commands

...
When run in module-aware mode, these commands use go.mod files to interpret import paths listed on the command line or written in Go source files. These commands accept the following flags, common to all module commands.
...

So, I was just playing with go commands based on what's written in the doc and I noticed that -mod works will all module commands except for go get.

$ go get -mod=mod ./...

What did you expect to see?

As per documentation, -mod must work with go get just like it works for go {build,fix,generate,install,list,run,test,vet}

What did you see instead?

$ go get -mod=mod ./...
flag provided but not defined: -mod
usage: go get [-d] [-t] [-u] [-v] [-insecure] [build flags] [packages]
Run 'go help get' for details.
@dmitshur dmitshur changed the title cmd/go: -mod flag does work with module get cmd/go: -mod flag doesn't work with module-mode go get Mar 3, 2021
@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Mar 3, 2021

@bcmills
Copy link
Member

@bcmills bcmills commented Mar 3, 2021

The purpose of go get in module mode is to edit the dependencies of the module. For that purpose, the only sensible -mod behavior is -mod=mod-mod=readonly or -mod=vendor would be incoherent.

I intentionally removed the -mod flag from go get in CL 198438 so that it could be set in GOFLAGS without causing errors in go get. (See #30345 and #32502.)

@bcmills
Copy link
Member

@bcmills bcmills commented Mar 3, 2021

So, probably the thing to fix here is to note the different behavior for go get in https://golang.org/ref/mod#build-commands.

@shmsr
Copy link
Contributor Author

@shmsr shmsr commented Mar 3, 2021

So, should I send a CL for this?

@bcmills
Copy link
Member

@bcmills bcmills commented Mar 3, 2021

Sure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants