Latest Links

Aug 18th

Go Vendoring On The Cheap

Go is great, but I just had to do something about its borderline insane dependency management.

Being able to do import github.com/foo/bar is cute, but there’s very little guarantee that dependencies won’t change overnight, and no practical way of pinning stuff to a specific version/revision. Having a strong desire to avoid a repeat of my early experiences with NodeJS, where stuff like express broke all of my code a few weeks down the road, I started looking for solutions early on.

But all the approaches I came across required third-party tools that are entirely too much hassle to set up and use reproducibly, so after a little experimentation, I converged on a rather lazy approach that mimics my usual Python pattern:

I set GOPATH to a vendor directory inside each project repository, go dep into that and clean out the .git/.hg folders in order to commit all the dependencies together with the project.

It’s a little wasteful in terms of storage, but perfectly doable for my ongoing projects and ensures that I’ll be able to rebuild things six months down the line. Plus it’s trivial to automate with a Makefile like so (which also makes it easy for me to do cross-compiles):

export GOPATH:=$(shell pwd)/vendor
export PATH:=$(PATH):$(GOPATH)/bin
BINARY=foobar

$(BINARY): *.go
    go build -o $(BINARY)

deps:
    mkdir -p vendor
    go get github.com/rakyll/globalconf
    go get github.com/efarrer/iothrottler
    find vendor -name .git | xargs rm -rf
    find vendor -name .hg | xargs rm -rf
    git add vendor/src

clean:
    rm -f $(BINARY)
    go fmt *.go

pi:
    GOARCH=arm GOARM=6 go build -o $(BINARY)-rpi

synology:
    GOARCH=arm GOARM=5 go build -o $(BINARY)-syno

So to add a dependency I just add another go get line, do a make deps and all the required code is added to the project. To update a dependency, I just remove its files and do it again. A trifle unsubtle, for sure, but it works, and has the additional side benefit of my being able to organize my projects anywhere on the filesystem without having to submit to Go’s “there can be only one way to organize your code” silliness.

Since make is available pretty much everywhere and not something that is likely to go out of fashion (outside the NodeJS world, that is, where they keep reinventing it), I think this solves my problems for the foreseeable future — or until Go standardizes on something at least as simple to use and maintain.


Recent Posts

Summer Mornings

I’ve been skimping on writing lately, so I feel I must make amends with a sort of brain dump. Read More

Not That Better

It seems that my decision to rebuild this server atop btrfs for better container management has come back to bite me. Read More

Reviving a dead synth with a Raspberry Pi

I’ve never been much of a musician, but I had some fun with a Kawai K1-II for a number of years. And it seems that will go on even after it died. Read More

After the Storm

The weather is back to its (un)usual antics, and so am I, to a degree — a sizable portion of the week was spent attending the Data Storm Big Data Summer School at my alma mater. Read More

A Matter of Identity

Over the years, a few people asked me what it’s like to be Portuguese — to which my invariable reply consisted of stating I was (still am, in fact) almost anything but, except statistically. Read More

Go-like concurrency (and profiling!) in Hy and PyPy

Waking up at 6:30 AM has bestowed upon me a blissful, irritant-free period that is perfect for contemplation, so of course I used it for a few experiments instead. Read More

Environmental Picks

I find it hilarious to watch programming language partisans astroturfing. Sometimes I even play along. Read More

Freak Weather

June showers seem to be a weather fad for the past few years here in Lisbon. Read More