version: finish version setup

This setup will now correctly set the version number from the git tag.
When using `--version`, we will see the binary name, the package it was
built from and a git hash based on the tag:

```console
$./bin/dist -v
./bin/dist github.com/docker/containerd 0b45d91.m
```

Note that in the above example, if we set a tag of `v1.0.0-dev`, that
will show up in the version number, as follows:

```console
$./bin/dist -v
./bin/dist github.com/docker/containerd v1.0.0-dev
```

Once commits are made past that tag, the version number will be
expressed relative to that tag and include a git hash:

```console
$./bin/dist -v
./bin/dist github.com/docker/containerd v1.0.0-dev-1-g7953e96.m
```

Some these examples include a `.m` postfix. This indicates that the
binary was build from a source tree with local modifications.

We can add a dev tag to start getting 1.0 version numbers for test
builds.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day 2017-02-22 13:16:06 -08:00
parent 0b45d91340
commit 935144fadd
No known key found for this signature in database
GPG key ID: 67B3DED84EDC823F
5 changed files with 28 additions and 21 deletions

View file

@ -7,11 +7,11 @@ DESTDIR=/usr/local
# Used to populate version variable in main package.
VERSION=$(shell git describe --match 'v[0-9]*' --dirty='.m' --always)
PROJECT_ROOT=github.com/docker/containerd
PKG=github.com/docker/containerd
# Project packages.
PACKAGES=$(shell go list ./... | grep -v /vendor/)
INTEGRATION_PACKAGE=${PROJECT_ROOT}/integration
INTEGRATION_PACKAGE=${PKG}/integration
SNAPSHOT_PACKAGES=$(shell go list ./snapshot/...)
# Project binaries.
@ -21,7 +21,7 @@ BINARIES=$(addprefix bin/,$(COMMANDS))
# TODO(stevvooe): This will set version from git tag, but overrides major,
# minor, patch in the actual file. We'll have to resolve this before release
# time.
GO_LDFLAGS=-ldflags "-X `go list`.Version=$(VERSION)"
GO_LDFLAGS=-ldflags "-X $(PKG).Version=$(VERSION) -X $(PKG).Package=$(PKG)"
# Flags passed to `go test`
TESTFLAGS ?=-parallel 8 -race
@ -108,8 +108,8 @@ FORCE:
# Build a binary from a cmd.
bin/%: cmd/% FORCE
@test $$(go list) = "${PROJECT_ROOT}" || \
(echo "👹 Please correctly set up your Go build environment. This project must be located at <GOPATH>/src/${PROJECT_ROOT}" && false)
@test $$(go list) = "${PKG}" || \
(echo "👹 Please correctly set up your Go build environment. This project must be located at <GOPATH>/src/${PKG}" && false)
@echo "🐳 $@"
@go build -i -o $@ ${GO_LDFLAGS} ${GO_GCFLAGS} ./$<