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