Skip to content

Commit

Permalink
cmd/release: start using FreeBSD 11.2 builders for Go 1.15 RC 2+
Browse files Browse the repository at this point in the history
Add the ability to have builds apply only to select Go versions
according to a module-query-like but fictional syntax. We don't
need to support all arbitrary queries right away, so start with
a smaller set of queries, and let this inform future work.

Fixes golang/go#40563.
Updates golang/go#40558.

Change-Id: I8f7afa90bfe1f91190cee34af51c012216bba455
Reviewed-on: https://go-review.googlesource.com/c/build/+/246597
Run-TryBot: Dmitri Shuralyov <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Andrew Bonventre <[email protected]>
Reviewed-by: Alexander Rakoczy <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
  • Loading branch information
dmitshur committed Aug 4, 2020
1 parent cb64255 commit 56b7eea
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 4 deletions.
53 changes: 49 additions & 4 deletions cmd/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func main() {
if *target != "" && b.String() != *target {
continue
}
if !match(b.GoQuery, *version) {
continue
}
matches++
b.logf("Start.")
wg.Add(1)
Expand All @@ -103,6 +106,10 @@ func main() {
}

type Build struct {
// GoQuery is a Go version query specifying the Go versions
// the build applies to. Empty string means all Go versions.
GoQuery string

OS, Arch string
Source bool

Expand Down Expand Up @@ -169,15 +176,17 @@ var builds = []*Build{
Builder: "linux-arm64-packet",
},
{
GoQuery: ">= go1.15rc2", // See #40563.
OS: "freebsd",
Arch: "386",
Builder: "freebsd-386-11_1",
Builder: "freebsd-386-11_2",
},
{
GoQuery: ">= go1.15rc2", // See #40563.
OS: "freebsd",
Arch: "amd64",
Race: true,
Builder: "freebsd-amd64-11_1",
Builder: "freebsd-amd64-11_2",
},
{
OS: "windows",
Expand Down Expand Up @@ -213,6 +222,21 @@ var builds = []*Build{
Builder: "linux-ppc64le-buildlet",
},

// Older builds.
{
GoQuery: "< go1.15",
OS: "freebsd",
Arch: "386",
Builder: "freebsd-386-11_1",
},
{
GoQuery: "< go1.15",
OS: "freebsd",
Arch: "amd64",
Race: true,
Builder: "freebsd-amd64-11_1",
},

// Test-only builds.
{
Builder: "linux-amd64-longtest",
Expand Down Expand Up @@ -933,16 +957,37 @@ func setGOARCH(env []string, goarch string) []string {
// minSupportedMacOSVersion provides the minimum supported macOS
// version (of the form N.M) for supported Go versions.
func minSupportedMacOSVersion(goVer string) string {
// TODO(amedee): Use a version package to compare versions of Go.
// TODO(amedee,dmitshur,golang.org/issue/40558): Use a version package to compare versions of Go.

// The minimum supported version of macOS with each version of go:
// go1.13 - macOS 10.11
// go1.14 - macOS 10.11
// go1.15 - macOS 10.12
minMacVersion := "10.12"
if strings.HasPrefix(goVer, "go1.13") || strings.HasPrefix(goVer, "go1.14") {
if match("< go1.15", goVer) {
minMacVersion = "10.11"
return minMacVersion
}
return minMacVersion
}

// match reports whether the Go version goVer matches the provided version query.
// The empty query matches all Go versions.
// match panics if given a query that it doesn't support.
func match(query, goVer string) bool {
// TODO(golang.org/issue/40558): This should help inform the API for a Go version parser.
switch query {
case "": // A special case to make the zero Build.GoQuery value useful.
return true
case ">= go1.15rc2":
// By the time this code is added, Go 1.15 RC 1 has already been released and
// won't be modified, that's why we only care about matching RC 2 and onwards.
// (We could've just done ">= go1.15", but that could be misleading in future.)
return goVer != "go1.15rc1" && !strings.HasPrefix(goVer, "go1.15beta") &&
!strings.HasPrefix(goVer, "go1.14") && !strings.HasPrefix(goVer, "go1.13")
case "< go1.15":
return strings.HasPrefix(goVer, "go1.14") || strings.HasPrefix(goVer, "go1.13")
default:
panic(fmt.Errorf("match: query %q is not supported", query))
}
}
61 changes: 61 additions & 0 deletions cmd/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ func TestBuildersExist(t *testing.T) {
}
}

func TestAllQueriesSupported(t *testing.T) {
for _, b := range builds {
t.Run(b.String(), func(t *testing.T) {
defer func() {
if err := recover(); err != nil {
t.Errorf("build %v uses an unsupported version query:\n%v", b, err)
}
}()
match(b.GoQuery, "go1.14.6") // Shouldn't panic for any b.GoQuery.
})
}
}

func TestTestOnlyBuildsDontSkipTests(t *testing.T) {
for _, b := range builds {
if b.TestOnly && b.SkipTests {
Expand Down Expand Up @@ -49,3 +62,51 @@ func TestMinSupportedMacOSVersion(t *testing.T) {
})
}
}

func TestFreeBSDBuilder(t *testing.T) {
matchBuilds := func(target, goVer string) (matched []*Build) {
for _, b := range builds {
if b.String() != target || !match(b.GoQuery, goVer) {
continue
}
matched = append(matched, b)
}
return matched
}

testCases := []struct {
goVer string
target string
wantBuilder string
}{
// Go 1.14.x and 1.13.x still use the FreeBSD 11.1 builder.
{"go1.13.55", "freebsd-amd64", "freebsd-amd64-11_1"},
{"go1.13.55", "freebsd-386", "freebsd-386-11_1"},
{"go1.14.55", "freebsd-amd64", "freebsd-amd64-11_1"},
{"go1.14.55", "freebsd-386", "freebsd-386-11_1"},

// Go 1.15 RC 2+ starts to use the the FreeBSD 11.2 builder.
{"go1.15rc2", "freebsd-amd64", "freebsd-amd64-11_2"},
{"go1.15rc2", "freebsd-386", "freebsd-386-11_2"},
{"go1.15", "freebsd-amd64", "freebsd-amd64-11_2"},
{"go1.15", "freebsd-386", "freebsd-386-11_2"},
{"go1.15.1", "freebsd-amd64", "freebsd-amd64-11_2"},
{"go1.15.1", "freebsd-386", "freebsd-386-11_2"},

// May change further during the 1.16 dev cycle,
// but expect same builder as 1.15 for now.
{"go1.16", "freebsd-amd64", "freebsd-amd64-11_2"},
{"go1.16", "freebsd-386", "freebsd-386-11_2"},
}
for _, tc := range testCases {
t.Run(tc.goVer, func(t *testing.T) {
builds := matchBuilds(tc.target, tc.goVer)
if len(builds) != 1 {
t.Fatalf("got %d matching builds; want 1", len(builds))
}
if got, want := builds[0].Builder, tc.wantBuilder; got != want {
t.Errorf("got %s; want %s", got, want)
}
})
}
}

0 comments on commit 56b7eea

Please sign in to comment.