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

Closed
shmsr opened this issue Mar 3, 2021 · 8 comments
Closed

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

shmsr opened this issue Mar 3, 2021 · 8 comments
Labels
Documentation GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@shmsr
Copy link
Contributor

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 added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Mar 3, 2021
@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 commented Mar 3, 2021

CC @bcmills, @jayconrod, @matloob.

@bcmills
Copy link
Contributor

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 bcmills closed this as completed Mar 3, 2021
@bcmills bcmills reopened this Mar 3, 2021
@bcmills bcmills added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Mar 3, 2021
@bcmills bcmills added this to the Backlog milestone Mar 3, 2021
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Mar 3, 2021
@bcmills
Copy link
Contributor

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 commented Mar 3, 2021

So, should I send a CL for this?

@bcmills
Copy link
Contributor

bcmills commented Mar 3, 2021

Sure!

@tenkoh
Copy link

tenkoh commented Sep 28, 2022

I have happened to meet the same issue.
If @shmsr doesn't mind, I will make a CL on documentation in a few days.

@shmsr
Copy link
Contributor Author

shmsr commented Sep 28, 2022

I have happened to meet the same issue. If @shmsr doesn't mind, I will make a CL on documentation in a few days.

Really sorry. Totally forgot about this. I'll send a CL ASAP.

@gopherbot
Copy link

Change https://go.dev/cl/475715 mentions this issue: _content/ref: note "go get" reject -mod flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants