@@ -10,6 +10,7 @@ import (
10
10
"os/exec"
11
11
"os/user"
12
12
"path/filepath"
13
+ "regexp"
13
14
"runtime"
14
15
"strconv"
15
16
"strings"
@@ -384,14 +385,30 @@ func isGoroot(goroot string) bool {
384
385
// getGorootVersion returns the major and minor version for a given GOROOT path.
385
386
// If the goroot cannot be determined, (0, 0) is returned.
386
387
func getGorootVersion (goroot string ) (major , minor int , err error ) {
387
- data , err := ioutil .ReadFile (filepath .Join (goroot , "VERSION" ))
388
- if err != nil {
388
+ var s string
389
+
390
+ if data , err := ioutil .ReadFile (filepath .Join (
391
+ goroot , "src" , "runtime" , "internal" , "sys" , "zversion.go" )); err == nil {
392
+
393
+ r := regexp .MustCompile ("const TheVersion = `(.*)`" )
394
+ matches := r .FindSubmatch (data )
395
+ if len (matches ) != 2 {
396
+ return 0 , 0 , errors .New ("Invalid go version output:\n " + string (data ))
397
+ }
398
+
399
+ s = string (matches [1 ])
400
+
401
+ } else if data , err := ioutil .ReadFile (filepath .Join (goroot , "VERSION" )); err == nil {
402
+ s = string (data )
403
+
404
+ } else {
389
405
return 0 , 0 , err
390
406
}
391
- s := string ( data )
392
- if s [:2 ] != "go" {
407
+
408
+ if s == "" || s [:2 ] != "go" {
393
409
return 0 , 0 , errors .New ("could not parse Go version: version does not start with 'go' prefix" )
394
410
}
411
+
395
412
parts := strings .Split (s [2 :], "." )
396
413
if len (parts ) < 2 {
397
414
return 0 , 0 , errors .New ("could not parse Go version: version has less than two parts" )
0 commit comments