Allow stubborn users to avoid having to move their project
Some users like to have their project in ~/code/mgmt/ for example, but this is not compatible with a $GOPATH which is elsewhere. This isn't a problem unless you need vendored directories in ~/code/mgmt/vendor/ which doesn't work because ~/code/mgmt/ isn't in $GOPATH. With this symlink and the provided ~/bin/go wrapper, vendored directories work exactly as expected, and we also get a local $GOPATH pointing to the same thing. Since $GOPATH must have a src/ dir, and vendor/ must NOT, then we symlink the two together accordingly. An important part of this is that those who like to put everything in $GOPATH won't be affected by any of this!
This commit is contained in:
2
gopath/.gitignore
vendored
Normal file
2
gopath/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
bin/
|
||||
pkg/
|
||||
1
gopath/src
Symbolic link
1
gopath/src
Symbolic link
@@ -0,0 +1 @@
|
||||
../vendor
|
||||
12
misc/go
Executable file
12
misc/go
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
# hack around stupid $GOPATH semantics, with ~/bin/go helper
|
||||
# thanks to Nilium in #go-nuts for 1/3 of the idea
|
||||
[ -z "$GOPATH" ] && echo '$GOPATH is not set!' && exit 1
|
||||
GO="$(which -a go | sed -e '2q;d')" # TODO: pick /usr/bin/go in a better way
|
||||
# the idea is to have $project/gopath/src/ be a symlink to ../vendor but you put
|
||||
# all of your vendored things in vendor/ but with this gopath can be per project
|
||||
if [ -d "$PWD/vendor/" ] && [ -d "$PWD/gopath/" ] && [ "`readlink $PWD/gopath/src`" = "../vendor" ] ; then
|
||||
GOPATH="$PWD/gopath/:$GOPATH" $GO "$@"
|
||||
else
|
||||
$GO "$@"
|
||||
fi
|
||||
Reference in New Issue
Block a user