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

proposal: cmd/go: partial GOPATH source trees, or GOPATH mounts #20535

Open
mildred opened this Issue May 31, 2017 · 1 comment

Comments

Projects
None yet
3 participants
@mildred
Copy link

mildred commented May 31, 2017

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

1.8.1

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

linux

Explanation of the issue

In projects using different languages and tools, it is difficult to always clone a Go code repository inside a GOPATH. This makes it difficult for external tools to build Go projects. What I want to achieve is:

  • Clone a go project anywhere you want
  • Run a shell script or a Makefile to build an executable, it should work

This is possible using a temporary GOPATH in the script, and symlinks, but not easy to do.

Proposal

Have a GOPATH_MOUNTS environment variable containing a list of directories and their name in the go package hierarchy. Those directories will be read as if they were mounted in the GOPATH/src/source-location.

For example:

GOPATH=/home/me/go
GOPATH_MOUNTS=github.com/me/foo=/home/me/project/foo:github.com/me/bar=/home/me/project/bar

With this configuration, a package github.com/me/foo/a would be searched in /home/me/project/foo/a while a package github.com/me/baz would still be searched under /home/me/go/src/github.com/me/baz.

Actual workarounds

I'm currently using two workarounds, mainly. The first is simple. The git repository is a gopath in itself, and won't be able to be imported. This is the case of https://github.com/mildred/ipfs-objects/

The other solution is to use some tricks with symlinks in the Makefile to build the project even if outside of the GOPATH. The main idea is to setup a custom GOPATH using:

IMPORT_PATH=github.com/me/foo
mkdir -p "gopath/src/$IMPORT_PATH"
ln -s "$PWD" "gopath/src/$IMPORT_PATH"
export GOPATH="$PWD/gopath"
go build "$IMPORT_PATH"
@rsc

This comment has been minimized.

Copy link
Contributor

rsc commented Jun 5, 2017

On hold for package management.

@rsc rsc added the Proposal-Hold label Jun 5, 2017

@bcmills bcmills changed the title proposal: partial GOPATH source trees, or GOPATH mounts proposal: cmd/go: partial GOPATH source trees, or GOPATH mounts Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.