Skip to content

Commit 505325c

Browse files
ianlancetaylorgopherbot
authored andcommitted
cmd/dist: use a copy of platform.BuildModeSupported
The dist tool already includes a similar duplicate of BuildModeSupported. Replace it with an exact copy, to make it easier to maintain going forward. Change-Id: Id14a6c5a48f92d843e02218d87cc62c6b001923b Reviewed-on: https://go-review.googlesource.com/c/go/+/467495 Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent 261fe25 commit 505325c

File tree

2 files changed

+94
-68
lines changed

2 files changed

+94
-68
lines changed

src/cmd/dist/test.go

Lines changed: 93 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,79 +1136,14 @@ func (t *tester) internalLinkPIE() bool {
11361136

11371137
// supportedBuildMode reports whether the given build mode is supported.
11381138
func (t *tester) supportedBuildmode(mode string) bool {
1139-
pair := goos + "-" + goarch
11401139
switch mode {
1141-
case "c-archive":
1142-
if !t.extLink() {
1143-
return false
1144-
}
1145-
switch goos {
1146-
case "aix", "darwin", "ios", "windows":
1147-
return true
1148-
case "linux":
1149-
switch goarch {
1150-
case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64", "ppc64le", "riscv64", "s390x":
1151-
return true
1152-
default:
1153-
// Other targets do not support -shared,
1154-
// per ParseFlags in
1155-
// cmd/compile/internal/base/flag.go.
1156-
// For c-archive the Go tool passes -shared,
1157-
// so that the result is suitable for inclusion
1158-
// in a PIE or shared library.
1159-
return false
1160-
}
1161-
case "freebsd":
1162-
return goarch == "amd64"
1163-
}
1164-
return false
1165-
case "c-shared":
1166-
switch pair {
1167-
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
1168-
"darwin-amd64", "darwin-arm64",
1169-
"freebsd-amd64",
1170-
"android-arm", "android-arm64", "android-386", "android-amd64",
1171-
"windows-amd64", "windows-386", "windows-arm64":
1172-
return true
1173-
}
1174-
return false
1175-
case "shared":
1176-
switch pair {
1177-
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-s390x":
1178-
return true
1179-
}
1180-
return false
1181-
case "plugin":
1182-
switch pair {
1183-
case "linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-s390x", "linux-ppc64le":
1184-
return true
1185-
case "android-386", "android-amd64":
1186-
return true
1187-
case "darwin-amd64", "darwin-arm64":
1188-
return true
1189-
case "freebsd-amd64":
1190-
return true
1191-
}
1192-
return false
1193-
case "pie":
1194-
switch pair {
1195-
case "aix-ppc64",
1196-
"linux-386", "linux-amd64", "linux-arm", "linux-arm64", "linux-ppc64le", "linux-riscv64", "linux-s390x",
1197-
"android-amd64", "android-arm", "android-arm64", "android-386":
1198-
return true
1199-
case "darwin-amd64", "darwin-arm64", "ios-amd64", "ios-arm64":
1200-
return true
1201-
case "windows-amd64", "windows-386", "windows-arm", "windows-arm64":
1202-
return true
1203-
case "freebsd-amd64":
1204-
return true
1205-
}
1206-
return false
1207-
1140+
case "c-archive", "c-shared", "shared", "plugin", "pie":
12081141
default:
12091142
fatalf("internal error: unknown buildmode %s", mode)
12101143
return false
12111144
}
1145+
1146+
return buildModeSupported("gc", mode, goos, goarch)
12121147
}
12131148

12141149
func (t *tester) registerCgoTests() {
@@ -1737,6 +1672,96 @@ func raceDetectorSupported(goos, goarch string) bool {
17371672
}
17381673
}
17391674

1675+
// buildModeSupports is a copy of the function
1676+
// internal/platform.BuildModeSupported, which can't be used here
1677+
// because cmd/dist can not import internal packages during bootstrap.
1678+
func buildModeSupported(compiler, buildmode, goos, goarch string) bool {
1679+
if compiler == "gccgo" {
1680+
return true
1681+
}
1682+
1683+
platform := goos + "/" + goarch
1684+
1685+
switch buildmode {
1686+
case "archive":
1687+
return true
1688+
1689+
case "c-archive":
1690+
switch goos {
1691+
case "aix", "darwin", "ios", "windows":
1692+
return true
1693+
case "linux":
1694+
switch goarch {
1695+
case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "ppc64le", "riscv64", "s390x":
1696+
// linux/ppc64 not supported because it does
1697+
// not support external linking mode yet.
1698+
return true
1699+
default:
1700+
// Other targets do not support -shared,
1701+
// per ParseFlags in
1702+
// cmd/compile/internal/base/flag.go.
1703+
// For c-archive the Go tool passes -shared,
1704+
// so that the result is suitable for inclusion
1705+
// in a PIE or shared library.
1706+
return false
1707+
}
1708+
case "freebsd":
1709+
return goarch == "amd64"
1710+
}
1711+
return false
1712+
1713+
case "c-shared":
1714+
switch platform {
1715+
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
1716+
"android/amd64", "android/arm", "android/arm64", "android/386",
1717+
"freebsd/amd64",
1718+
"darwin/amd64", "darwin/arm64",
1719+
"windows/amd64", "windows/386", "windows/arm64":
1720+
return true
1721+
}
1722+
return false
1723+
1724+
case "default":
1725+
return true
1726+
1727+
case "exe":
1728+
return true
1729+
1730+
case "pie":
1731+
switch platform {
1732+
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
1733+
"android/amd64", "android/arm", "android/arm64", "android/386",
1734+
"freebsd/amd64",
1735+
"darwin/amd64", "darwin/arm64",
1736+
"ios/amd64", "ios/arm64",
1737+
"aix/ppc64",
1738+
"windows/386", "windows/amd64", "windows/arm", "windows/arm64":
1739+
return true
1740+
}
1741+
return false
1742+
1743+
case "shared":
1744+
switch platform {
1745+
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
1746+
return true
1747+
}
1748+
return false
1749+
1750+
case "plugin":
1751+
switch platform {
1752+
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
1753+
"android/amd64", "android/386",
1754+
"darwin/amd64", "darwin/arm64",
1755+
"freebsd/amd64":
1756+
return true
1757+
}
1758+
return false
1759+
1760+
default:
1761+
return false
1762+
}
1763+
}
1764+
17401765
// isUnsupportedVMASize reports whether the failure is caused by an unsupported
17411766
// VMA for the race detector (for example, running the race detector on an
17421767
// arm64 machine configured with 39-bit VMA)

src/internal/platform/supported.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ func MustLinkExternal(goos, goarch string) bool {
8888

8989
// BuildModeSupported reports whether goos/goarch supports the given build mode
9090
// using the given compiler.
91+
// There is a copy of this function in cmd/dist/test.go.
9192
func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
9293
if compiler == "gccgo" {
9394
return true

0 commit comments

Comments
 (0)