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: confusion with module-aware get changes #26591

Closed
anacrolix opened this issue Jul 25, 2018 · 11 comments
Closed

cmd/go: confusion with module-aware get changes #26591

anacrolix opened this issue Jul 25, 2018 · 11 comments
Labels
Documentation FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@anacrolix
Copy link
Contributor

Previously go get would check out code necessary to install something. With go modules, that changes. go install is now required to install something external to the current module. Go get will merely check out and add dependencies (so far as I can tell).

While the new behavior seems superior, it is surprising. I couldn't find any clarification on this. I'm also not sure how one would prevent go install from downloading code.

@mvdan
Copy link
Member

mvdan commented Jul 25, 2018

I'm also not sure how one would prevent go install from downloading code.

Maybe you want #26361. Or perhaps one of the existing -getmode modes.

I couldn't find any clarification on this.

I think you want go help module-get. From the last paragraph in go help get:

This text describes the behavior of get when using GOPATH
to manage source code and dependencies.
If instead the go command is running in module-aware mode,
the details of get's flags and effects change, as does 'go help get'.
See 'go help modules' and 'go help module-get'.

@mvdan mvdan added the modules label Jul 25, 2018
@mvdan mvdan added this to the Go1.11 milestone Jul 25, 2018
@mvdan mvdan changed the title go get changes with go modules cmd/go: confusion with module-aware get changes Jul 25, 2018
@mvdan
Copy link
Member

mvdan commented Jul 25, 2018

Milestoned for 1.11 in case there's anything else to do here. cc @rsc @bcmills

@bcmills
Copy link
Contributor

bcmills commented Jul 26, 2018

I'm also not sure how one would prevent go install from downloading code.

From downloading code for existing dependencies, or from adding new dependencies?
(Adding new dependencies is #26361.)

@bcmills bcmills added Documentation NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jul 26, 2018
@anacrolix
Copy link
Contributor Author

If I want to install an arbitrary command, like go get used to do, what do I do now? If I want to install an arbitrary command, without downloading anything (what go install used to do), what now?

@earthboundkid
Copy link
Contributor

I find the new behavior confusing as well.

$ mkdir /tmp/gopath
$ GO111MODULE=on GOPATH=/tmp/gopath go1.11beta2 get -v github.com/baltimore-sun-data/boreas
go: cannot find main module root; see 'go help modules'
$ GO111MODULE=on GOPATH=/tmp/gopath go1.11beta2 install -v github.com/baltimore-sun-data/boreas
go: cannot find main module root; see 'go help modules'

Is there a way to install arbitrary CLI tools with the go command any more, or do I have to git clone instead?

@myitcv
Copy link
Member

myitcv commented Aug 3, 2018

@carlmjohnson yes you can use go install, but you will need a go.mod file, i.e. a module, as the starting point for that.

So if you want these tools to be generally available you could do something like:

mkdir -p $HOME/gotools
cd $HOME/gotools
mkdir bin
export GOBIN=$HOME/gotools/bin
go mod init gotools

GOBIN is a way of specifying exactly where programs should be installed.

Then:

go install github.com/baltimore-sun-data/boreas

Notice how you don't care what value is set for GOPATH; GOBIN becomes the relevant directory.

You might then also want to add the export above to your .bashrc or equivalent.

@earthboundkid
Copy link
Contributor

Doesn't work:

$ GO111MODULE=on go1.11beta2 mod init whatever
go: cannot find main module root; see 'go help modules'

@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

Is there a way to install arbitrary CLI tools with the go command any more, or do I have to git clone instead?

That's #24250.

@bcmills
Copy link
Contributor

bcmills commented Aug 3, 2018

@carlmjohnson, mod -init was changed to mod init after go1.11beta2. Either build from head or use the older spelling of the flag.

@earthboundkid
Copy link
Contributor

$ GO111MODULE=on GOPATH=/tmp/gopath go1.11beta2 mod -init
go: cannot determine module path for source directory /tmp/gopath (outside GOPATH, no import comments)
$ GO111MODULE=on GOPATH=/tmp/gopath go1.11beta2 mod -init whatever
go mod: mod takes no arguments

My Go projects (including Boreas) all include these installation instructions in the README:

First install Go. If you just want to install the binary to your current directory and don't care about the source code, run GOBIN="$(pwd)" GOPATH="$(mktemp -d)" go get github.com/baltimore-sun-data/boreas.

It looks like for Go 1.12, if #24250 doesn't happen, I will need to change the instructions to

git clone $REPO
cd $PKG
GOBIN=$(pwd)/../bin GOPATH=$(mktemp -d) go install -v ./...

Three lines instead of one is not the end of the world, but it would be nice if I could just say to run a single command.

@myitcv
Copy link
Member

myitcv commented Aug 7, 2018

I think (per #26591 (comment)) this is covered by #24250; please shout if that's not the correct conclusion.

@myitcv myitcv closed this as completed Aug 7, 2018
@golang golang locked and limited conversation to collaborators Aug 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge modules NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants