2016-03-01 15:57:46 -07:00
|
|
|
// Copyright 2012 The Go Authors. All rights reserved.
|
cmd/dist: new command
dist is short for distribution. This is the new Go distribution tool.
The plan is to replace the Makefiles with what amounts to
'go tool dist bootstrap', although it cannot be invoked like
that since it is in charge of getting us to the point where we
can build the go command.
It will also add additional commands to replace bash scripts
like test/run (go tool dist testrun), eventually eliminating our
dependence on not just bash but all the Unix tools and all
of cygwin.
This is strong enough to build (cc *.c) and run (a.out bootstrap)
to build not just the C libraries and tools but also the basic
Go packages up to the bootstrap form of the go command
(go_bootstrap). I've run it successfully on both Linux and Windows.
This means that once we've switched to this tool in the build,
we can delete the buildscripts.
This tool is not nearly as nice as the go tool. There are many
special cases that turn into simple if statements or tables in
the code. Please forgive that. C does not enjoy the benefits
that we designed into Go.
I was planning to wait to do this until after Go 1, but the
Windows builders are both broken due to a bug in either
make or bash or both involving the parsing of quoted command
arguments. Make thinks it is invoking
quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c
but bash (quietgcc is a bash script) thinks it is being invoked as
quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c
which obviously does not have the desired effect. Rather than fight
these clumsy ports, I accelerated the schedule for the new tool.
We should be completely off cygwin (using just the mingw gcc port,
which is much more standalone) before Go 1.
It is big for a single CL, and for that I apologize. I can cut it into
separate CLs along file boundaries if people would prefer that.
R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter
CC=golang-dev
https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
package main
|
cmd/dist: new command
dist is short for distribution. This is the new Go distribution tool.
The plan is to replace the Makefiles with what amounts to
'go tool dist bootstrap', although it cannot be invoked like
that since it is in charge of getting us to the point where we
can build the go command.
It will also add additional commands to replace bash scripts
like test/run (go tool dist testrun), eventually eliminating our
dependence on not just bash but all the Unix tools and all
of cygwin.
This is strong enough to build (cc *.c) and run (a.out bootstrap)
to build not just the C libraries and tools but also the basic
Go packages up to the bootstrap form of the go command
(go_bootstrap). I've run it successfully on both Linux and Windows.
This means that once we've switched to this tool in the build,
we can delete the buildscripts.
This tool is not nearly as nice as the go tool. There are many
special cases that turn into simple if statements or tables in
the code. Please forgive that. C does not enjoy the benefits
that we designed into Go.
I was planning to wait to do this until after Go 1, but the
Windows builders are both broken due to a bug in either
make or bash or both involving the parsing of quoted command
arguments. Make thinks it is invoking
quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c
but bash (quietgcc is a bash script) thinks it is being invoked as
quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c
which obviously does not have the desired effect. Rather than fight
these clumsy ports, I accelerated the schedule for the new tool.
We should be completely off cygwin (using just the mingw gcc port,
which is much more standalone) before Go 1.
It is big for a single CL, and for that I apologize. I can cut it into
separate CLs along file boundaries if people would prefer that.
R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter
CC=golang-dev
https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
|
|
|
|
2015-01-07 09:38:00 -07:00
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2017-08-31 05:00:19 -06:00
|
|
|
"runtime"
|
2015-01-07 09:38:00 -07:00
|
|
|
"strconv"
|
2017-08-31 05:00:19 -06:00
|
|
|
"strings"
|
2015-01-07 09:38:00 -07:00
|
|
|
)
|
2012-02-03 16:16:42 -07:00
|
|
|
|
2017-08-31 05:00:19 -06:00
|
|
|
func usage() {
|
2017-08-31 04:50:57 -06:00
|
|
|
xprintf(`usage: go tool dist [command]
|
|
|
|
Commands are:
|
|
|
|
|
|
|
|
banner print installation banner
|
|
|
|
bootstrap rebuild everything
|
|
|
|
clean deletes all built files
|
|
|
|
env [-p] print environment (-p: include $PATH)
|
|
|
|
install [dir] install individual directory
|
|
|
|
list [-json] list all supported platforms
|
|
|
|
test [-h] run Go test(s)
|
|
|
|
version print Go version
|
|
|
|
|
|
|
|
All commands take -v flags to emit extra information.
|
|
|
|
`)
|
2017-08-31 05:00:19 -06:00
|
|
|
xexit(2)
|
|
|
|
}
|
|
|
|
|
2017-08-31 04:50:57 -06:00
|
|
|
// commands records the available commands.
|
|
|
|
var commands = map[string]func(){
|
|
|
|
"banner": cmdbanner,
|
|
|
|
"bootstrap": cmdbootstrap,
|
|
|
|
"clean": cmdclean,
|
|
|
|
"env": cmdenv,
|
|
|
|
"install": cmdinstall,
|
|
|
|
"list": cmdlist,
|
|
|
|
"test": cmdtest,
|
|
|
|
"version": cmdversion,
|
2015-01-07 09:38:00 -07:00
|
|
|
}
|
cmd/dist: new command
dist is short for distribution. This is the new Go distribution tool.
The plan is to replace the Makefiles with what amounts to
'go tool dist bootstrap', although it cannot be invoked like
that since it is in charge of getting us to the point where we
can build the go command.
It will also add additional commands to replace bash scripts
like test/run (go tool dist testrun), eventually eliminating our
dependence on not just bash but all the Unix tools and all
of cygwin.
This is strong enough to build (cc *.c) and run (a.out bootstrap)
to build not just the C libraries and tools but also the basic
Go packages up to the bootstrap form of the go command
(go_bootstrap). I've run it successfully on both Linux and Windows.
This means that once we've switched to this tool in the build,
we can delete the buildscripts.
This tool is not nearly as nice as the go tool. There are many
special cases that turn into simple if statements or tables in
the code. Please forgive that. C does not enjoy the benefits
that we designed into Go.
I was planning to wait to do this until after Go 1, but the
Windows builders are both broken due to a bug in either
make or bash or both involving the parsing of quoted command
arguments. Make thinks it is invoking
quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c
but bash (quietgcc is a bash script) thinks it is being invoked as
quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c
which obviously does not have the desired effect. Rather than fight
these clumsy ports, I accelerated the schedule for the new tool.
We should be completely off cygwin (using just the mingw gcc port,
which is much more standalone) before Go 1.
It is big for a single CL, and for that I apologize. I can cut it into
separate CLs along file boundaries if people would prefer that.
R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter
CC=golang-dev
https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
|
|
|
|
2017-08-31 05:00:19 -06:00
|
|
|
// main takes care of OS-specific startup and dispatches to xmain.
|
|
|
|
func main() {
|
|
|
|
os.Setenv("TERM", "dumb") // disable escape codes in clang errors
|
|
|
|
|
|
|
|
// provide -check-armv6k first, before checking for $GOROOT so that
|
|
|
|
// it is possible to run this check without having $GOROOT available.
|
|
|
|
if len(os.Args) > 1 && os.Args[1] == "-check-armv6k" {
|
|
|
|
useARMv6K() // might fail with SIGILL
|
|
|
|
println("ARMv6K supported.")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
gohostos = runtime.GOOS
|
|
|
|
switch gohostos {
|
|
|
|
case "darwin":
|
|
|
|
// Even on 64-bit platform, darwin uname -m prints i386.
|
|
|
|
// We don't support any of the OS X versions that run on 32-bit-only hardware anymore.
|
|
|
|
gohostarch = "amd64"
|
|
|
|
case "freebsd":
|
|
|
|
// Since FreeBSD 10 gcc is no longer part of the base system.
|
|
|
|
defaultclang = true
|
|
|
|
case "solaris":
|
|
|
|
// Even on 64-bit platform, solaris uname -m prints i86pc.
|
|
|
|
out := run("", CheckExit, "isainfo", "-n")
|
|
|
|
if strings.Contains(out, "amd64") {
|
|
|
|
gohostarch = "amd64"
|
|
|
|
}
|
|
|
|
if strings.Contains(out, "i386") {
|
|
|
|
gohostarch = "386"
|
|
|
|
}
|
|
|
|
case "plan9":
|
|
|
|
gohostarch = os.Getenv("objtype")
|
|
|
|
if gohostarch == "" {
|
2017-08-31 04:52:04 -06:00
|
|
|
fatalf("$objtype is unset")
|
2017-08-31 05:00:19 -06:00
|
|
|
}
|
|
|
|
case "windows":
|
|
|
|
exe = ".exe"
|
|
|
|
}
|
|
|
|
|
|
|
|
sysinit()
|
|
|
|
|
|
|
|
if gohostarch == "" {
|
|
|
|
// Default Unix system.
|
|
|
|
out := run("", CheckExit, "uname", "-m")
|
|
|
|
switch {
|
|
|
|
case strings.Contains(out, "x86_64"), strings.Contains(out, "amd64"):
|
|
|
|
gohostarch = "amd64"
|
|
|
|
case strings.Contains(out, "86"):
|
|
|
|
gohostarch = "386"
|
|
|
|
case strings.Contains(out, "arm"):
|
|
|
|
gohostarch = "arm"
|
|
|
|
case strings.Contains(out, "aarch64"):
|
|
|
|
gohostarch = "arm64"
|
|
|
|
case strings.Contains(out, "ppc64le"):
|
|
|
|
gohostarch = "ppc64le"
|
|
|
|
case strings.Contains(out, "ppc64"):
|
|
|
|
gohostarch = "ppc64"
|
|
|
|
case strings.Contains(out, "mips64"):
|
|
|
|
gohostarch = "mips64"
|
|
|
|
if elfIsLittleEndian(os.Args[0]) {
|
|
|
|
gohostarch = "mips64le"
|
|
|
|
}
|
|
|
|
case strings.Contains(out, "mips"):
|
|
|
|
gohostarch = "mips"
|
|
|
|
if elfIsLittleEndian(os.Args[0]) {
|
|
|
|
gohostarch = "mipsle"
|
|
|
|
}
|
|
|
|
case strings.Contains(out, "s390x"):
|
|
|
|
gohostarch = "s390x"
|
|
|
|
case gohostos == "darwin":
|
|
|
|
if strings.Contains(run("", CheckExit, "uname", "-v"), "RELEASE_ARM_") {
|
|
|
|
gohostarch = "arm"
|
|
|
|
}
|
|
|
|
default:
|
2017-08-31 04:52:04 -06:00
|
|
|
fatalf("unknown architecture: %s", out)
|
2017-08-31 05:00:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if gohostarch == "arm" || gohostarch == "mips64" || gohostarch == "mips64le" {
|
|
|
|
maxbg = min(maxbg, runtime.NumCPU())
|
|
|
|
}
|
|
|
|
bginit()
|
|
|
|
|
|
|
|
// The OS X 10.6 linker does not support external linking mode.
|
|
|
|
// See golang.org/issue/5130.
|
|
|
|
//
|
|
|
|
// OS X 10.6 does not work with clang either, but OS X 10.9 requires it.
|
|
|
|
// It seems to work with OS X 10.8, so we default to clang for 10.8 and later.
|
|
|
|
// See golang.org/issue/5822.
|
|
|
|
//
|
|
|
|
// Roughly, OS X 10.N shows up as uname release (N+4),
|
|
|
|
// so OS X 10.6 is uname version 10 and OS X 10.8 is uname version 12.
|
|
|
|
if gohostos == "darwin" {
|
|
|
|
rel := run("", CheckExit, "uname", "-r")
|
|
|
|
if i := strings.Index(rel, "."); i >= 0 {
|
|
|
|
rel = rel[:i]
|
|
|
|
}
|
|
|
|
osx, _ := strconv.Atoi(rel)
|
|
|
|
if osx <= 6+4 {
|
|
|
|
goextlinkenabled = "0"
|
|
|
|
}
|
|
|
|
if osx >= 8+4 {
|
|
|
|
defaultclang = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(os.Args) > 1 && os.Args[1] == "-check-goarm" {
|
|
|
|
useVFPv1() // might fail with SIGILL
|
|
|
|
println("VFPv1 OK.")
|
|
|
|
useVFPv3() // might fail with SIGILL
|
|
|
|
println("VFPv3 OK.")
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
xinit()
|
|
|
|
xmain()
|
|
|
|
xexit(0)
|
|
|
|
}
|
|
|
|
|
cmd/dist: new command
dist is short for distribution. This is the new Go distribution tool.
The plan is to replace the Makefiles with what amounts to
'go tool dist bootstrap', although it cannot be invoked like
that since it is in charge of getting us to the point where we
can build the go command.
It will also add additional commands to replace bash scripts
like test/run (go tool dist testrun), eventually eliminating our
dependence on not just bash but all the Unix tools and all
of cygwin.
This is strong enough to build (cc *.c) and run (a.out bootstrap)
to build not just the C libraries and tools but also the basic
Go packages up to the bootstrap form of the go command
(go_bootstrap). I've run it successfully on both Linux and Windows.
This means that once we've switched to this tool in the build,
we can delete the buildscripts.
This tool is not nearly as nice as the go tool. There are many
special cases that turn into simple if statements or tables in
the code. Please forgive that. C does not enjoy the benefits
that we designed into Go.
I was planning to wait to do this until after Go 1, but the
Windows builders are both broken due to a bug in either
make or bash or both involving the parsing of quoted command
arguments. Make thinks it is invoking
quietgcc -fno-common -I"c:/go/include" -ggdb -O2 -c foo.c
but bash (quietgcc is a bash script) thinks it is being invoked as
quietgcc -fno-common '-Ic:/go/include -ggdb' -O2 -c foo.c
which obviously does not have the desired effect. Rather than fight
these clumsy ports, I accelerated the schedule for the new tool.
We should be completely off cygwin (using just the mingw gcc port,
which is much more standalone) before Go 1.
It is big for a single CL, and for that I apologize. I can cut it into
separate CLs along file boundaries if people would prefer that.
R=golang-dev, adg, gri, bradfitz, alex.brainman, dsymonds, iant, ality, hcwfrichter
CC=golang-dev
https://golang.org/cl/5620045
2012-02-02 17:41:39 -07:00
|
|
|
// The OS-specific main calls into the portable code here.
|
2015-01-07 09:38:00 -07:00
|
|
|
func xmain() {
|
|
|
|
if len(os.Args) < 2 {
|
|
|
|
usage()
|
|
|
|
}
|
|
|
|
cmd := os.Args[1]
|
|
|
|
os.Args = os.Args[1:] // for flag parsing during cmd
|
2017-08-31 04:50:57 -06:00
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Fprintf(os.Stderr, "usage: go tool dist %s [options]\n", cmd)
|
|
|
|
flag.PrintDefaults()
|
|
|
|
os.Exit(2)
|
|
|
|
}
|
|
|
|
if f, ok := commands[cmd]; ok {
|
|
|
|
f()
|
|
|
|
} else {
|
|
|
|
xprintf("unknown command %s\n", cmd)
|
|
|
|
usage()
|
2015-01-07 09:38:00 -07:00
|
|
|
}
|
|
|
|
}
|