From 2ab72bdf94cdc5aa3f272e69464d2aff65bba0f0 Mon Sep 17 00:00:00 2001 From: James Shubin Date: Mon, 4 Apr 2016 01:18:04 -0400 Subject: [PATCH] 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! --- gopath/.gitignore | 2 ++ gopath/src | 1 + misc/go | 12 ++++++++++++ 3 files changed, 15 insertions(+) create mode 100644 gopath/.gitignore create mode 120000 gopath/src create mode 100755 misc/go diff --git a/gopath/.gitignore b/gopath/.gitignore new file mode 100644 index 00000000..882d4499 --- /dev/null +++ b/gopath/.gitignore @@ -0,0 +1,2 @@ +bin/ +pkg/ diff --git a/gopath/src b/gopath/src new file mode 120000 index 00000000..9c39cc9f --- /dev/null +++ b/gopath/src @@ -0,0 +1 @@ +../vendor \ No newline at end of file diff --git a/misc/go b/misc/go new file mode 100755 index 00000000..7e612698 --- /dev/null +++ b/misc/go @@ -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