goenv: improve Go version detection
First look at the VERSION file, only then look at src/runtime/internal/sys/zversion.go. This makes it possible to correctly detect the Go version for release candidates.
Этот коммит содержится в:
родитель
931f87f96a
коммит
ad73986070
1 изменённых файлов: 4 добавлений и 4 удалений
|
@ -48,7 +48,10 @@ func GetGorootVersion(goroot string) (major, minor int, err error) {
|
||||||
// toolchain for the given GOROOT path. It is usually of the form `go1.x.y` but
|
// toolchain for the given GOROOT path. It is usually of the form `go1.x.y` but
|
||||||
// can have some variations (for beta releases, for example).
|
// can have some variations (for beta releases, for example).
|
||||||
func GorootVersionString(goroot string) (string, error) {
|
func GorootVersionString(goroot string) (string, error) {
|
||||||
if data, err := ioutil.ReadFile(filepath.Join(
|
if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil {
|
||||||
|
return string(data), nil
|
||||||
|
|
||||||
|
} else if data, err := ioutil.ReadFile(filepath.Join(
|
||||||
goroot, "src", "runtime", "internal", "sys", "zversion.go")); err == nil {
|
goroot, "src", "runtime", "internal", "sys", "zversion.go")); err == nil {
|
||||||
|
|
||||||
r := regexp.MustCompile("const TheVersion = `(.*)`")
|
r := regexp.MustCompile("const TheVersion = `(.*)`")
|
||||||
|
@ -59,9 +62,6 @@ func GorootVersionString(goroot string) (string, error) {
|
||||||
|
|
||||||
return string(matches[1]), nil
|
return string(matches[1]), nil
|
||||||
|
|
||||||
} else if data, err := ioutil.ReadFile(filepath.Join(goroot, "VERSION")); err == nil {
|
|
||||||
return string(data), nil
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче