]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist: introduce list subcommand to list all supported platforms
authorShenghou Ma <minux@golang.org>
Wed, 24 Feb 2016 17:34:56 +0000 (12:34 -0500)
committerMinux Ma <minux@golang.org>
Wed, 24 Feb 2016 06:41:08 +0000 (06:41 +0000)
Fixes #12270.

Change-Id: Ie3dcbd0403d270b4b7f5c39049e12315eee159ed
Reviewed-on: https://go-review.googlesource.com/19837
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

doc/go1.7.txt
src/cmd/dist/build.go
src/cmd/dist/buildgo.go
src/cmd/dist/main.go

index 15efa287ce9aa4718a308d3514b9e22a1117e977..2af8b5447e6554a9871016a40b01b0dad14ef51c 100644 (file)
@@ -1,5 +1,6 @@
 Tools:
 
+cmd/dist: add list subcommand to list all supported platforms (CL 19837)
 cmd/go: GO15VENDOREXPERIMENT gone, assumed on (CL 19615)
 cmd/link: "-X name value" form gone (CL 19614)
 
index 8ef73e7a89b361ff5b34ce405bb5326706b7984d..1b3df333d602a19d6509e9af1df229933d32f32a 100644 (file)
@@ -6,6 +6,7 @@ package main
 
 import (
        "bytes"
+       "encoding/json"
        "flag"
        "fmt"
        "os"
@@ -937,6 +938,7 @@ func usage() {
                "clean          deletes all built files\n" +
                "env [-p]       print environment (-p: include $PATH)\n" +
                "install [dir]  install individual directory\n" +
+               "list [-json]   list all supported platforms\n" +
                "test [-h]      run Go test(s)\n" +
                "version        print Go version\n" +
                "\n" +
@@ -1068,6 +1070,10 @@ func cmdbootstrap() {
 // Cannot use go/build directly because cmd/dist for a new release
 // builds against an old release's go/build, which may be out of sync.
 // To reduce duplication, we generate the list for go/build from this.
+//
+// We list all supported platforms in this list, so that this is the
+// single point of truth for supported platforms. This list is used
+// by 'go tool dist list'.
 var cgoEnabled = map[string]bool{
        "darwin/386":      true,
        "darwin/amd64":    true,
@@ -1076,19 +1082,31 @@ var cgoEnabled = map[string]bool{
        "dragonfly/amd64": true,
        "freebsd/386":     true,
        "freebsd/amd64":   true,
+       "freebsd/arm":     false,
        "linux/386":       true,
        "linux/amd64":     true,
        "linux/arm":       true,
        "linux/arm64":     true,
+       "linux/ppc64":     false,
        "linux/ppc64le":   true,
+       "linux/mips64":    false,
+       "linux/mips64le":  false,
        "android/386":     true,
        "android/amd64":   true,
        "android/arm":     true,
+       "android/arm64":   true,
+       "nacl/386":        false,
+       "nacl/amd64p32":   false,
+       "nacl/arm":        false,
        "netbsd/386":      true,
        "netbsd/amd64":    true,
        "netbsd/arm":      true,
        "openbsd/386":     true,
        "openbsd/amd64":   true,
+       "openbsd/arm":     false,
+       "plan9/386":       false,
+       "plan9/amd64":     false,
+       "plan9/arm":       false,
        "solaris/amd64":   true,
        "windows/386":     true,
        "windows/amd64":   true,
@@ -1199,3 +1217,43 @@ func cmdversion() {
        xflagparse(0)
        xprintf("%s\n", findgoversion())
 }
+
+// cmdlist lists all supported platforms.
+func cmdlist() {
+       jsonFlag := flag.Bool("json", false, "produce JSON output")
+       xflagparse(0)
+
+       var plats []string
+       for p := range cgoEnabled {
+               plats = append(plats, p)
+       }
+       sort.Strings(plats)
+
+       if !*jsonFlag {
+               for _, p := range plats {
+                       xprintf("%s\n", p)
+               }
+               return
+       }
+
+       type jsonResult struct {
+               GOOS         string
+               GOARCH       string
+               CgoSupported bool
+       }
+       var results []jsonResult
+       for _, p := range plats {
+               fields := strings.Split(p, "/")
+               results = append(results, jsonResult{
+                       GOOS:         fields[0],
+                       GOARCH:       fields[1],
+                       CgoSupported: cgoEnabled[p]})
+       }
+       out, err := json.MarshalIndent(results, "", "\t")
+       if err != nil {
+               fatal("json marshal error: %v", err)
+       }
+       if _, err := os.Stdout.Write(out); err != nil {
+               fatal("write failed: %v", err)
+       }
+}
index 3dc9ff0dde30fd9eb0e077f951bf4df995e1acbf..c0bdfad9b1ba27837c8ff2407aa13daee2bc828c 100644 (file)
@@ -56,8 +56,10 @@ func mkzcgo(dir, file string) {
                        "package build\n"+
                        "\n"+
                        "var cgoEnabled = map[string]bool{\n")
-       for plat := range cgoEnabled {
-               fmt.Fprintf(&buf, "\t%q: true,\n", plat)
+       for plat, hasCgo := range cgoEnabled {
+               if hasCgo {
+                       fmt.Fprintf(&buf, "\t%q: true,\n", plat)
+               }
        }
        fmt.Fprintf(&buf, "}")
 
index 1f19a7ca1836f786de0796e86308fd05f3120187..eaee28ada8268b16700b9477047a2edbd0bd4d0a 100644 (file)
@@ -21,6 +21,7 @@ var cmdtab = []struct {
        {"clean", cmdclean},
        {"env", cmdenv},
        {"install", cmdinstall},
+       {"list", cmdlist},
        {"test", cmdtest},
        {"version", cmdversion},
 }