提交 d9d3118a 编写于 作者: D Derek Parker

Fix: Parse rc version strings

上级 ed9b7769
......@@ -37,7 +37,7 @@ func (a *AMD64) SetGStructOffset(ver GoVersion, isextld bool) {
a.gStructOffset = 0x8a0
case "linux":
a.gStructOffset = 0xfffffffffffffff0
if isextld || ver.AfterOrEqual(GoVersion{1, 5, -1, 2}) || ver.IsDevel() {
if isextld || ver.AfterOrEqual(GoVersion{1, 5, -1, 2, 0}) || ver.IsDevel() {
a.gStructOffset += 8
}
}
......
......@@ -10,6 +10,7 @@ type GoVersion struct {
Minor int
Rev int
Beta int
RC int
}
func parseVersionString(ver string) (GoVersion, bool) {
......@@ -17,7 +18,7 @@ func parseVersionString(ver string) (GoVersion, bool) {
var err1, err2, err3 error
if strings.HasPrefix(ver, "devel") {
return GoVersion{-1, 0, 0, 0}, true
return GoVersion{-1, 0, 0, 0, 0}, true
}
if strings.HasPrefix(ver, "go") {
......@@ -25,14 +26,21 @@ func parseVersionString(ver string) (GoVersion, bool) {
switch len(v) {
case 2:
r.Major, err1 = strconv.Atoi(v[0])
v = strings.SplitN(v[1], "beta", 2)
if len(v) != 2 {
vr := strings.SplitN(v[1], "beta", 2)
if len(vr) == 2 {
r.Beta, err3 = strconv.Atoi(vr[1])
} else {
vr = strings.SplitN(v[1], "rc", 2)
if len(vr) == 2 {
r.RC, err3 = strconv.Atoi(vr[1])
}
}
if len(vr) < 2 {
return GoVersion{}, false
}
r.Minor, err2 = strconv.Atoi(v[0])
r.Minor, err2 = strconv.Atoi(vr[0])
r.Rev = -1
r.Beta, err3 = strconv.Atoi(v[1])
if err1 != nil || err2 != nil || err3 != nil {
return GoVersion{}, false
......@@ -82,6 +90,10 @@ func (a *GoVersion) AfterOrEqual(b GoVersion) bool {
return false
}
if a.RC < b.RC {
return false
}
return true
}
......
......@@ -668,9 +668,10 @@ func versionAfterOrEqual(t *testing.T, verStr string, ver GoVersion) {
}
func TestParseVersionString(t *testing.T) {
versionAfterOrEqual(t, "go1.5.0", GoVersion{1, 5, 0, 0})
versionAfterOrEqual(t, "go1.4.2", GoVersion{1, 4, 2, 0})
versionAfterOrEqual(t, "go1.5beta2", GoVersion{1, 5, -1, 2})
versionAfterOrEqual(t, "go1.5.0", GoVersion{1, 5, 0, 0, 0})
versionAfterOrEqual(t, "go1.4.2", GoVersion{1, 4, 2, 0, 0})
versionAfterOrEqual(t, "go1.5beta2", GoVersion{1, 5, -1, 2, 0})
versionAfterOrEqual(t, "go1.5rc2", GoVersion{1, 5, -1, 0, 2})
ver, ok := parseVersionString("devel +17efbfc Tue Jul 28 17:39:19 2015 +0000 linux/amd64")
if !ok {
t.Fatalf("Could not parse devel version string")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册