@ -260,11 +260,6 @@ type errJustExit int
func ( e errJustExit ) Error ( ) string { return fmt . Sprintf ( "exit: %d" , e ) }
func ( e errJustExit ) Error ( ) string { return fmt . Sprintf ( "exit: %d" , e ) }
// toolchainVersionSemver is a semver-compatible version of the Go toolchain currently
// being used, as reported by "go env GOVERSION".
// Note that the version of Go that built the garble binary might be newer.
var toolchainVersionSemver string
func goVersionOK ( ) bool {
func goVersionOK ( ) bool {
const (
const (
minGoVersionSemver = "v1.20.0"
minGoVersionSemver = "v1.20.0"
@ -275,7 +270,7 @@ func goVersionOK() bool {
rxVersion := regexp . MustCompile ( ` go\d+\.\d+(?:\.\d+)? ` )
rxVersion := regexp . MustCompile ( ` go\d+\.\d+(?:\.\d+)? ` )
toolchainVersionFull := cache . GoEnv . GOVERSION
toolchainVersionFull := cache . GoEnv . GOVERSION
toolchainVersion := rxVersion . FindString ( cache. GoEnv . GOVERSION )
toolchainVersion := rxVersion . FindString ( toolchainVersionFull )
if toolchainVersion == "" {
if toolchainVersion == "" {
// Go 1.15.x and older do not have GOVERSION yet.
// Go 1.15.x and older do not have GOVERSION yet.
// We could go the extra mile and fetch it via 'go toolchainVersion',
// We could go the extra mile and fetch it via 'go toolchainVersion',
@ -284,14 +279,14 @@ func goVersionOK() bool {
return false
return false
}
}
toolchain VersionSemver = "v" + strings . TrimPrefix ( toolchainVersion , "go" )
cache. Go VersionSemver = "v" + strings . TrimPrefix ( toolchainVersion , "go" )
if semver . Compare ( toolchain VersionSemver, minGoVersionSemver ) < 0 {
if semver . Compare ( cache. Go VersionSemver, minGoVersionSemver ) < 0 {
fmt . Fprintf ( os . Stderr , "Go version %q is too old; please upgrade to Go %s or newer\n" , toolchainVersionFull , suggestedGoVersion )
fmt . Fprintf ( os . Stderr , "Go version %q is too old; please upgrade to Go %s or newer\n" , toolchainVersionFull , suggestedGoVersion )
return false
return false
}
}
// Ensure that the version of Go that built the garble binary is equal or
// Ensure that the version of Go that built the garble binary is equal or
// newer than toolchain VersionSemver.
// newer than cache.Go VersionSemver.
builtVersionFull := os . Getenv ( "GARBLE_TEST_GOVERSION" )
builtVersionFull := os . Getenv ( "GARBLE_TEST_GOVERSION" )
if builtVersionFull == "" {
if builtVersionFull == "" {
builtVersionFull = runtime . Version ( )
builtVersionFull = runtime . Version ( )
@ -303,7 +298,7 @@ func goVersionOK() bool {
return true
return true
}
}
builtVersionSemver := "v" + strings . TrimPrefix ( builtVersion , "go" )
builtVersionSemver := "v" + strings . TrimPrefix ( builtVersion , "go" )
if semver . Compare ( builtVersionSemver , toolchain VersionSemver) < 0 {
if semver . Compare ( builtVersionSemver , cache. Go VersionSemver) < 0 {
fmt . Fprintf ( os . Stderr , "garble was built with %q and is being used with %q; please rebuild garble with the newer version\n" ,
fmt . Fprintf ( os . Stderr , "garble was built with %q and is being used with %q; please rebuild garble with the newer version\n" ,
builtVersionFull , toolchainVersionFull )
builtVersionFull , toolchainVersionFull )
return false
return false