The canonical way of publishing Go code is providing a repo which is
"go get"-able. OK, fine. So, now I want to build some well-behaved
canonical Go code, and do something with the artifact, like ship it
somewhere.
I have a build infrastructure, like Travis, which can build any repo.
The build system takes as input a repository (location) and a
revision. It will check out that repo at that revision, and then do
<something>, which (if successful) will produce my build artifact in a
known location.
What is <something>?
It's not "make", because my canonical Go code doesn't have a Makefile.
It's not "go build", because that doesn't produce an artifact.
It could be "go install", but my checked-out repo isn't necessarily in
a $GOPATH. In fact, I don't even have a $GOPATH set in my build
environment. That's fine, I can set up an arbitrary $GOPATH as part of
my <something>, and create $GOPATH/src/myrepo as a symlink to
/path/to/checked/out/myrepo. Except, whoops, none of my dependencies
are there. How does the Go toolchain resolve dependencies? Right --
"go get" automatically fetches, builds, and installs them. I should
probably leverage that.
So it could be "go get ." (hat tip to Alex Surma for discovering this
AFAIK). I've actually been using this method for some time in another
context, but I've now hit a wall trying to help get Go support in
Travis. When I create the symlink and cd to $GOPATH/src/myrepo, the go
tool gets confused about where it is and says:
/arbitrary/gopath/src/myrepo$ go get -v .
go install: no install location for /path/to/checked/out/myrepo
The exact problem is at [0]. On advice, I tried dropping the symlink
and copying the .go source files to the $GOPATH/src directory
directly, and that worked[1]. So there appears to be some buggy
behavior in "go get". But that's really not my point, which is rather
that this all seems so fragile, so poorly-thought-out. (Is "go get ."
even officially supported behavior, or is it working by accident?) In
any case I can't go back to my contact at Travis and suggest the
default behavior for Go projects is to cp -r the folder to another
location; he's already generally mystified by the GOPATH requirements,
especially given that no other supported language (of a dozen+)
demands anything like this level of specificity.
I digress. I must be missing something: given that you're sitting in a
directory which contains exactly the Go code you want to build, *with
no other assumptions about your environment*, how are you meant to
convert that into an artifact (ie. binary), canonically?
_____
[0]
http://travis-ci.org/#!/peterbourgon/g2g/builds/1820924
[1]
http://travis-ci.org/#!/peterbourgon/g2g/builds/1821107