Skip to content

Commit

Permalink
cmd/rebuild, internal/task: delete copies of go/version code
Browse files Browse the repository at this point in the history
We can use go/version directly from the standard library now that it
exists there, and because Go 1.22 or newer is always used in x/build.

Change-Id: I5fc65eefa552c9b457691fe0cea6a1cffc2ac871
Reviewed-on: https://go-review.googlesource.com/c/build/+/611976
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
  • Loading branch information
dmitshur authored and gopherbot committed Sep 10, 2024
1 parent 46dec96 commit 4fcdaed
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 355 deletions.
20 changes: 12 additions & 8 deletions cmd/gorebuild/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"fmt"
goversion "go/version"
"os"
"os/exec"
"path/filepath"
Expand All @@ -17,24 +18,27 @@ import (
// for the named version of Go. If the version needs no bootstrap
// (that is, if it's before Go 1.5), BootstrapVersion returns an empty version.
func BootstrapVersion(version string) (string, error) {
if Compare(version, Go(1, 5)) < 0 {
// go1 returns the version string for Go 1.N ("go1.N").
go1 := func(N int) string { return fmt.Sprintf("go1.%d", N) }

if goversion.Compare(version, go1(5)) < 0 {
return "", nil
}
if Compare(version, Go(1, 20)) < 0 {
return Go(1, 4), nil
if goversion.Compare(version, go1(20)) < 0 {
return go1(4), nil
}
if Compare(version, Go(1, 22)) < 0 {
return Go(1, 17), nil
if goversion.Compare(version, go1(22)) < 0 {
return go1(17), nil
}
if Compare(version, Go(1, 1000)) > 0 {
if goversion.Compare(version, go1(1000)) > 0 {
return "", fmt.Errorf("invalid version %q", version)
}
for i := 24; ; i += 2 {
if Compare(version, Go(1, i)) < 0 {
if goversion.Compare(version, go1(i)) < 0 {
// 1.24 will switch to 1.22; before that we used 1.20
// 1.26 will switch to 1.24; before that we used 1.22
// ...
return Go(1, i-4), nil
return go1(i - 4), nil
}
}
}
Expand Down
174 changes: 0 additions & 174 deletions cmd/gorebuild/gover.go

This file was deleted.

3 changes: 2 additions & 1 deletion cmd/gorebuild/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package main
import (
"bytes"
"fmt"
goversion "go/version"
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -243,7 +244,7 @@ func Run(args []string) *Report {
if r.Log.Status != FAIL {
r.Log.Status = PASS
}
sort.Slice(r.Releases, func(i, j int) bool { return Compare(r.Releases[i].Version, r.Releases[j].Version) > 0 })
sort.Slice(r.Releases, func(i, j int) bool { return goversion.Compare(r.Releases[i].Version, r.Releases[j].Version) > 0 })
for _, rel := range r.Releases {
if rel.Log.Status != FAIL {
rel.Log.Status = PASS
Expand Down
3 changes: 2 additions & 1 deletion internal/relui/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encoding/json"
"errors"
"fmt"
goversion "go/version"
"io"
"io/fs"
"net/http"
Expand Down Expand Up @@ -1644,7 +1645,7 @@ func (tasks *BuildReleaseTasks) publishArtifacts(ctx *wf.TaskContext, version st
if a.Target.GOOS == "linux" && a.Target.GOARCH == "arm" && slices.Contains(a.Target.ExtraEnv, "GOARM=6") {
f.Arch = "armv6l"
}
if task.CompareGoVersions(version, "go1.23") == -1 { // TODO: Delete this after Go 1.24.0 is out and this becomes dead code.
if goversion.Compare(version, "go1.23") == -1 { // TODO: Delete this after Go 1.24.0 is out and this becomes dead code.
// Due to an oversight, we've been inadvertently setting the "arch" field
// of published download metadata to "armv6l" for all arm ports, not just
// linux/arm port as intended. Keep doing it for the rest of Go 1.22/1.21
Expand Down
3 changes: 2 additions & 1 deletion internal/task/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"embed"
"errors"
"fmt"
goversion "go/version"
"io"
"mime"
"net/http"
Expand Down Expand Up @@ -456,7 +457,7 @@ var announceTmpl = template.Must(template.New("").Funcs(template.FuncMap{
},
// atLeast reports whether v1 >= v2.
"atLeast": func(v1, v2 string) bool {
return CompareGoVersions(v1, v2) >= 0
return goversion.Compare(v1, v2) >= 0
},
// build extracts the pre-release build number of a valid Go version.
// For example, build("go1.19beta2") == "2".
Expand Down
Loading

0 comments on commit 4fcdaed

Please sign in to comment.