...
Source file src/pkg/cmd/dist/main.go
1
2
3
4
5 package main
6
7 import (
8 "flag"
9 "fmt"
10 "os"
11 "runtime"
12 "strings"
13 )
14
15 func usage() {
16 xprintf(`usage: go tool dist [command]
17 Commands are:
18
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
27
28 All commands take -v flags to emit extra information.
29 `)
30 xexit(2)
31 }
32
33
34 var commands = map[string]func(){
35 "banner": cmdbanner,
36 "bootstrap": cmdbootstrap,
37 "clean": cmdclean,
38 "env": cmdenv,
39 "install": cmdinstall,
40 "list": cmdlist,
41 "test": cmdtest,
42 "version": cmdversion,
43 }
44
45
46 func main() {
47 os.Setenv("TERM", "dumb")
48
49
50
51 if len(os.Args) > 1 && os.Args[1] == "-check-armv6k" {
52 useARMv6K()
53 println("ARMv6K supported.")
54 os.Exit(0)
55 }
56
57 gohostos = runtime.GOOS
58 switch gohostos {
59 case "aix":
60
61 gohostarch = "ppc64"
62 case "darwin":
63
64 defaultclang = true
65 case "freebsd":
66
67 defaultclang = true
68 case "openbsd":
69
70
71
72
73 if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
74 defaultclang = true
75 }
76 case "plan9":
77 gohostarch = os.Getenv("objtype")
78 if gohostarch == "" {
79 fatalf("$objtype is unset")
80 }
81 case "solaris", "illumos":
82
83
84
85
86 out := run("", CheckExit, "isainfo", "-n")
87 if strings.Contains(out, "amd64") {
88 gohostarch = "amd64"
89 }
90 if strings.Contains(out, "i386") {
91 gohostarch = "386"
92 }
93 case "windows":
94 exe = ".exe"
95 }
96
97 sysinit()
98
99 if gohostarch == "" {
100
101 out := run("", CheckExit, "uname", "-m")
102 switch {
103 case strings.Contains(out, "x86_64"), strings.Contains(out, "amd64"):
104 gohostarch = "amd64"
105 case strings.Contains(out, "86"):
106 gohostarch = "386"
107 if gohostos == "darwin" {
108
109
110 gohostarch = "amd64"
111 }
112 case strings.Contains(out, "aarch64"), strings.Contains(out, "arm64"):
113 gohostarch = "arm64"
114 case strings.Contains(out, "arm"):
115 gohostarch = "arm"
116 case strings.Contains(out, "ppc64le"):
117 gohostarch = "ppc64le"
118 case strings.Contains(out, "ppc64"):
119 gohostarch = "ppc64"
120 case strings.Contains(out, "mips64"):
121 gohostarch = "mips64"
122 if elfIsLittleEndian(os.Args[0]) {
123 gohostarch = "mips64le"
124 }
125 case strings.Contains(out, "mips"):
126 gohostarch = "mips"
127 if elfIsLittleEndian(os.Args[0]) {
128 gohostarch = "mipsle"
129 }
130 case strings.Contains(out, "s390x"):
131 gohostarch = "s390x"
132 case gohostos == "darwin":
133 if strings.Contains(run("", CheckExit, "uname", "-v"), "RELEASE_ARM64_") {
134 gohostarch = "arm64"
135 }
136 default:
137 fatalf("unknown architecture: %s", out)
138 }
139 }
140
141 if gohostarch == "arm" || gohostarch == "mips64" || gohostarch == "mips64le" {
142 maxbg = min(maxbg, runtime.NumCPU())
143 }
144 bginit()
145
146 if len(os.Args) > 1 && os.Args[1] == "-check-goarm" {
147 useVFPv1()
148 println("VFPv1 OK.")
149 useVFPv3()
150 println("VFPv3 OK.")
151 os.Exit(0)
152 }
153
154 xinit()
155 xmain()
156 xexit(0)
157 }
158
159
160 func xmain() {
161 if len(os.Args) < 2 {
162 usage()
163 }
164 cmd := os.Args[1]
165 os.Args = os.Args[1:]
166 flag.Usage = func() {
167 fmt.Fprintf(os.Stderr, "usage: go tool dist %s [options]\n", cmd)
168 flag.PrintDefaults()
169 os.Exit(2)
170 }
171 if f, ok := commands[cmd]; ok {
172 f()
173 } else {
174 xprintf("unknown command %s\n", cmd)
175 usage()
176 }
177 }
178
View as plain text