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

Closed
mildred opened this issue May 31, 2017 · 5 comments
Closed

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

mildred opened this issue May 31, 2017 · 5 comments

Comments

@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
Copy link
Contributor

rsc commented Jun 5, 2017

On hold for package management.

@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
@agnivade
Copy link
Contributor

@bcmills @rsc - Does this still make sense now ?

@mildred
Copy link
Author

mildred commented Apr 10, 2019 via email

@bcmills
Copy link
Contributor

bcmills commented Apr 10, 2019

Pulling the Proposal-Hold label so that this can be re-reviewed in light of module support stabilizing.

@andybons
Copy link
Member

Per @golang/proposal-review, with modules stabilizing further, this doesn’t make much sense now. Thanks.

@golang golang locked and limited conversation to collaborators Apr 16, 2020
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

6 participants