Use internal versioning
Signed-off-by: Aoi K <koizumi.aoi@chaotic.ninja> git-svn-id: https://svn.yakumo.dev/yakumo.izuru/suika/trunk@809 f0ae65fe-ee39-954e-97ec-027ff2717ef4
This commit is contained in:
parent
b4caef0619
commit
526d067cc2
7
Makefile
7
Makefile
@ -1,13 +1,18 @@
|
||||
GO ?= go
|
||||
RM ?= rm
|
||||
SCDOC ?= scdoc
|
||||
GOFLAGS ?= -v
|
||||
GOFLAGS ?= -v -ldflags "-w -X `go list`.Version=$(VERSION) -X `go list`.Commit=$(COMMIT) -X `go list`.Build=$(BUILD)"
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= bin
|
||||
MANDIR ?= share/man
|
||||
MKDIR ?= mkdir
|
||||
CP ?= cp
|
||||
|
||||
VERSION = `git describe --abbrev=0 --tags 2>/dev/null || echo "$VERSION"`
|
||||
COMMIT = `git rev-parse --short HEAD || echo "$COMMIT"`
|
||||
BRANCH = `git rev-parse --abbrev-ref HEAD`
|
||||
BUILD = `git show -s --pretty=format:%cI`
|
||||
|
||||
all: suika suikactl suika-znc-import doc/suika.1
|
||||
|
||||
suika:
|
||||
|
50
version.go
Normal file
50
version.go
Normal file
@ -0,0 +1,50 @@
|
||||
package suika
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime/debug"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultVersion = "0.0.0"
|
||||
defaultCommit = "HEAD"
|
||||
defaultBuild = "0000-01-01:00:00+00:00"
|
||||
)
|
||||
|
||||
var (
|
||||
// Version is the tagged release version in the form <major>.<minor>.<patch>
|
||||
// following semantic versioning and is overwritten by the build system.
|
||||
Version = defaultVersion
|
||||
|
||||
// Commit is the commit sha of the build (normally from Git) and is overwritten
|
||||
// by the build system.
|
||||
Commit = defaultCommit
|
||||
|
||||
// Build is the date and time of the build as an RFC3339 formatted string
|
||||
// and is overwritten by the build system.
|
||||
Build = defaultBuild
|
||||
)
|
||||
|
||||
// FullVersion display the full version and build
|
||||
func FullVersion() string {
|
||||
var sb strings.Builder
|
||||
|
||||
isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
|
||||
|
||||
if !isDefault {
|
||||
sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
|
||||
}
|
||||
|
||||
if info, ok := debug.ReadBuildInfo(); ok {
|
||||
if isDefault {
|
||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
|
||||
if info.Main.Sum != "" {
|
||||
sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
|
||||
}
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user