Skip to content

Commit f8616b8

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
internal/platform,cmd/dist: export the list of supported platforms
Also switch internal/platform to commit the generated code instead of regenerating it in cmd/dist. Nothing in the generated code depends on the target configuration, and committing the source file makes it more amenable to searching and indexing (particularly on https://cs.opensource.google/go/go). For golang#60939. Change-Id: I9133dfd5129b3c4d7457267589dfac5e7ecbef65 Reviewed-on: https://go-review.googlesource.com/c/go/+/505175 TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Austin Clements <[email protected]> Run-TryBot: Bryan Mills <[email protected]>
1 parent 51885c1 commit f8616b8

File tree

9 files changed

+275
-45
lines changed

9 files changed

+275
-45
lines changed

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ _testmain.go
3333
/src/cmd/cgo/zdefaultcc.go
3434
/src/cmd/dist/dist
3535
/src/cmd/go/internal/cfg/zdefaultcc.go
36-
/src/cmd/go/internal/cfg/zosarch.go
3736
/src/cmd/internal/objabi/zbootstrap.go
3837
/src/go/build/zcgo.go
3938
/src/go/doc/headscan
4039
/src/internal/buildcfg/zbootstrap.go
41-
/src/internal/platform/zosarch.go
4240
/src/runtime/internal/sys/zversion.go
4341
/src/unicode/maketables
4442
/src/time/tzdata/zzipdata.go

src/cmd/dist/build.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,6 @@ var gentab = []struct {
631631
}{
632632
{"go/build", "zcgo.go", mkzcgo},
633633
{"cmd/go/internal/cfg", "zdefaultcc.go", mkzdefaultcc},
634-
{"internal/platform", "zosarch.go", mkzosarch},
635634
{"runtime/internal/sys", "zversion.go", mkzversion},
636635
{"time/tzdata", "zzipdata.go", mktzdata},
637636
}
@@ -1899,11 +1898,12 @@ func cmdversion() {
18991898
// cmdlist lists all supported platforms.
19001899
func cmdlist() {
19011900
jsonFlag := flag.Bool("json", false, "produce JSON output")
1901+
brokenFlag := flag.Bool("broken", false, "include broken ports")
19021902
xflagparse(0)
19031903

19041904
var plats []string
19051905
for p := range cgoEnabled {
1906-
if broken[p] {
1906+
if broken[p] && !*brokenFlag {
19071907
continue
19081908
}
19091909
plats = append(plats, p)
@@ -1922,6 +1922,7 @@ func cmdlist() {
19221922
GOARCH string
19231923
CgoSupported bool
19241924
FirstClass bool
1925+
Broken bool `json:",omitempty"`
19251926
}
19261927
var results []jsonResult
19271928
for _, p := range plats {
@@ -1930,7 +1931,9 @@ func cmdlist() {
19301931
GOOS: fields[0],
19311932
GOARCH: fields[1],
19321933
CgoSupported: cgoEnabled[p],
1933-
FirstClass: firstClass[p]})
1934+
FirstClass: firstClass[p],
1935+
Broken: broken[p],
1936+
})
19341937
}
19351938
out, err := json.MarshalIndent(results, "", "\t")
19361939
if err != nil {

src/cmd/dist/buildruntime.go

-23
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package main
66

77
import (
88
"fmt"
9-
"sort"
109
"strings"
1110
)
1211

@@ -80,25 +79,3 @@ func mkobjabi(file string) {
8079

8180
writefile(buf.String(), file, writeSkipSame)
8281
}
83-
84-
// mkzosarch writes zosarch.go for internal/platform.
85-
func mkzosarch(dir, file string) {
86-
// sort for deterministic file contents.
87-
var list []string
88-
for plat := range cgoEnabled {
89-
list = append(list, plat)
90-
}
91-
sort.Strings(list)
92-
93-
var buf strings.Builder
94-
writeHeader(&buf)
95-
fmt.Fprintf(&buf, "package platform\n")
96-
fmt.Fprintln(&buf)
97-
fmt.Fprintf(&buf, "var osArchSupportsCgo = map[string]bool{\n")
98-
for _, plat := range list {
99-
fmt.Fprintf(&buf, "\t\t%s: %v,\n", quote(plat), cgoEnabled[plat])
100-
}
101-
fmt.Fprintf(&buf, "}\n")
102-
103-
writefile(buf.String(), file, writeSkipSame)
104-
}

src/cmd/dist/buildtool.go

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func bootstrapBuildTools() {
126126

127127
mkbuildcfg(pathf("%s/src/internal/buildcfg/zbootstrap.go", goroot))
128128
mkobjabi(pathf("%s/src/cmd/internal/objabi/zbootstrap.go", goroot))
129-
mkzosarch("", pathf("%s/src/internal/platform/zosarch.go", goroot))
130129

131130
// Use $GOROOT/pkg/bootstrap as the bootstrap workspace root.
132131
// We use a subdirectory of $GOROOT/pkg because that's the

src/cmd/dist/main.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ func usage() {
1616
xprintf(`usage: go tool dist [command]
1717
Commands are:
1818
19-
banner print installation banner
20-
bootstrap rebuild everything
21-
clean deletes all built files
22-
env [-p] print environment (-p: include $PATH)
23-
install [dir] install individual directory
24-
list [-json] list all supported platforms
25-
test [-h] run Go test(s)
26-
version print Go version
19+
banner print installation banner
20+
bootstrap rebuild everything
21+
clean deletes all built files
22+
env [-p] print environment (-p: include $PATH)
23+
install [dir] install individual directory
24+
list [-json] [-broken] list all supported platforms
25+
test [-h] run Go test(s)
26+
version print Go version
2727
2828
All commands take -v flags to emit extra information.
2929
`)

src/cmd/distpack/pack.go

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ func main() {
127127
// Generated during cmd/dist. See ../dist/build.go:/gentab.
128128
"src/cmd/go/internal/cfg/zdefaultcc.go",
129129
"src/go/build/zcgo.go",
130-
"src/internal/platform/zosarch.go",
131130
"src/runtime/internal/sys/zversion.go",
132131
"src/time/tzdata/zzipdata.go",
133132

src/internal/platform/supported.go

+38-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:generate go test . -run=TestGenerated -fix
6+
57
package platform
68

9+
// An OSArch is a pair of GOOS and GOARCH values indicating a platform.
10+
type OSArch struct {
11+
GOOS, GOARCH string
12+
}
13+
14+
func (p OSArch) String() string {
15+
return p.GOOS + "/" + p.GOARCH
16+
}
17+
718
// RaceDetectorSupported reports whether goos/goarch supports the race
819
// detector. There is a copy of this function in cmd/dist/test.go.
920
// Race detector only supports 48-bit VMA on arm64. But it will always
@@ -123,11 +134,11 @@ func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
123134
return true
124135
}
125136

126-
platform := goos + "/" + goarch
127-
if _, ok := osArchSupportsCgo[platform]; !ok {
137+
if _, ok := distInfo[OSArch{goos, goarch}]; !ok {
128138
return false // platform unrecognized
129139
}
130140

141+
platform := goos + "/" + goarch
131142
switch buildmode {
132143
case "archive":
133144
return true
@@ -239,11 +250,6 @@ func DefaultPIE(goos, goarch string, isRace bool) bool {
239250
return false
240251
}
241252

242-
// CgoSupported reports whether goos/goarch supports cgo.
243-
func CgoSupported(goos, goarch string) bool {
244-
return osArchSupportsCgo[goos+"/"+goarch]
245-
}
246-
247253
// ExecutableHasDWARF reports whether the linked executable includes DWARF
248254
// symbols on goos/goarch.
249255
func ExecutableHasDWARF(goos, goarch string) bool {
@@ -253,3 +259,28 @@ func ExecutableHasDWARF(goos, goarch string) bool {
253259
}
254260
return true
255261
}
262+
263+
// osArchInfo describes information about an OSArch extracted from cmd/dist and
264+
// stored in the generated distInfo map.
265+
type osArchInfo struct {
266+
CgoSupported bool
267+
FirstClass bool
268+
Broken bool
269+
}
270+
271+
// CgoSupported reports whether goos/goarch supports cgo.
272+
func CgoSupported(goos, goarch string) bool {
273+
return distInfo[OSArch{goos, goarch}].CgoSupported
274+
}
275+
276+
// FirstClass reports whether goos/goarch is considered a “first class” port.
277+
// (See https://go.dev/wiki/PortingPolicy#first-class-ports.)
278+
func FirstClass(goos, goarch string) bool {
279+
return distInfo[OSArch{goos, goarch}].FirstClass
280+
}
281+
282+
// Broken reportsr whether goos/goarch is considered a broken port.
283+
// (See https://go.dev/wiki/PortingPolicy#broken-ports.)
284+
func Broken(goos, goarch string) bool {
285+
return distInfo[OSArch{goos, goarch}].Broken
286+
}

src/internal/platform/zosarch.go

+114
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)