Skip to content

Commit c3ecded

Browse files
committed
cmd/dist: introduce list subcommand to list all supported platforms
Fixes #12270. Change-Id: Ie3dcbd0403d270b4b7f5c39049e12315eee159ed Reviewed-on: https://go-review.googlesource.com/19837 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Minux Ma <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 539aa05 commit c3ecded

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

doc/go1.7.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Tools:
22

3+
cmd/dist: add list subcommand to list all supported platforms (CL 19837)
34
cmd/go: GO15VENDOREXPERIMENT gone, assumed on (CL 19615)
45
cmd/link: "-X name value" form gone (CL 19614)
56

src/cmd/dist/build.go

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

77
import (
88
"bytes"
9+
"encoding/json"
910
"flag"
1011
"fmt"
1112
"os"
@@ -937,6 +938,7 @@ func usage() {
937938
"clean deletes all built files\n" +
938939
"env [-p] print environment (-p: include $PATH)\n" +
939940
"install [dir] install individual directory\n" +
941+
"list [-json] list all supported platforms\n" +
940942
"test [-h] run Go test(s)\n" +
941943
"version print Go version\n" +
942944
"\n" +
@@ -1068,6 +1070,10 @@ func cmdbootstrap() {
10681070
// Cannot use go/build directly because cmd/dist for a new release
10691071
// builds against an old release's go/build, which may be out of sync.
10701072
// To reduce duplication, we generate the list for go/build from this.
1073+
//
1074+
// We list all supported platforms in this list, so that this is the
1075+
// single point of truth for supported platforms. This list is used
1076+
// by 'go tool dist list'.
10711077
var cgoEnabled = map[string]bool{
10721078
"darwin/386": true,
10731079
"darwin/amd64": true,
@@ -1076,19 +1082,31 @@ var cgoEnabled = map[string]bool{
10761082
"dragonfly/amd64": true,
10771083
"freebsd/386": true,
10781084
"freebsd/amd64": true,
1085+
"freebsd/arm": false,
10791086
"linux/386": true,
10801087
"linux/amd64": true,
10811088
"linux/arm": true,
10821089
"linux/arm64": true,
1090+
"linux/ppc64": false,
10831091
"linux/ppc64le": true,
1092+
"linux/mips64": false,
1093+
"linux/mips64le": false,
10841094
"android/386": true,
10851095
"android/amd64": true,
10861096
"android/arm": true,
1097+
"android/arm64": true,
1098+
"nacl/386": false,
1099+
"nacl/amd64p32": false,
1100+
"nacl/arm": false,
10871101
"netbsd/386": true,
10881102
"netbsd/amd64": true,
10891103
"netbsd/arm": true,
10901104
"openbsd/386": true,
10911105
"openbsd/amd64": true,
1106+
"openbsd/arm": false,
1107+
"plan9/386": false,
1108+
"plan9/amd64": false,
1109+
"plan9/arm": false,
10921110
"solaris/amd64": true,
10931111
"windows/386": true,
10941112
"windows/amd64": true,
@@ -1199,3 +1217,43 @@ func cmdversion() {
11991217
xflagparse(0)
12001218
xprintf("%s\n", findgoversion())
12011219
}
1220+
1221+
// cmdlist lists all supported platforms.
1222+
func cmdlist() {
1223+
jsonFlag := flag.Bool("json", false, "produce JSON output")
1224+
xflagparse(0)
1225+
1226+
var plats []string
1227+
for p := range cgoEnabled {
1228+
plats = append(plats, p)
1229+
}
1230+
sort.Strings(plats)
1231+
1232+
if !*jsonFlag {
1233+
for _, p := range plats {
1234+
xprintf("%s\n", p)
1235+
}
1236+
return
1237+
}
1238+
1239+
type jsonResult struct {
1240+
GOOS string
1241+
GOARCH string
1242+
CgoSupported bool
1243+
}
1244+
var results []jsonResult
1245+
for _, p := range plats {
1246+
fields := strings.Split(p, "/")
1247+
results = append(results, jsonResult{
1248+
GOOS: fields[0],
1249+
GOARCH: fields[1],
1250+
CgoSupported: cgoEnabled[p]})
1251+
}
1252+
out, err := json.MarshalIndent(results, "", "\t")
1253+
if err != nil {
1254+
fatal("json marshal error: %v", err)
1255+
}
1256+
if _, err := os.Stdout.Write(out); err != nil {
1257+
fatal("write failed: %v", err)
1258+
}
1259+
}

src/cmd/dist/buildgo.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ func mkzcgo(dir, file string) {
5656
"package build\n"+
5757
"\n"+
5858
"var cgoEnabled = map[string]bool{\n")
59-
for plat := range cgoEnabled {
60-
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
59+
for plat, hasCgo := range cgoEnabled {
60+
if hasCgo {
61+
fmt.Fprintf(&buf, "\t%q: true,\n", plat)
62+
}
6163
}
6264
fmt.Fprintf(&buf, "}")
6365

src/cmd/dist/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var cmdtab = []struct {
2121
{"clean", cmdclean},
2222
{"env", cmdenv},
2323
{"install", cmdinstall},
24+
{"list", cmdlist},
2425
{"test", cmdtest},
2526
{"version", cmdversion},
2627
}

0 commit comments

Comments
 (0)