1// Package moxvar provides the version number of a mox build.
2package moxvar
3
4import (
5 "runtime"
6 "runtime/debug"
7)
8
9// Version is set at runtime based on the Go module used to build.
10var Version string
11
12// VersionBare does not add a "+modifications", goversion or other suffix to the version.
13var VersionBare string
14
15func init() {
16 Version = "(devel)"
17 VersionBare = "(devel)"
18
19 defer func() {
20 Version += "-" + runtime.Version()
21 }()
22
23 buildInfo, ok := debug.ReadBuildInfo()
24 if !ok {
25 return
26 }
27 Version = buildInfo.Main.Version
28 VersionBare = buildInfo.Main.Version
29 if Version == "(devel)" {
30 var vcsRev, vcsMod string
31 for _, setting := range buildInfo.Settings {
32 if setting.Key == "vcs.revision" {
33 vcsRev = setting.Value
34 } else if setting.Key == "vcs.modified" {
35 vcsMod = setting.Value
36 }
37 }
38 if vcsRev == "" {
39 return
40 }
41 Version = vcsRev
42 VersionBare = vcsRev
43 switch vcsMod {
44 case "false":
45 case "true":
46 Version += "+modifications"
47 default:
48 Version += "+unknown"
49 }
50 }
51}
52