2019-07-25 WG follow-up: injecting versioning information at build time

Jacob Blain Christen (Intel)
 

As discussed in this morning’s call, there are extant examples of injecting versioning information into your binaries at build time, most of which leverage `git describe`. I mentioned Consul and jq and have since poked around for some pointers to share.

 

Consul is built with gox which is a go toolchain wrapper that Mitchell Hashimoto wrote to deal with various shortcomings of early 1.x go. Don’t let that get in the way of understanding that gox does to pass through many command-line switches to `go build` and specifically to our interest -ldflags. All of this is to say, focus on the ldflags callout and realize that the Consul GNUMakefile is eventually invoking the go toolchain.

 

This link shows how Consul is invoking `git describe`:

https://github.com/hashicorp/consul/blob/421ecd32fc8fe9933cf50005eafc14705ffd45b1/GNUmakefile#L29

 

and this link shows how the Consul build script makes use of the exported GOLDFLAGS envvar:

https://github.com/hashicorp/consul/blob/63508c601538bfa11f1d0a644a4adb3ee01e489a/build-support/functions/20-build.sh#L306

 

 

Another good example is jq which is written in C. This link shows a utility script that invokes `git describe`:

https://github.com/stedolan/jq/blob/jq-1.6/scripts/version

 

and this link shows how that information is used to generate a version.h header:

https://github.com/stedolan/jq/blob/jq-1.6/Makefile.am#L96

 

 

These represent common patterns in my experience. We would probably want to lift from the Consul project how it invokes `git describe`, e.g. `git describe --tags --always --match "v*"` because this makes it more explicit that we only care about our semver information embedded in tags. The `--always` tells git describe to fallback to a 7 character sha prefix (instead of exiting with an error) if there are no matching tags which enough information for automation to assume and inject a default initial value for the version (if so desired).

 

I am happy to discuss this further and/or develop a plan forward via working session(s) but I hope this is at least a decent primer on what other projects our in the world are doing to inject version at build time.

Join EdgeX-TSC-DevOps@lists.edgexfoundry.org to automatically receive all group messages.