Skip to content

Commit

Permalink
Determine version via go 1.18's buildinfo
Browse files Browse the repository at this point in the history
This makes it possible to use go install with the github URL and end up with an
executable that knows it's version.

At the moment we still set the version when building via the build-release
script.
  • Loading branch information
schmir committed Apr 30, 2022
1 parent 3f62019 commit 9807d04
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 1 addition & 3 deletions rolling-shutter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ BINDIR ?= ./bin
EXECUTABLE ?= ${BINDIR}/rolling-shutter

build:
@VERSION=`git describe --tags --always --abbrev=4 --dirty --match 'rolling-shutter/v*' | sed -e s#^rolling-shutter/##`; \
echo "Building ${EXECUTABLE} $${VERSION}"; \
${GO} build ${GOFLAGS} -o ${EXECUTABLE} -ldflags "-X github.com/shutter-network/rolling-shutter/rolling-shutter/cmd/shversion.version=$${VERSION}"; \
${GO} build ${GOFLAGS} -o ${EXECUTABLE}

wasm:
GOARCH=wasm GOOS=js ${GO} build ${GOFLAGS} -o ${BINDIR}/shcrypto.wasm ./shcryptowasm/main_wasm.go
Expand Down
18 changes: 17 additions & 1 deletion rolling-shutter/cmd/shversion/shversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ package shversion
import (
"fmt"
"runtime"
"runtime/debug"
)

var version string = "(unknown)"
var version string

// Version returns shuttermint's version string.
func Version() string {
if version == "" {
info, ok := debug.ReadBuildInfo()
if ok {
version = info.Main.Version
if version == "(devel)" {
for _, s := range info.Settings {
if s.Key == "vcs.revision" {
version = fmt.Sprintf("(devel-%s)", s.Value)
break
}
}
}
}
}

var raceinfo string
if raceDetectorEnabled {
raceinfo = ", race detector enabled"
Expand Down

0 comments on commit 9807d04

Please sign in to comment.