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: run gives conflicting advice when using path@version syntax #29415

Open
davecheney opened this issue Dec 25, 2018 · 13 comments
Open

cmd/go: run gives conflicting advice when using path@version syntax #29415

davecheney opened this issue Dec 25, 2018 · 13 comments

Comments

@davecheney
Copy link
Contributor

@davecheney davecheney commented Dec 25, 2018

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

% go version
go version devel +97d5cb24b1 Sat Dec 22 09:37:04 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

unknown

What operating system and processor architecture are you using (go env)?

go env Output
% go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dfc/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GOPROXY=""
GORACE=""
GOROOT="/home/dfc/go"
GOTMPDIR=""
GOTOOLDIR="/home/dfc/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build125128327=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Go 1.12beta1 (tip) does not permit @Version syntax unless modules explicitly enabled, even if GOPATH is unset

% unset GOPATH && go run -v github.com/davecheney/httpstat@1.0.0
package github.com/davecheney/httpstat@1.1.0: cannot use path@version syntax in GOPATH mode

What did you expect to see?

env GO111MODULE=on go run -v github.com/davecheney/httpstat@1.0.0

would download and build httpstat v1.0.0

What did you see instead?

% unset GOPATH && env GO111MODULE=on go run -v github.com/davecheney/httpstat@1.0.0
missing $GOPATH

Running without modules enabled tells me I must enable modules even thought I don't have GOPATH set. Running with modules enable tells me I must set GOPATH.

lucky(/tmp) % env GO111MODULE=on GOPATH=/tmp/ go run -v github.com/davecheney/httpstat@1.0.0
package github.com/davecheney/httpstat@1.0.0: can only use path@version syntax with 'go get'

Setting both tells me that this isn't supported.

a. Can go run path@version be supported? If not, why not?
b. Can the error messages be improved make it clearer sooner that the operation will not succeed once the correct permutation of environment variables is discovered.

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Dec 27, 2018

Thank you for this report @davecheney!

Kindly paging @bcmills @rsc.

@odeke-em odeke-em changed the title go run gives conflicting advice when using path@version syntax cmd/go: run gives conflicting advice when using path@version syntax Dec 27, 2018
@jadekler
Copy link
Contributor

@jadekler jadekler commented Jan 4, 2019

Seems to not be working for me, either:

$ cd /tmp/whatever && unset GOPATH && go get cloud.google.com/go@v0.30.0
go: cannot use path@version syntax in GOPATH mode
@ahmetb
Copy link

@ahmetb ahmetb commented Jan 4, 2019

Hit this as well in #29575. Closing that as duplicate.

@bcmills bcmills added this to the Go1.13 milestone Jan 8, 2019
@bcmills bcmills added the modules label Jan 8, 2019
@rsc
Copy link
Contributor

@rsc rsc commented Jan 10, 2019

Only go get and module-manipulation commands take path@version.
go build, go run, etc do not.

@jadekler
Copy link
Contributor

@jadekler jadekler commented Jan 10, 2019

Go get does not take path@version for me. I've filed #29659, since that appears to be different from the go run case that this issue was describing. (happy to dedupe if you prefer the conversation to happen here)

@ahmetb
Copy link

@ahmetb ahmetb commented Jan 30, 2019

Can someone take a look at this please?

Example from https://golang.org/cmd/go/#hdr-Module_aware_go_get which is go get golang.org/x/text@v0.3.0 doesn't work and fails with the same error when GOPATH environment variable is not set.

This is breaking go-get’s ability as a package manager as the support for the go get -v github.com/rakyll/hey@v0.1.1 syntax is currently not working.

@bcmills
Copy link
Member

@bcmills bcmills commented Jan 30, 2019

@ahmetb, this issue is about the diagnostic messages. If go get is not actually behaving as documented, please file that as a separate issue.

That said, from the detail in #29575 it appears that you are, in fact, running in GOPATH mode.
Per https://golang.org/cmd/go/#hdr-Preliminary_module_support:

If GO111MODULE=auto or is unset, then the go command enables or disables module support based on the current directory. Module support is enabled only when the current directory is outside GOPATH/src and itself contains a go.mod file or is below a directory containing a go.mod file.

@ahmetb
Copy link

@ahmetb ahmetb commented Apr 12, 2019

@bcmills I'm still seeing this despite I'm not running in GOPATH mode. go get or go build uses modules just fine when I don't specify a @version syntax.

Here's a minimal repro with go1.12

dir=$(mktemp -d)

cd $dir

# write a go.mod to indicate go111module=on
echo 'module foo' > go.mod

go get module syntax uses go.mod file:

# unset all env vars, with the exception of $HOME (mock it) and $PATH (inherit it)

env -i HOME="$PWD/mock-home" PATH="$PATH" go build -o ./httpstat github.com/davecheney/httpstat

    go: finding github.com/davecheney/httpstat v1.0.0
    go: downloading github.com/davecheney/httpstat v1.0.0
    go: extracting github.com/davecheney/httpstat v1.0.0
    ...
    (works)

go get module@1.0.0 syntax is not working in the same setup:

env -i HOME="$PWD/mock-home" PATH="$PATH" go build -o ./httpstat github.com/davecheney/httpstat@1.0.0

can't load package: package github.com/davecheney/httpstat@1.0.0: can only use path@version syntax with 'go get'

Would you still suggest I'm in "GOPATH mode"?

@bcmills
Copy link
Member

@bcmills bcmills commented Apr 12, 2019

@ahmetb, this issue is about the go command giving conflicting advice.

The advice from the commands you posted above does not conflict: it correctly indicates that, in module mode (which you are clearly in), you “can only use path@version syntax with 'go get'”.

@probonopd
Copy link

@probonopd probonopd commented Nov 2, 2019

With Go 1.13, also running into

imports github.com/diskfs/go-diskfs/filesystem@squashfs: cannot use path@version syntax in GOPATH mode

This is so annoying. Especially because it does not tell one what to do.

@smikulcik
Copy link

@smikulcik smikulcik commented Nov 25, 2019

From what I can tell, you just have to be in a package that has a go.mod file. Then you can get a particular version.

@nivekastoreth
Copy link

@nivekastoreth nivekastoreth commented Feb 4, 2020

Thanks to @smikulcik's comment go get is at least minimally functional.

As someone who doesn't program in go and only uses it to install utilities written in go, it's extremely frustrating spending an hour trying to figure out how to install a simple application only to find out I have to pretend to be working on a project in order to install a version of a utility that's needed.

@AgrPriyank
Copy link

@AgrPriyank AgrPriyank commented Feb 14, 2020

From what I can tell, you just have to be in a package that has a go.mod file. Then you can get a particular version.

As I understand it, path@version should be used in Golang specifically for version maintenance. Hence @smikulcik comment to run the command in directory with go.mod file makes sense. Go will try to download the repository to your src folder from Github and will try to maintain the version in the mod file.

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
You can’t perform that action at this time.