Skip to content

Commit 55a33d8

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/dist, internal/platform: test agreement on supported build modes
This synchronizes the supported build modes between cmd/dist and internal/platform, and adds a test to keep them in synch. In order to do that, this has several changes to cmd/dist, and one change to internal/platform. If the build dashboard is green after this is submitted, we can probably make the functions identical. Change-Id: Ia78ce76b193399058fde79e38dd9f23818e566a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/463992 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 4bca2b9 commit 55a33d8

File tree

2 files changed

+62
-17
lines changed

2 files changed

+62
-17
lines changed

src/cmd/dist/supported_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2023 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"internal/platform"
9+
"testing"
10+
)
11+
12+
// TestSupportedBuildModes tests that dist and the main tools agree on
13+
// which build modes are supported for a given target. We do things
14+
// this way because the dist tool needs to be buildable directly by
15+
// the bootstrap compiler, and as such can't import internal packages.
16+
func TestSupported(t *testing.T) {
17+
defer func(a, o string) {
18+
goarch = a
19+
goos = o
20+
}(goarch, goos)
21+
22+
var modes = []string{
23+
// we assume that "exe" and "archive" always work
24+
"pie",
25+
"c-archive",
26+
"c-shared",
27+
"shared",
28+
"plugin",
29+
}
30+
31+
for _, a := range okgoarch {
32+
goarch = a
33+
for _, o := range okgoos {
34+
if _, ok := cgoEnabled[o+"/"+a]; !ok {
35+
continue
36+
}
37+
goos = o
38+
for _, mode := range modes {
39+
var dt tester
40+
dist := dt.supportedBuildmode(mode)
41+
std := platform.BuildModeSupported("gc", mode, o, a)
42+
if dist != std {
43+
t.Errorf("discrepancy for %s-%s %s: dist says %t, standard library says %t", o, a, mode, dist, std)
44+
}
45+
}
46+
}
47+
}
48+
}

src/cmd/dist/test.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,21 +1086,14 @@ func (t *tester) out(v string) {
10861086
fmt.Println("\n" + t.banner + v)
10871087
}
10881088

1089+
// extLink reports whether the current goos/goarch supports
1090+
// external linking. This should match the test in determineLinkMode
1091+
// in cmd/link/internal/ld/config.go.
10891092
func (t *tester) extLink() bool {
1090-
pair := goos + "-" + goarch
1091-
switch pair {
1092-
case "aix-ppc64",
1093-
"android-arm", "android-arm64",
1094-
"darwin-amd64", "darwin-arm64",
1095-
"dragonfly-amd64",
1096-
"freebsd-386", "freebsd-amd64", "freebsd-arm", "freebsd-riscv64",
1097-
"linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-loong64", "linux-ppc64le", "linux-mips64", "linux-mips64le", "linux-mips", "linux-mipsle", "linux-riscv64", "linux-s390x",
1098-
"netbsd-386", "netbsd-amd64",
1099-
"openbsd-386", "openbsd-amd64",
1100-
"windows-386", "windows-amd64":
1101-
return true
1093+
if goarch == "ppc64" && goos != "aix" {
1094+
return false
11021095
}
1103-
return false
1096+
return true
11041097
}
11051098

11061099
func (t *tester) internalLink() bool {
@@ -1174,7 +1167,7 @@ func (t *tester) supportedBuildmode(mode string) bool {
11741167
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
11751168
"darwin-amd64", "darwin-arm64",
11761169
"freebsd-amd64",
1177-
"android-arm", "android-arm64", "android-386",
1170+
"android-arm", "android-arm64", "android-386", "android-amd64",
11781171
"windows-amd64", "windows-386", "windows-arm64":
11791172
return true
11801173
}
@@ -1189,6 +1182,8 @@ func (t *tester) supportedBuildmode(mode string) bool {
11891182
switch pair {
11901183
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-s390x", "linux-ppc64le":
11911184
return true
1185+
case "android-386", "android-amd64", "android-arm", "android-arm64":
1186+
return true
11921187
case "darwin-amd64", "darwin-arm64":
11931188
return true
11941189
case "freebsd-amd64":
@@ -1197,13 +1192,15 @@ func (t *tester) supportedBuildmode(mode string) bool {
11971192
return false
11981193
case "pie":
11991194
switch pair {
1200-
case "aix/ppc64",
1195+
case "aix-ppc64",
12011196
"linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
12021197
"android-amd64", "android-arm", "android-arm64", "android-386":
12031198
return true
1204-
case "darwin-amd64", "darwin-arm64":
1199+
case "darwin-amd64", "darwin-arm64", "ios-amd64", "ios-arm64":
12051200
return true
1206-
case "windows-amd64", "windows-386", "windows-arm":
1201+
case "windows-amd64", "windows-386", "windows-arm", "windows-arm64":
1202+
return true
1203+
case "freebsd-amd64":
12071204
return true
12081205
}
12091206
return false

0 commit comments

Comments
 (0)