Source file
src/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 defaultclang = true
71 case "plan9":
72 gohostarch = os.Getenv("objtype")
73 if gohostarch == "" {
74 fatalf("$objtype is unset")
75 }
76 case "solaris", "illumos":
77
78
79
80
81 out := run("", CheckExit, "isainfo", "-n")
82 if strings.Contains(out, "amd64") {
83 gohostarch = "amd64"
84 }
85 if strings.Contains(out, "i386") {
86 gohostarch = "386"
87 }
88 case "windows":
89 exe = ".exe"
90 }
91
92 sysinit()
93
94 if gohostarch == "" {
95
96 out := run("", CheckExit, "uname", "-m")
97 outAll := run("", CheckExit, "uname", "-a")
98 switch {
99 case strings.Contains(outAll, "RELEASE_ARM64"):
100
101
102
103
104
105 gohostarch = "arm64"
106 case strings.Contains(out, "x86_64"), strings.Contains(out, "amd64"):
107 gohostarch = "amd64"
108 case strings.Contains(out, "86"):
109 gohostarch = "386"
110 if gohostos == "darwin" {
111
112
113 gohostarch = "amd64"
114 }
115 case strings.Contains(out, "aarch64"), strings.Contains(out, "arm64"):
116 gohostarch = "arm64"
117 case strings.Contains(out, "arm"):
118 gohostarch = "arm"
119 if gohostos == "netbsd" && strings.Contains(run("", CheckExit, "uname", "-p"), "aarch64") {
120 gohostarch = "arm64"
121 }
122 case strings.Contains(out, "ppc64le"):
123 gohostarch = "ppc64le"
124 case strings.Contains(out, "ppc64"):
125 gohostarch = "ppc64"
126 case strings.Contains(out, "mips64"):
127 gohostarch = "mips64"
128 if elfIsLittleEndian(os.Args[0]) {
129 gohostarch = "mips64le"
130 }
131 case strings.Contains(out, "mips"):
132 gohostarch = "mips"
133 if elfIsLittleEndian(os.Args[0]) {
134 gohostarch = "mipsle"
135 }
136 case strings.Contains(out, "riscv64"):
137 gohostarch = "riscv64"
138 case strings.Contains(out, "s390x"):
139 gohostarch = "s390x"
140 case gohostos == "darwin", gohostos == "ios":
141 if strings.Contains(run("", CheckExit, "uname", "-v"), "RELEASE_ARM64_") {
142 gohostarch = "arm64"
143 }
144 case gohostos == "openbsd":
145 if strings.Contains(run("", CheckExit, "uname", "-p"), "mips64") {
146 gohostarch = "mips64"
147 }
148 default:
149 fatalf("unknown architecture: %s", out)
150 }
151 }
152
153 if gohostarch == "arm" || gohostarch == "mips64" || gohostarch == "mips64le" {
154 maxbg = min(maxbg, runtime.NumCPU())
155 }
156 bginit()
157
158 if len(os.Args) > 1 && os.Args[1] == "-check-goarm" {
159 useVFPv1()
160 println("VFPv1 OK.")
161 useVFPv3()
162 println("VFPv3 OK.")
163 os.Exit(0)
164 }
165
166 xinit()
167 xmain()
168 xexit(0)
169 }
170
171
172 func xmain() {
173 if len(os.Args) < 2 {
174 usage()
175 }
176 cmd := os.Args[1]
177 os.Args = os.Args[1:]
178 flag.Usage = func() {
179 fmt.Fprintf(os.Stderr, "usage: go tool dist %s [options]\n", cmd)
180 flag.PrintDefaults()
181 os.Exit(2)
182 }
183 if f, ok := commands[cmd]; ok {
184 f()
185 } else {
186 xprintf("unknown command %s\n", cmd)
187 usage()
188 }
189 }
190
View as plain text