Last change
on this file since 814 was 809, checked in by koizumi.aoi, 2 years ago |
Use internal versioning
Signed-off-by: Aoi K <koizumi.aoi@…>
|
File size:
1.2 KB
|
Rev | Line | |
---|
[809] | 1 | package suika
|
---|
| 2 |
|
---|
| 3 | import (
|
---|
| 4 | "fmt"
|
---|
| 5 | "runtime/debug"
|
---|
| 6 | "strings"
|
---|
| 7 | )
|
---|
| 8 |
|
---|
| 9 | const (
|
---|
| 10 | defaultVersion = "0.0.0"
|
---|
| 11 | defaultCommit = "HEAD"
|
---|
| 12 | defaultBuild = "0000-01-01:00:00+00:00"
|
---|
| 13 | )
|
---|
| 14 |
|
---|
| 15 | var (
|
---|
| 16 | // Version is the tagged release version in the form <major>.<minor>.<patch>
|
---|
| 17 | // following semantic versioning and is overwritten by the build system.
|
---|
| 18 | Version = defaultVersion
|
---|
| 19 |
|
---|
| 20 | // Commit is the commit sha of the build (normally from Git) and is overwritten
|
---|
| 21 | // by the build system.
|
---|
| 22 | Commit = defaultCommit
|
---|
| 23 |
|
---|
| 24 | // Build is the date and time of the build as an RFC3339 formatted string
|
---|
| 25 | // and is overwritten by the build system.
|
---|
| 26 | Build = defaultBuild
|
---|
| 27 | )
|
---|
| 28 |
|
---|
| 29 | // FullVersion display the full version and build
|
---|
| 30 | func FullVersion() string {
|
---|
| 31 | var sb strings.Builder
|
---|
| 32 |
|
---|
| 33 | isDefault := Version == defaultVersion && Commit == defaultCommit && Build == defaultBuild
|
---|
| 34 |
|
---|
| 35 | if !isDefault {
|
---|
| 36 | sb.WriteString(fmt.Sprintf("%s@%s %s", Version, Commit, Build))
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | if info, ok := debug.ReadBuildInfo(); ok {
|
---|
| 40 | if isDefault {
|
---|
| 41 | sb.WriteString(fmt.Sprintf(" %s", info.Main.Version))
|
---|
| 42 | }
|
---|
| 43 | sb.WriteString(fmt.Sprintf(" %s", info.GoVersion))
|
---|
| 44 | if info.Main.Sum != "" {
|
---|
| 45 | sb.WriteString(fmt.Sprintf(" %s", info.Main.Sum))
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | return sb.String()
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.