-
Notifications
You must be signed in to change notification settings - Fork 19
/
version.go
60 lines (55 loc) · 1.8 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package core
import (
"errors"
"fmt"
"os"
)
const VERSION = "1.0.52"
const REVISION = "a6f0088f2e43fe837c905792459dfca4e1022a0b+1"
const NUMBER = 324
// these fields will be filled by compiler, see CORE_VERSION in cmd/xgo/version.go
const XGO_VERSION = ""
const XGO_REVISION = ""
const XGO_NUMBER = 0
const XGO_CHECK_TOOLCHAIN_VERSION = "XGO_CHECK_TOOLCHAIN_VERSION"
func init() {
envVal := os.Getenv(XGO_CHECK_TOOLCHAIN_VERSION)
if envVal == "false" || envVal == "off" {
return
}
err := checkVersion()
if err != nil {
fmt.Fprintf(os.Stderr, "WARNING: xgo toolchain: %v\nnote: this message can be turned off by setting %s=false\n", err, XGO_CHECK_TOOLCHAIN_VERSION)
}
}
func checkVersion() error {
// xgoVersion, xgoRevision, xgoNumber := XGO_VERSION, XGO_REVISION, XGO_NUMBER
// _, _, _ = xgoVersion, xgoRevision, xgoNumber
if XGO_VERSION == "" {
return errors.New("failed to detect xgo version, consider install xgo: go install github.com/xhd2015/xgo/cmd/xgo@latest")
}
if XGO_VERSION == VERSION {
// if xgo version same with runtime version, then
// different numbers are compatible with each other,
// e.g. xgo v1.0.29 <-> runtime v1.0.29
// [ok] xgo 205, runtime 205
// [ok] xgo 205, runtime 206
// [ok] xgo 205, runtime 204
return nil
}
if XGO_NUMBER == NUMBER {
// good to go
return nil
}
var msg string
if XGO_NUMBER < NUMBER {
// incompatible possibly: xgo < runtime
updateCmd := "xgo upgrade"
msg = fmt.Sprintf("xgo v%s maybe incompatible with xgo/runtime v%s, consider run: %s", XGO_VERSION, VERSION, updateCmd)
} else {
// compatible: xgo >= runtime
updateCmd := "go get github.com/xhd2015/xgo/runtime@latest"
msg = fmt.Sprintf("xgo/runtime v%s can be upgraded to v%s, consider run: %s", VERSION, XGO_VERSION, updateCmd)
}
return errors.New(msg)
}