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: go get can't fetch tools with mod=vendor #32502

Closed
variadico opened this issue Jun 9, 2019 · 4 comments

Comments

@variadico
Copy link

commented Jun 9, 2019

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

$ go version
go version go1.12.5 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
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jaime/.cache/go-build"
GOEXE=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/jaime/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build448668772=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I tried to install goimports from my home directory.

$ echo $GO111MODULE 
on
$ echo $GOFLAGS
-mod=vendor
$ pwd
/home/jaime
$ go get golang.org/x/tools/cmd/goimports
go get: disabled by -mod=vendor
$ 

What did you expect to see?

I expected the tool to work like it has for years. I expected go get to download and install goimports.

What did you see instead?

I got an error about -mod=vendor being on.

In my environment, we use vendoring. Because Go is moving away from dep and moving towards modules, we've started doing the work to migrate to modules.

A temporary work around for this bug is to do this.

GO111MODULE=off go get golang.org/x/tools/cmd/goimports
@AlexRouSg

This comment has been minimized.

Copy link
Contributor

commented Jun 9, 2019

Assuming you vendor your tools, you can try go install -mod=vendor golang.org/x/tools/cmd/goimports or go build -mod=vendor golang.org/x/tools/cmd/goimports

Edit: Just realized I misunderstood what you were trying to do

@mazei513

This comment has been minimized.

Copy link

commented Jun 10, 2019

This is more of an issue with -mod=vendor. Possible things you could try are

  1. Temporarily set -mod=vendor off.
GOFLAGS='' go get golang.org/x/tools/cmd/goimports
  1. Create a file named something like tools.go in the repo that references the tools you'd want to use.
// +build tools

package tools

import (
    _ "golang.org/x/tools/cmd/goimports"
    // and other tools used
)
@bcmills

This comment has been minimized.

Copy link
Member

commented Jun 10, 2019

#30240 may make the -mod=vendor unnecessary in the general case.

#30515 tracks some sort of command (probably a flag for go get) to install a binary independent of the current module.

Note that the argument to go get is a package, and go get some/package implicitly selects the latest version. That version can be arbitrarily different from what is in the vendor directory, so go get -mod=vendor really does seem like a contradictory command.

On the other hand, go get -mod=readonly intentionally ignores the -mod flag, precisely so that you can set it in GOFLAGS. Perhaps go get -mod=vendor should do the same.

@gopherbot

This comment has been minimized.

Copy link

commented Oct 3, 2019

Change https://golang.org/cl/198438 mentions this issue: cmd/go: remove the -mod flag from 'go get'

@bcmills bcmills self-assigned this Oct 3, 2019
@gopherbot gopherbot closed this in 6145a80 Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.