main: use zversion.go and VERSION files to detect version, fixes #433
Этот коммит содержится в:
родитель
6611578ec8
коммит
aabb6ba22b
1 изменённых файлов: 21 добавлений и 4 удалений
25
target.go
25
target.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -384,14 +385,30 @@ func isGoroot(goroot string) bool {
|
||||||
// getGorootVersion returns the major and minor version for a given GOROOT path.
|
// getGorootVersion returns the major and minor version for a given GOROOT path.
|
||||||
// If the goroot cannot be determined, (0, 0) is returned.
|
// If the goroot cannot be determined, (0, 0) is returned.
|
||||||
func getGorootVersion(goroot string) (major, minor int, err error) {
|
func getGorootVersion(goroot string) (major, minor int, err error) {
|
||||||
data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION"))
|
var s string
|
||||||
if err != nil {
|
|
||||||
|
if data, err := ioutil.ReadFile(filepath.Join(
|
||||||
|
goroot, "src", "runtime", "internal", "sys", "zversion.go")); err == nil {
|
||||||
|
|
||||||
|
r := regexp.MustCompile("const TheVersion = `(.*)`")
|
||||||
|
matches := r.FindSubmatch(data)
|
||||||
|
if len(matches) != 2 {
|
||||||
|
return 0, 0, errors.New("Invalid go version output:\n" + string(data))
|
||||||
|
}
|
||||||
|
|
||||||
|
s = string(matches[1])
|
||||||
|
|
||||||
|
} else if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil {
|
||||||
|
s = string(data)
|
||||||
|
|
||||||
|
} else {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
s := string(data)
|
|
||||||
if s[:2] != "go" {
|
if s == "" || s[:2] != "go" {
|
||||||
return 0, 0, errors.New("could not parse Go version: version does not start with 'go' prefix")
|
return 0, 0, errors.New("could not parse Go version: version does not start with 'go' prefix")
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(s[2:], ".")
|
parts := strings.Split(s[2:], ".")
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
return 0, 0, errors.New("could not parse Go version: version has less than two parts")
|
return 0, 0, errors.New("could not parse Go version: version has less than two parts")
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче