pax_global_header00006660000000000000000000000064127444103500014512gustar00rootroot0000000000000052 comment=b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/000077500000000000000000000000001274441035000212025ustar00rootroot00000000000000buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/README.md000066400000000000000000000027011274441035000224610ustar00rootroot00000000000000# Go build information utilities These are some small build information utilities I wrote for tracking Go binary version information. Rather than trying to assign a linear version number to a binary, the tag names and version control commit hashes of all dependencies are tracked. This information is then burnt into the binary at build time. You use the shell script `gen`, included, to generate the version information blob. It outputs arguments suitable for `go build`, so you can use it like `go build ./... -ldflags "$($GOPATH/src/github.com/hlandau/buildinfo/gen ./...)"`. ## For upstream packagers OS upstream packagers which want to specify their own information may do so: simply set the `github.com/hlandau/buildinfo.RawBuildInfo` string variable at build time, by passing `-ldflags -X github.com/hlandau/buildinfo.RawBuildInfo=BUILDINFO...` to `go build`. This expects base64-encoded data in a particular format. If you want to specify an arbitrary freeform string instead, set `BuildInfo` instead of `RawBuildInfo`. The string you specify will be used verbatim without modification. Example: ``` go install -ldflags '-X github.com/hlandau/buildinfo.BuildInfo="Packaged by Distro X"' \ github.com/my/project ``` ### Previous location This package was previously located at `github.com/hlandau/degoutils/buildinfo`. Packagers setting `github.com/hlandau/degoutils/buildinfo.BuildInfo` will need to change to `github.com/hlandau/buildinfo.BuildInfo`. buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/buildinfo.go000066400000000000000000000017471274441035000235150ustar00rootroot00000000000000package buildinfo import ( "encoding/base64" "fmt" "gopkg.in/hlandau/easyconfig.v1/cflag" "os" "runtime" "strings" ) // Full build info. var BuildInfo string // Set via go build. var RawBuildInfo string // Program-settable extra version information to print. var Extra string // You should never need to call this. func Update() { if RawBuildInfo == "" || BuildInfo != "" { return } b, err := base64.RawStdEncoding.DecodeString(strings.TrimRight(RawBuildInfo, "=")) if err != nil { return } BuildInfo = string(b) } func init() { versionFlag := cflag.Bool(nil, "version", false, "Print version information") versionFlag.RegisterOnChange(func(bf *cflag.BoolFlag) { if !bf.Value() { return } fmt.Print(Full()) os.Exit(2) }) Update() } func Full() string { bi := BuildInfo if bi == "" { bi = "build unknown" } return fmt.Sprintf("%sgo version %s %s/%s %s cgo=%v\n%s\n", Extra, runtime.Version(), runtime.GOOS, runtime.GOARCH, runtime.Compiler, Cgo, bi) } buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/cgo-no.go000066400000000000000000000000651274441035000227140ustar00rootroot00000000000000// +build !cgo package buildinfo const Cgo = false buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/cgo-yes.go000066400000000000000000000000631274441035000230760ustar00rootroot00000000000000// +build cgo package buildinfo const Cgo = true buildinfo-b25d4b0e518fdb8bcbefaa3d52d77473bebe08fd/gen000077500000000000000000000014241274441035000217020ustar00rootroot00000000000000#!/bin/bash [ -z "$BUILDNAME" ] && BUILDNAME="$(date -u "+%Y%m%d%H%M%S") on $(hostname -f)" BUILDINFO="$((echo built $BUILDNAME; go list -f '{{range $imp := .Deps}}{{printf "%s\n" $imp}}{{end}}' "$1" | sort -u | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | awk "{print \"$GOPATH/src/\" \$0}" | (while read line; do x="$line"; while [ ! -e "$x/.git" -a ! -e "$x/.hg" ]; do x=${x%/*}; if [ "$x" = "" ]; then break; fi; done; echo "$x"; done) | sort -u | (while read line; do echo git ${line#$GOPATH/src/} $(git -C "$line" rev-parse HEAD) $(git -C "$line" describe --all --dirty=+ --abbrev=99 --always); done)) | base64 | tr -d '\n')" # (base64 -w 0 doesn't work on busybox, so use base64 | tr -d '\n' instead) echo -X github.com/hlandau/buildinfo.RawBuildInfo=$BUILDINFO