build/version: move version.go to build pkg
This commit is contained in:
parent
bbceec8bea
commit
1e64070a1d
@ -3,7 +3,7 @@
|
||||
// Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go
|
||||
// Copyright (C) 2015-2017 The Lightning Network Developers
|
||||
|
||||
package main
|
||||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -11,6 +11,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Commit stores the current commit hash of this build, this should be set using
|
||||
// the -ldflags during compilation.
|
||||
var Commit string
|
||||
|
||||
// semanticAlphabet
|
||||
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-"
|
||||
|
||||
@ -26,14 +30,9 @@ const (
|
||||
appPreRelease = "beta"
|
||||
)
|
||||
|
||||
// appBuild is defined as a variable so it can be overridden during the build
|
||||
// process with '-ldflags "-X main.appBuild foo' if needed. It MUST only
|
||||
// contain characters from semanticAlphabet per the semantic versioning spec.
|
||||
var appBuild string
|
||||
|
||||
// version returns the application version as a properly formed string per the
|
||||
// Version returns the application version as a properly formed string per the
|
||||
// semantic versioning 2.0.0 spec (http://semver.org/).
|
||||
func version() string {
|
||||
func Version() string {
|
||||
// Start with the major, minor, and patch versions.
|
||||
version := fmt.Sprintf("%d.%d.%d", appMajor, appMinor, appPatch)
|
||||
|
||||
@ -46,15 +45,6 @@ func version() string {
|
||||
version = fmt.Sprintf("%s-%s", version, preRelease)
|
||||
}
|
||||
|
||||
// Append build metadata if there is any. The plus called for
|
||||
// by the semantic versioning spec is automatically appended and should
|
||||
// not be contained in the build metadata string. The build metadata
|
||||
// string is not appended if it contains invalid characters.
|
||||
build := normalizeVerString(appBuild)
|
||||
if build != "" {
|
||||
version = fmt.Sprintf("%s+%s", version, build)
|
||||
}
|
||||
|
||||
// Append commit hash of current build to version.
|
||||
version = fmt.Sprintf("%s commit=%s", version, Commit)
|
||||
|
Loading…
Reference in New Issue
Block a user