2017-11-28 03:12:09 +03:00
|
|
|
// Copyright (c) 2013-2017 The btcsuite developers
|
|
|
|
// Copyright (c) 2015-2016 The Decred developers
|
2016-03-23 04:40:54 +03:00
|
|
|
// Heavily inspired by https://github.com/btcsuite/btcd/blob/master/version.go
|
2017-11-28 03:12:09 +03:00
|
|
|
// Copyright (C) 2015-2017 The Lightning Network Developers
|
|
|
|
|
2018-09-20 13:31:50 +03:00
|
|
|
package build
|
2016-03-23 04:40:54 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2020-04-10 03:04:25 +03:00
|
|
|
var (
|
|
|
|
// Commit stores the current commit of this build, which includes the
|
|
|
|
// most recent tag, the number of commits since that tag (if non-zero),
|
|
|
|
// the commit hash, and a dirty marker. This should be set using the
|
|
|
|
// -ldflags during compilation.
|
|
|
|
Commit string
|
|
|
|
|
|
|
|
// CommitHash stores the current commit hash of this build, this should
|
|
|
|
// be set using the -ldflags during compilation.
|
|
|
|
CommitHash string
|
2020-04-10 03:04:55 +03:00
|
|
|
|
|
|
|
// RawTags contains the raw set of build tags, separated by commas. This
|
|
|
|
// should be set using -ldflags during compilation.
|
|
|
|
RawTags string
|
2020-04-10 03:05:24 +03:00
|
|
|
|
|
|
|
// GoVersion stores the go version that the executable was compiled
|
|
|
|
// with. This hsould be set using -ldflags during compilation.
|
|
|
|
GoVersion string
|
2020-04-10 03:04:25 +03:00
|
|
|
)
|
2018-09-20 13:31:50 +03:00
|
|
|
|
2020-04-10 03:03:27 +03:00
|
|
|
// semanticAlphabet is the set of characters that are permitted for use in an
|
|
|
|
// AppPreRelease.
|
2020-04-15 06:08:36 +03:00
|
|
|
const semanticAlphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-."
|
2016-03-23 04:40:54 +03:00
|
|
|
|
|
|
|
// These constants define the application version and follow the semantic
|
|
|
|
// versioning 2.0.0 spec (http://semver.org/).
|
|
|
|
const (
|
2020-04-10 03:03:57 +03:00
|
|
|
// AppMajor defines the major version of this binary.
|
|
|
|
AppMajor uint = 0
|
2016-03-23 04:40:54 +03:00
|
|
|
|
2020-04-10 03:03:57 +03:00
|
|
|
// AppMinor defines the minor version of this binary.
|
2020-04-15 06:08:36 +03:00
|
|
|
AppMinor uint = 10
|
2020-04-10 03:03:57 +03:00
|
|
|
|
|
|
|
// AppPatch defines the application patch for this binary.
|
|
|
|
AppPatch uint = 0
|
|
|
|
|
|
|
|
// AppPreRelease MUST only contain characters from semanticAlphabet
|
2016-03-23 04:40:54 +03:00
|
|
|
// per the semantic versioning spec.
|
2020-04-22 04:12:46 +03:00
|
|
|
AppPreRelease = "beta.rc4"
|
2016-03-23 04:40:54 +03:00
|
|
|
)
|
|
|
|
|
2020-04-10 03:04:11 +03:00
|
|
|
func init() {
|
|
|
|
// Assert that AppPreRelease is valid according to the semantic
|
|
|
|
// versioning guidelines for pre-release version and build metadata
|
|
|
|
// strings. In particular it MUST only contain characters in
|
|
|
|
// semanticAlphabet.
|
|
|
|
for _, r := range AppPreRelease {
|
|
|
|
if !strings.ContainsRune(semanticAlphabet, r) {
|
|
|
|
panic(fmt.Errorf("rune: %v is not in the semantic "+
|
|
|
|
"alphabet", r))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 13:31:50 +03:00
|
|
|
// Version returns the application version as a properly formed string per the
|
2016-03-23 04:40:54 +03:00
|
|
|
// semantic versioning 2.0.0 spec (http://semver.org/).
|
2018-09-20 13:31:50 +03:00
|
|
|
func Version() string {
|
2016-03-23 04:40:54 +03:00
|
|
|
// Start with the major, minor, and patch versions.
|
2020-04-10 03:03:57 +03:00
|
|
|
version := fmt.Sprintf("%d.%d.%d", AppMajor, AppMinor, AppPatch)
|
2016-03-23 04:40:54 +03:00
|
|
|
|
2020-04-10 03:04:11 +03:00
|
|
|
// Append pre-release version if there is one. The hyphen called for by
|
|
|
|
// the semantic versioning spec is automatically appended and should not
|
|
|
|
// be contained in the pre-release string.
|
|
|
|
if AppPreRelease != "" {
|
|
|
|
version = fmt.Sprintf("%s-%s", version, AppPreRelease)
|
2016-03-23 04:40:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return version
|
|
|
|
}
|
2020-04-10 03:04:55 +03:00
|
|
|
|
|
|
|
// Tags returns the list of build tags that were compiled into the executable.
|
|
|
|
func Tags() []string {
|
|
|
|
if len(RawTags) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return strings.Split(RawTags, ",")
|
|
|
|
}
|