cmd/dlv: Parse Go+BoringCrypto version (#2712)

This changes allow us to parse Go+BoringCrypto which formatted in <GoVersion>b<BoringCryptoVersion> so that we can surpress `Version of Go is too old for this version of Delve` error.

Fixes #2711
This commit is contained in:
Yang Wei 2021-09-23 13:25:31 +09:00 committed by GitHub
parent 9f8b352a98
commit ff52a37a6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

@ -37,9 +37,14 @@ func Parse(ver string) (GoVersion, bool) {
switch len(v) {
case 2:
r.Major, err1 = strconv.Atoi(v[0])
vr := strings.SplitN(v[1], "beta", 2)
if len(vr) == 2 {
var vr []string
if vr = strings.SplitN(v[1], "beta", 2); len(vr) == 2 {
r.Beta, err3 = strconv.Atoi(vr[1])
} else if vr = strings.SplitN(v[1], "b", 2); len(vr) == 2 {
if _, err := strconv.Atoi(vr[1]); err != nil {
return GoVersion{}, false
}
} else {
vr = strings.SplitN(v[1], "rc", 2)
if len(vr) == 2 {
@ -67,7 +72,14 @@ func Parse(ver string) (GoVersion, bool) {
r.Major, err1 = strconv.Atoi(v[0])
r.Minor, err2 = strconv.Atoi(v[1])
vr := strings.SplitN(v[2], "b", 2)
if len(vr) == 2 {
r.Rev, err3 = strconv.Atoi(vr[0])
} else {
r.Rev, err3 = strconv.Atoi(v[2])
}
r.Proposal = ""
if err1 != nil || err2 != nil || err3 != nil {
return GoVersion{}, false

@ -24,6 +24,8 @@ func TestParseVersionString(t *testing.T) {
versionAfterOrEqual(t, "go1.5rc2", GoVersion{1, 5, -1, 0, 2, ""})
versionAfterOrEqual(t, "go1.6.1 (appengine-1.9.37)", GoVersion{1, 6, 1, 0, 0, ""})
versionAfterOrEqual(t, "go1.8.1.typealias", GoVersion{1, 6, 1, 0, 0, ""})
versionAfterOrEqual(t, "go1.8b1", GoVersion{1, 8, -1, 0, 0, ""})
versionAfterOrEqual(t, "go1.16.4b7", GoVersion{1, 16, 4, 0, 0, ""})
ver, ok := Parse("devel +17efbfc Tue Jul 28 17:39:19 2015 +0000 linux/amd64")
if !ok {
t.Fatalf("Could not parse devel version string")