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 - Recreate $GOPATH from go.mod/go.sum files #28295

Closed
rkedward opened this issue Oct 20, 2018 · 4 comments
Closed

cmd/go: mod - Recreate $GOPATH from go.mod/go.sum files #28295

rkedward opened this issue Oct 20, 2018 · 4 comments

Comments

@rkedward
Copy link

Please answer these questions before submitting your issue. Thanks!

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

1.11.1

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/nfs/orto/home/rkedward/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/hnfs/torcfs01n04a/vol/ret_users_rkedward/dev/play/grpc_golang_examples/.gospace"
GOPROXY=""
GORACE=""
GOROOT="/p/ret/rettools/stream/pkgs/golang/1.11.1"
GOTMPDIR=""
GOTOOLDIR="/p/ret/rettools/stream/pkgs/golang/1.11.1/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/hnfs/torcfs01n04a/vol/ret_users_rkedward/dev/play/grpc_golang_examples/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build592164460=/tmp/go-build -gno-record-gcc-switches"

What did you do?

% go 
go version go1.11.1 linux/amd64

# 1. Setup a project with a local gospace
% mkdir -p /path/to/mymod && cd /path/to/mymod
% export GOPATH=/path/to/mymod/.gospace
% mkdir -p  $GOPATH/pkg  # create the local gospace (aka virtual environment)
% mkdir -p  $GOPATH/bin

# 2. Install a module and package into the venv
% go mod  init example.com/myname/mymod
% go get -u google.golang.org/grpc  # install module
% go get -u github.com/golang/protobuf/protoc-gen-go  # install cmd/package
% ls $GOPATH/bin
protoc-gen-go

# 3. Wipe $GOPATH and reinstall from go.mod/go.sum files
% rm -rf  $GOPATH
% mkdir -p  $GOPATH/pkg
% mkdir -p  $GOPATH/bin
% go mod download 
% ls %GOPATH/bin
<empty>
...

What did you expect to see?

The protoc-gen-go file $GOPATH/bin directory after running go mod download

What did you see instead?

An empty directory

Rational

I would like to be able to recreate the $GOPATH exactly (bin, pkgs) from go.mod and go.sum. Since go.mod and go.sum are checked into the repository, another could clone the repo and recreate my development environment. This has many advantages for debugging/recreating issues to sharing project development environments between members.

@thepudds
Copy link
Contributor

@gopherbot, please add label modules

@thepudds
Copy link
Contributor

@rkedward I'm not sure that go mod download is the what you are looking for here. go mod download is for more narrow use cases such as pre-populating the module download cache, such as
in base docker images:
https://tip.golang.org/cmd/go/#hdr-Download_modules_to_local_cache

It sounds like part of what you are trying to do is track precise versions of tools as a dependency of your module? If so, you might want to give this FAQ on the modules wiki a quick read:
https://github.com/golang/go/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module

and there is a related runnable example of tracking tools as dependencies here (from @myitcv):
https://github.com/go-modules-by-example/index/blob/master/010_tools/README.md

@thepudds
Copy link
Contributor

And sorry if that is not a perfect answer. You might want to give those a quick read, and then follow up back here with additional questions, or more comments on your use case.

@myitcv
Copy link
Member

myitcv commented Oct 21, 2018

@rkedward - what you want to do here is use go mod vendor (see https://github.com/go-modules-by-example/index/blob/master/008_vendor_example/README.md for an example) and then move the vendor to be your $GOPATH/src directory. I do something similar in my CI for testing with Go 1.10 (ignore the GopherJS hack)

I'll close this on the basis that answers your question; but please shout it not and we can re-open.

@myitcv myitcv closed this as completed Oct 21, 2018
@golang golang locked and limited conversation to collaborators Oct 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants