delve/pkg/goversion/compat.go
Alessandro Arzilli 891a1f080d
goversion,teamcity: update test matrix and fix build scripts (#3463)
Update test matrix to remove 1.18 and add 1.21, fix build scripts to
deal with the new format returned by:
	https://golang.org/VERSION?m=text
which now has an extra second line with the time.
2023-08-11 08:52:35 -07:00

44 lines
1.9 KiB
Go

package goversion
import (
"fmt"
"github.com/go-delve/delve/pkg/logflags"
)
var (
MinSupportedVersionOfGoMajor = 1
MinSupportedVersionOfGoMinor = 19
MaxSupportedVersionOfGoMajor = 1
MaxSupportedVersionOfGoMinor = 21
goTooOldErr = fmt.Sprintf("Go version %%s is too old for this version of Delve (minimum supported version %d.%d, suppress this error with --check-go-version=false)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor)
goTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - Go version %%s is too old for this version of Delve (minimum supported version %d.%d)", MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor)
dlvTooOldErr = fmt.Sprintf("Version of Delve is too old for Go version %%s (maximum supported version %d.%d, suppress this error with --check-go-version=false)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor)
dlvTooOldWarn = fmt.Sprintf("WARNING: undefined behavior - version of Delve is too old for Go version %%s (maximum supported version %d.%d)", MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor)
)
// Compatible checks that the version specified in the producer string is compatible with
// this version of delve.
func Compatible(producer string, warnonly bool) error {
ver := ParseProducer(producer)
if ver.IsDevel() {
return nil
}
verstr := fmt.Sprintf("%d.%d.%d", ver.Major, ver.Minor, ver.Rev)
if !ver.AfterOrEqual(GoVersion{MinSupportedVersionOfGoMajor, MinSupportedVersionOfGoMinor, -1, 0, 0, ""}) {
if warnonly {
logflags.WriteError(fmt.Sprintf(goTooOldWarn, verstr))
return nil
}
return fmt.Errorf(goTooOldErr, verstr)
}
if ver.AfterOrEqual(GoVersion{MaxSupportedVersionOfGoMajor, MaxSupportedVersionOfGoMinor + 1, -1, 0, 0, ""}) {
if warnonly {
logflags.WriteError(fmt.Sprintf(dlvTooOldWarn, verstr))
return nil
}
return fmt.Errorf(dlvTooOldErr, verstr)
}
return nil
}