Skip to content

Commit 56b7eea

Browse files
committed
cmd/release: start using FreeBSD 11.2 builders for Go 1.15 RC 2+
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]>
1 parent cb64255 commit 56b7eea

File tree

2 files changed

+110
-4
lines changed

2 files changed

+110
-4
lines changed

cmd/release/release.go

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func main() {
8484
if *target != "" && b.String() != *target {
8585
continue
8686
}
87+
if !match(b.GoQuery, *version) {
88+
continue
89+
}
8790
matches++
8891
b.logf("Start.")
8992
wg.Add(1)
@@ -103,6 +106,10 @@ func main() {
103106
}
104107

105108
type Build struct {
109+
// GoQuery is a Go version query specifying the Go versions
110+
// the build applies to. Empty string means all Go versions.
111+
GoQuery string
112+
106113
OS, Arch string
107114
Source bool
108115

@@ -169,15 +176,17 @@ var builds = []*Build{
169176
Builder: "linux-arm64-packet",
170177
},
171178
{
179+
GoQuery: ">= go1.15rc2", // See #40563.
172180
OS: "freebsd",
173181
Arch: "386",
174-
Builder: "freebsd-386-11_1",
182+
Builder: "freebsd-386-11_2",
175183
},
176184
{
185+
GoQuery: ">= go1.15rc2", // See #40563.
177186
OS: "freebsd",
178187
Arch: "amd64",
179188
Race: true,
180-
Builder: "freebsd-amd64-11_1",
189+
Builder: "freebsd-amd64-11_2",
181190
},
182191
{
183192
OS: "windows",
@@ -213,6 +222,21 @@ var builds = []*Build{
213222
Builder: "linux-ppc64le-buildlet",
214223
},
215224

225+
// Older builds.
226+
{
227+
GoQuery: "< go1.15",
228+
OS: "freebsd",
229+
Arch: "386",
230+
Builder: "freebsd-386-11_1",
231+
},
232+
{
233+
GoQuery: "< go1.15",
234+
OS: "freebsd",
235+
Arch: "amd64",
236+
Race: true,
237+
Builder: "freebsd-amd64-11_1",
238+
},
239+
216240
// Test-only builds.
217241
{
218242
Builder: "linux-amd64-longtest",
@@ -933,16 +957,37 @@ func setGOARCH(env []string, goarch string) []string {
933957
// minSupportedMacOSVersion provides the minimum supported macOS
934958
// version (of the form N.M) for supported Go versions.
935959
func minSupportedMacOSVersion(goVer string) string {
936-
// TODO(amedee): Use a version package to compare versions of Go.
960+
// TODO(amedee,dmitshur,golang.org/issue/40558): Use a version package to compare versions of Go.
937961

938962
// The minimum supported version of macOS with each version of go:
939963
// go1.13 - macOS 10.11
940964
// go1.14 - macOS 10.11
941965
// go1.15 - macOS 10.12
942966
minMacVersion := "10.12"
943-
if strings.HasPrefix(goVer, "go1.13") || strings.HasPrefix(goVer, "go1.14") {
967+
if match("< go1.15", goVer) {
944968
minMacVersion = "10.11"
945969
return minMacVersion
946970
}
947971
return minMacVersion
948972
}
973+
974+
// match reports whether the Go version goVer matches the provided version query.
975+
// The empty query matches all Go versions.
976+
// match panics if given a query that it doesn't support.
977+
func match(query, goVer string) bool {
978+
// TODO(golang.org/issue/40558): This should help inform the API for a Go version parser.
979+
switch query {
980+
case "": // A special case to make the zero Build.GoQuery value useful.
981+
return true
982+
case ">= go1.15rc2":
983+
// By the time this code is added, Go 1.15 RC 1 has already been released and
984+
// won't be modified, that's why we only care about matching RC 2 and onwards.
985+
// (We could've just done ">= go1.15", but that could be misleading in future.)
986+
return goVer != "go1.15rc1" && !strings.HasPrefix(goVer, "go1.15beta") &&
987+
!strings.HasPrefix(goVer, "go1.14") && !strings.HasPrefix(goVer, "go1.13")
988+
case "< go1.15":
989+
return strings.HasPrefix(goVer, "go1.14") || strings.HasPrefix(goVer, "go1.13")
990+
default:
991+
panic(fmt.Errorf("match: query %q is not supported", query))
992+
}
993+
}

cmd/release/release_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ func TestBuildersExist(t *testing.T) {
1919
}
2020
}
2121

22+
func TestAllQueriesSupported(t *testing.T) {
23+
for _, b := range builds {
24+
t.Run(b.String(), func(t *testing.T) {
25+
defer func() {
26+
if err := recover(); err != nil {
27+
t.Errorf("build %v uses an unsupported version query:\n%v", b, err)
28+
}
29+
}()
30+
match(b.GoQuery, "go1.14.6") // Shouldn't panic for any b.GoQuery.
31+
})
32+
}
33+
}
34+
2235
func TestTestOnlyBuildsDontSkipTests(t *testing.T) {
2336
for _, b := range builds {
2437
if b.TestOnly && b.SkipTests {
@@ -49,3 +62,51 @@ func TestMinSupportedMacOSVersion(t *testing.T) {
4962
})
5063
}
5164
}
65+
66+
func TestFreeBSDBuilder(t *testing.T) {
67+
matchBuilds := func(target, goVer string) (matched []*Build) {
68+
for _, b := range builds {
69+
if b.String() != target || !match(b.GoQuery, goVer) {
70+
continue
71+
}
72+
matched = append(matched, b)
73+
}
74+
return matched
75+
}
76+
77+
testCases := []struct {
78+
goVer string
79+
target string
80+
wantBuilder string
81+
}{
82+
// Go 1.14.x and 1.13.x still use the FreeBSD 11.1 builder.
83+
{"go1.13.55", "freebsd-amd64", "freebsd-amd64-11_1"},
84+
{"go1.13.55", "freebsd-386", "freebsd-386-11_1"},
85+
{"go1.14.55", "freebsd-amd64", "freebsd-amd64-11_1"},
86+
{"go1.14.55", "freebsd-386", "freebsd-386-11_1"},
87+
88+
// Go 1.15 RC 2+ starts to use the the FreeBSD 11.2 builder.
89+
{"go1.15rc2", "freebsd-amd64", "freebsd-amd64-11_2"},
90+
{"go1.15rc2", "freebsd-386", "freebsd-386-11_2"},
91+
{"go1.15", "freebsd-amd64", "freebsd-amd64-11_2"},
92+
{"go1.15", "freebsd-386", "freebsd-386-11_2"},
93+
{"go1.15.1", "freebsd-amd64", "freebsd-amd64-11_2"},
94+
{"go1.15.1", "freebsd-386", "freebsd-386-11_2"},
95+
96+
// May change further during the 1.16 dev cycle,
97+
// but expect same builder as 1.15 for now.
98+
{"go1.16", "freebsd-amd64", "freebsd-amd64-11_2"},
99+
{"go1.16", "freebsd-386", "freebsd-386-11_2"},
100+
}
101+
for _, tc := range testCases {
102+
t.Run(tc.goVer, func(t *testing.T) {
103+
builds := matchBuilds(tc.target, tc.goVer)
104+
if len(builds) != 1 {
105+
t.Fatalf("got %d matching builds; want 1", len(builds))
106+
}
107+
if got, want := builds[0].Builder, tc.wantBuilder; got != want {
108+
t.Errorf("got %s; want %s", got, want)
109+
}
110+
})
111+
}
112+
}

0 commit comments

Comments
 (0)