File tree Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Expand file tree Collapse file tree 1 file changed +29
-1
lines changed Original file line number Diff line number Diff line change 8
8
"runtime/debug"
9
9
"strings"
10
10
"sync"
11
+ "time"
12
+
13
+ "golang.org/x/mod/module"
11
14
)
12
15
13
16
// LanguageVersion returns the CUE language version.
@@ -40,7 +43,32 @@ var moduleVersionOnce = sync.OnceValue(func() string {
40
43
// module name; it also happens when running the cue tests.
41
44
return "(no-cue-module)"
42
45
}
43
- return cueMod .Version
46
+ version := cueMod .Version
47
+ if version != "(devel)" {
48
+ return version
49
+ }
50
+ // A specific version was not provided by the buildInfo
51
+ // so attempt to make our own.
52
+ var vcsTime time.Time
53
+ var vcsRevision string
54
+ for _ , s := range bi .Settings {
55
+ switch s .Key {
56
+ case "vcs.time" :
57
+ // If the format is invalid, we'll print a zero timestamp.
58
+ vcsTime , _ = time .Parse (time .RFC3339Nano , s .Value )
59
+ case "vcs.revision" :
60
+ vcsRevision = s .Value
61
+ // module.PseudoVersion recommends the revision to be a 12-byte
62
+ // commit hash prefix, which is what cmd/go uses as well.
63
+ if len (vcsRevision ) > 12 {
64
+ vcsRevision = vcsRevision [:12 ]
65
+ }
66
+ }
67
+ }
68
+ if vcsRevision != "" {
69
+ version = module .PseudoVersion ("" , "" , vcsTime , vcsRevision )
70
+ }
71
+ return version
44
72
})
45
73
46
74
func findCUEModule (bi * debug.BuildInfo ) * debug.Module {
You can’t perform that action at this time.
0 commit comments