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: module go install cmd with relative import path resolved against $GOPATH #35918
Comments
/cc @jayconrod @bcmills |
I think this is working as intended. The Relative paths are described in |
Well...that is curious. The package did have a go.mod file, and it was ignored. The entire go install process ignored the go.mod files -- but simply changing the install command to be inside the directory triggered module=on behavior. So two different forms of the "go install" command cause different results: one ignores the go.mod files and does a local disk compile and the other recognizes the modules and goes out to github.com to resolve the imports, etc. And look at "go help gopath": "GOPATH and Modules When using modules, GOPATH is no longer used for resolving imports. So if Go had been using modules it would have ignored the gopath/src and gone out to github to get the imports. I have tested this and that is the way it works. If you think it works as intended, then that is fine with me. It just doesn't seem to match the documentation. |
From "go help packages" An import path that is a rooted path or that begins with a . or .. element is interpreted as a file system path and denotes the package in that directory. Otherwise, the import path P denotes the package found in the directory DIR/src/P for some DIR listed in the GOPATH environment variable (For more details see: 'go help gopath'). I think that is pretty clear: it "denotes the package found in that directory". And in my case, that package had a go.mod file. Which was ignored. To take the alternative reading of the documentation would be to say: 'Fire up the command line and enter "go install github.com/userid/repo/pkgname" and if the user's home directory has a go.mod file that is what will be input to go install.' Would that be reasonable behavior? |
Go 1.13 includes support for Go modules. Module-aware mode is active by default whenever a go.mod file is found in, or in a parent of, the current directory.
|
OK, thank you for explaining that. |
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
NOTE: This is documented in github.com/Conformable/gotests/experiments/e003, e003b and e003c. The tests have re-runnable bash scripts and store the input and output of go install.
All of the tests are contained in a .zip for reuse.
go install github.com/githubuserid/reponame/pkgname
Am testing go install with all permutations: local-disk/remote vcs, internet on/off, GOPROXY on/off, etc. etc.
The current test is with internet off and just local disk source code within the $GOPATH.
If a package name is specified on the go install command line which is a relative path, relative to $GOPATH, then the install works successfully without accessing github.com -- BUT it is apparently treated as a non-module install. The go.mod file is not updated.
On the other hand, if go install is performed inside the package's directory like so, "go install", then Go does not resolve the imported package's path against $GOPATH -- this behavior matches the "go help gopath" documentation -- and it tries to access github.com using the internet.
What did you expect to see?
I expected the go install which used a relative import path to fail.
What did you see instead?
But it worked, though it did not recognize that the package had a go.mod file (apparently) and did not update it.
The text was updated successfully, but these errors were encountered: