| |
| |
| |
|
|
| package main |
|
|
| import ( |
| "bytes" |
| "encoding/json" |
| "flag" |
| "fmt" |
| "io" |
| "io/fs" |
| "log" |
| "os" |
| "os/exec" |
| "path/filepath" |
| "regexp" |
| "slices" |
| "sort" |
| "strconv" |
| "strings" |
| "sync" |
| "time" |
| ) |
|
|
| |
|
|
| |
| var ( |
| goarch string |
| gorootBin string |
| gorootBinGo string |
| gohostarch string |
| gohostos string |
| goos string |
| goarm string |
| goarm64 string |
| go386 string |
| goamd64 string |
| gomips string |
| gomips64 string |
| goppc64 string |
| goriscv64 string |
| goroot string |
| goextlinkenabled string |
| gogcflags string |
| goldflags string |
| goexperiment string |
| gofips140 string |
| workdir string |
| tooldir string |
| oldgoos string |
| oldgoarch string |
| oldgocache string |
| exe string |
| defaultcc map[string]string |
| defaultcxx map[string]string |
| defaultpkgconfig string |
| defaultldso string |
|
|
| rebuildall bool |
| noOpt bool |
| isRelease bool |
|
|
| vflag int |
| ) |
|
|
| |
| var okgoarch = []string{ |
| "386", |
| "amd64", |
| "arm", |
| "arm64", |
| "loong64", |
| "mips", |
| "mipsle", |
| "mips64", |
| "mips64le", |
| "ppc64", |
| "ppc64le", |
| "riscv64", |
| "s390x", |
| "sparc64", |
| "wasm", |
| } |
|
|
| |
| var okgoos = []string{ |
| "darwin", |
| "dragonfly", |
| "illumos", |
| "ios", |
| "js", |
| "wasip1", |
| "linux", |
| "android", |
| "solaris", |
| "freebsd", |
| "nacl", |
| "netbsd", |
| "openbsd", |
| "plan9", |
| "windows", |
| "aix", |
| } |
|
|
| |
| func xinit() { |
| b := os.Getenv("GOROOT") |
| if b == "" { |
| fatalf("$GOROOT must be set") |
| } |
| goroot = filepath.Clean(b) |
| gorootBin = pathf("%s/bin", goroot) |
|
|
| |
| |
| |
| |
| gorootBinGo = pathf("%s/bin/go", goroot) |
|
|
| b = os.Getenv("GOOS") |
| if b == "" { |
| b = gohostos |
| } |
| goos = b |
| if slices.Index(okgoos, goos) < 0 { |
| fatalf("unknown $GOOS %s", goos) |
| } |
|
|
| b = os.Getenv("GOARM") |
| if b == "" { |
| b = xgetgoarm() |
| } |
| goarm = b |
|
|
| b = os.Getenv("GOARM64") |
| if b == "" { |
| b = "v8.0" |
| } |
| goarm64 = b |
|
|
| b = os.Getenv("GO386") |
| if b == "" { |
| b = "sse2" |
| } |
| go386 = b |
|
|
| b = os.Getenv("GOAMD64") |
| if b == "" { |
| b = "v1" |
| } |
| goamd64 = b |
|
|
| b = os.Getenv("GOMIPS") |
| if b == "" { |
| b = "hardfloat" |
| } |
| gomips = b |
|
|
| b = os.Getenv("GOMIPS64") |
| if b == "" { |
| b = "hardfloat" |
| } |
| gomips64 = b |
|
|
| b = os.Getenv("GOPPC64") |
| if b == "" { |
| b = "power8" |
| } |
| goppc64 = b |
|
|
| b = os.Getenv("GORISCV64") |
| if b == "" { |
| b = "rva20u64" |
| } |
| goriscv64 = b |
|
|
| b = os.Getenv("GOFIPS140") |
| if b == "" { |
| b = "off" |
| } |
| gofips140 = b |
|
|
| if p := pathf("%s/src/all.bash", goroot); !isfile(p) { |
| fatalf("$GOROOT is not set correctly or not exported\n"+ |
| "\tGOROOT=%s\n"+ |
| "\t%s does not exist", goroot, p) |
| } |
|
|
| b = os.Getenv("GOHOSTARCH") |
| if b != "" { |
| gohostarch = b |
| } |
| if slices.Index(okgoarch, gohostarch) < 0 { |
| fatalf("unknown $GOHOSTARCH %s", gohostarch) |
| } |
|
|
| b = os.Getenv("GOARCH") |
| if b == "" { |
| b = gohostarch |
| } |
| goarch = b |
| if slices.Index(okgoarch, goarch) < 0 { |
| fatalf("unknown $GOARCH %s", goarch) |
| } |
|
|
| b = os.Getenv("GO_EXTLINK_ENABLED") |
| if b != "" { |
| if b != "0" && b != "1" { |
| fatalf("unknown $GO_EXTLINK_ENABLED %s", b) |
| } |
| goextlinkenabled = b |
| } |
|
|
| goexperiment = os.Getenv("GOEXPERIMENT") |
| |
|
|
| gogcflags = os.Getenv("BOOT_GO_GCFLAGS") |
| goldflags = os.Getenv("BOOT_GO_LDFLAGS") |
|
|
| defaultcc = compilerEnv("CC", "") |
| defaultcxx = compilerEnv("CXX", "") |
|
|
| b = os.Getenv("PKG_CONFIG") |
| if b == "" { |
| b = "pkg-config" |
| } |
| defaultpkgconfig = b |
|
|
| defaultldso = os.Getenv("GO_LDSO") |
|
|
| |
| os.Setenv("GO386", go386) |
| os.Setenv("GOAMD64", goamd64) |
| os.Setenv("GOARCH", goarch) |
| os.Setenv("GOARM", goarm) |
| os.Setenv("GOARM64", goarm64) |
| os.Setenv("GOHOSTARCH", gohostarch) |
| os.Setenv("GOHOSTOS", gohostos) |
| os.Setenv("GOOS", goos) |
| os.Setenv("GOMIPS", gomips) |
| os.Setenv("GOMIPS64", gomips64) |
| os.Setenv("GOPPC64", goppc64) |
| os.Setenv("GORISCV64", goriscv64) |
| os.Setenv("GOROOT", goroot) |
| os.Setenv("GOFIPS140", gofips140) |
|
|
| |
| |
| |
| |
| os.Setenv("GOBIN", gorootBin) |
|
|
| |
| os.Setenv("LANG", "C") |
| os.Setenv("LANGUAGE", "en_US.UTF8") |
| os.Unsetenv("GO111MODULE") |
| os.Setenv("GOENV", "off") |
| os.Unsetenv("GOFLAGS") |
| os.Setenv("GOWORK", "off") |
|
|
| |
| |
| |
| modVer := goModVersion() |
| workdir = xworkdir() |
| if err := os.WriteFile(pathf("%s/go.mod", workdir), []byte("module bootstrap\n\ngo "+modVer+"\n"), 0666); err != nil { |
| fatalf("cannot write stub go.mod: %s", err) |
| } |
| xatexit(rmworkdir) |
|
|
| tooldir = pathf("%s/pkg/tool/%s_%s", goroot, gohostos, gohostarch) |
|
|
| goversion := findgoversion() |
| isRelease = (strings.HasPrefix(goversion, "release.") || strings.HasPrefix(goversion, "go")) && |
| !strings.Contains(goversion, "devel") |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| func compilerEnv(envName, def string) map[string]string { |
| m := map[string]string{"": def} |
|
|
| if env := os.Getenv(envName); env != "" { |
| m[""] = env |
| } |
| if env := os.Getenv(envName + "_FOR_TARGET"); env != "" { |
| if gohostos != goos || gohostarch != goarch { |
| m[gohostos+"/"+gohostarch] = m[""] |
| } |
| m[""] = env |
| } |
|
|
| for _, goos := range okgoos { |
| for _, goarch := range okgoarch { |
| if env := os.Getenv(envName + "_FOR_" + goos + "_" + goarch); env != "" { |
| m[goos+"/"+goarch] = env |
| } |
| } |
| } |
|
|
| return m |
| } |
|
|
| |
| var clangos = []string{ |
| "darwin", "ios", |
| "freebsd", |
| "openbsd", |
| } |
|
|
| |
| |
| func compilerEnvLookup(kind string, m map[string]string, goos, goarch string) string { |
| if !needCC() { |
| return "" |
| } |
| if cc := m[goos+"/"+goarch]; cc != "" { |
| return cc |
| } |
| if cc := m[""]; cc != "" { |
| return cc |
| } |
| for _, os := range clangos { |
| if goos == os { |
| if kind == "CXX" { |
| return "clang++" |
| } |
| return "clang" |
| } |
| } |
| if kind == "CXX" { |
| return "g++" |
| } |
| return "gcc" |
| } |
|
|
| |
| func rmworkdir() { |
| if vflag > 1 { |
| errprintf("rm -rf %s\n", workdir) |
| } |
| xremoveall(workdir) |
| } |
|
|
| |
| func chomp(s string) string { |
| return strings.TrimRight(s, " \t\r\n") |
| } |
|
|
| |
| |
| func findgoversion() string { |
| |
| |
| path := pathf("%s/VERSION", goroot) |
| if isfile(path) { |
| b := chomp(readfile(path)) |
|
|
| |
| |
| |
| if i := strings.Index(b, "\n"); i >= 0 { |
| rest := b[i+1:] |
| b = chomp(b[:i]) |
| for line := range strings.SplitSeq(rest, "\n") { |
| f := strings.Fields(line) |
| if len(f) == 0 { |
| continue |
| } |
| switch f[0] { |
| default: |
| fatalf("VERSION: unexpected line: %s", line) |
| case "time": |
| if len(f) != 2 { |
| fatalf("VERSION: unexpected time line: %s", line) |
| } |
| _, err := time.Parse(time.RFC3339, f[1]) |
| if err != nil { |
| fatalf("VERSION: bad time: %s", err) |
| } |
| } |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| if b != "" { |
| return b |
| } |
| } |
|
|
| |
| |
| |
| path = pathf("%s/VERSION.cache", goroot) |
| if isfile(path) { |
| return chomp(readfile(path)) |
| } |
|
|
| |
| if !isGitRepo() { |
| fatalf("FAILED: not a Git repo; must put a VERSION file in $GOROOT") |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| goversionSource := readfile(pathf("%s/src/internal/goversion/goversion.go", goroot)) |
| m := regexp.MustCompile(`(?m)^const Version = (\d+)`).FindStringSubmatch(goversionSource) |
| if m == nil { |
| fatalf("internal/goversion/goversion.go does not contain 'const Version = ...'") |
| } |
| version := fmt.Sprintf("go1.%s-devel_", m[1]) |
| version += chomp(run(goroot, CheckExit, "git", "log", "-n", "1", "--format=format:%h %cd", "HEAD")) |
|
|
| |
| writefile(version, path, 0) |
|
|
| return version |
| } |
|
|
| |
| |
| |
| func goModVersion() string { |
| goMod := readfile(pathf("%s/src/go.mod", goroot)) |
| m := regexp.MustCompile(`(?m)^go (1.\d+)$`).FindStringSubmatch(goMod) |
| if m == nil { |
| fatalf("std go.mod does not contain go 1.X") |
| } |
| return m[1] |
| } |
|
|
| func requiredBootstrapVersion(v string) string { |
| minorstr, ok := strings.CutPrefix(v, "1.") |
| if !ok { |
| fatalf("go version %q in go.mod does not start with %q", v, "1.") |
| } |
| minor, err := strconv.Atoi(minorstr) |
| if err != nil { |
| fatalf("invalid go version minor component %q: %v", minorstr, err) |
| } |
| |
| |
| requiredMinor := minor - 2 - minor%2 |
| return "1." + strconv.Itoa(requiredMinor) |
| } |
|
|
| |
| func isGitRepo() bool { |
| |
| |
| |
| gitDir := chomp(run(goroot, 0, "git", "rev-parse", "--git-dir")) |
| if !filepath.IsAbs(gitDir) { |
| gitDir = filepath.Join(goroot, gitDir) |
| } |
| return isdir(gitDir) |
| } |
|
|
| |
| |
| |
|
|
| |
| var oldtool = []string{ |
| "5a", "5c", "5g", "5l", |
| "6a", "6c", "6g", "6l", |
| "8a", "8c", "8g", "8l", |
| "9a", "9c", "9g", "9l", |
| "6cov", |
| "6nm", |
| "6prof", |
| "cgo", |
| "ebnflint", |
| "goapi", |
| "gofix", |
| "goinstall", |
| "gomake", |
| "gopack", |
| "gopprof", |
| "gotest", |
| "gotype", |
| "govet", |
| "goyacc", |
| "quietgcc", |
| } |
|
|
| |
| |
| var unreleased = []string{ |
| "src/cmd/newlink", |
| "src/cmd/objwriter", |
| "src/debug/goobj", |
| "src/old", |
| } |
|
|
| |
| func setup() { |
| |
| if p := pathf("%s/bin", goroot); !isdir(p) { |
| xmkdir(p) |
| } |
|
|
| |
| if p := pathf("%s/pkg", goroot); !isdir(p) { |
| xmkdir(p) |
| } |
|
|
| goosGoarch := pathf("%s/pkg/%s_%s", goroot, gohostos, gohostarch) |
| if rebuildall { |
| xremoveall(goosGoarch) |
| } |
| xmkdirall(goosGoarch) |
| xatexit(func() { |
| if files := xreaddir(goosGoarch); len(files) == 0 { |
| xremove(goosGoarch) |
| } |
| }) |
|
|
| if goos != gohostos || goarch != gohostarch { |
| p := pathf("%s/pkg/%s_%s", goroot, goos, goarch) |
| if rebuildall { |
| xremoveall(p) |
| } |
| xmkdirall(p) |
| } |
|
|
| |
| |
| |
| |
| |
| obj := pathf("%s/pkg/obj", goroot) |
| if !isdir(obj) { |
| xmkdir(obj) |
| } |
| xatexit(func() { xremove(obj) }) |
|
|
| |
| objGobuild := pathf("%s/pkg/obj/go-build", goroot) |
| if rebuildall { |
| xremoveall(objGobuild) |
| } |
| xmkdirall(objGobuild) |
| xatexit(func() { xremoveall(objGobuild) }) |
|
|
| |
| objGoBootstrap := pathf("%s/pkg/obj/go-bootstrap", goroot) |
| if rebuildall { |
| xremoveall(objGoBootstrap) |
| } |
| xmkdirall(objGoBootstrap) |
| xatexit(func() { xremoveall(objGoBootstrap) }) |
|
|
| |
| |
| if rebuildall { |
| xremoveall(tooldir) |
| } |
| xmkdirall(tooldir) |
|
|
| |
| xremoveall(pathf("%s/bin/tool", goroot)) |
|
|
| |
| for _, old := range oldtool { |
| xremove(pathf("%s/bin/%s", goroot, old)) |
| } |
|
|
| |
| if isRelease { |
| |
| for _, dir := range unreleased { |
| if p := pathf("%s/%s", goroot, dir); isdir(p) { |
| fatalf("%s should not exist in release build", p) |
| } |
| } |
| } |
| } |
|
|
| |
| |
| |
|
|
| |
| |
| |
| func mustLinkExternal(goos, goarch string, cgoEnabled bool) bool { |
| if cgoEnabled { |
| switch goarch { |
| case "mips", "mipsle", "mips64", "mips64le": |
| |
| |
| return true |
| case "ppc64": |
| |
| if goos == "aix" || goos == "linux" { |
| return true |
| } |
| } |
|
|
| switch goos { |
| case "android": |
| return true |
| case "dragonfly": |
| |
| |
| |
| return true |
| } |
| } |
|
|
| switch goos { |
| case "android": |
| if goarch != "arm64" { |
| return true |
| } |
| case "ios": |
| if goarch == "arm64" { |
| return true |
| } |
| } |
| return false |
| } |
|
|
| |
| var depsuffix = []string{ |
| ".s", |
| ".go", |
| } |
|
|
| |
| |
| var gentab = []struct { |
| pkg string |
| file string |
| gen func(dir, file string) |
| }{ |
| {"cmd/go/internal/cfg", "zdefaultcc.go", mkzdefaultcc}, |
| {"internal/runtime/sys", "zversion.go", mkzversion}, |
| {"time/tzdata", "zzipdata.go", mktzdata}, |
| } |
|
|
| |
| |
| var installed = make(map[string]chan struct{}) |
| var installedMu sync.Mutex |
|
|
| func install(dir string) { |
| <-startInstall(dir) |
| } |
|
|
| func startInstall(dir string) chan struct{} { |
| installedMu.Lock() |
| ch := installed[dir] |
| if ch == nil { |
| ch = make(chan struct{}) |
| installed[dir] = ch |
| go runInstall(dir, ch) |
| } |
| installedMu.Unlock() |
| return ch |
| } |
|
|
| |
| |
| func runInstall(pkg string, ch chan struct{}) { |
| if pkg == "net" || pkg == "os/user" || pkg == "crypto/x509" { |
| fatalf("go_bootstrap cannot depend on cgo package %s", pkg) |
| } |
|
|
| defer close(ch) |
|
|
| if pkg == "unsafe" { |
| return |
| } |
|
|
| if vflag > 0 { |
| if goos != gohostos || goarch != gohostarch { |
| errprintf("%s (%s/%s)\n", pkg, goos, goarch) |
| } else { |
| errprintf("%s\n", pkg) |
| } |
| } |
|
|
| workdir := pathf("%s/%s", workdir, pkg) |
| xmkdirall(workdir) |
|
|
| var clean []string |
| defer func() { |
| for _, name := range clean { |
| xremove(name) |
| } |
| }() |
|
|
| |
| dir := pathf("%s/src/%s", goroot, pkg) |
| name := filepath.Base(dir) |
|
|
| |
| |
| |
| ispkg := !strings.HasPrefix(pkg, "cmd/") || strings.Contains(pkg, "/internal/") || strings.Contains(pkg, "/vendor/") |
|
|
| |
| |
| var ( |
| link []string |
| targ int |
| ispackcmd bool |
| ) |
| if ispkg { |
| |
| ispackcmd = true |
| link = []string{"pack", packagefile(pkg)} |
| targ = len(link) - 1 |
| xmkdirall(filepath.Dir(link[targ])) |
| } else { |
| |
| elem := name |
| if elem == "go" { |
| elem = "go_bootstrap" |
| } |
| link = []string{pathf("%s/link", tooldir)} |
| if goos == "android" { |
| link = append(link, "-buildmode=pie") |
| } |
| if goldflags != "" { |
| link = append(link, goldflags) |
| } |
| link = append(link, "-extld="+compilerEnvLookup("CC", defaultcc, goos, goarch)) |
| link = append(link, "-L="+pathf("%s/pkg/obj/go-bootstrap/%s_%s", goroot, goos, goarch)) |
| link = append(link, "-o", pathf("%s/%s%s", tooldir, elem, exe)) |
| targ = len(link) - 1 |
| } |
| ttarg := mtime(link[targ]) |
|
|
| |
| |
| |
| files := xreaddir(dir) |
|
|
| |
| |
| |
| |
| |
| files = filter(files, func(p string) bool { |
| return !strings.HasPrefix(p, ".") && (!strings.HasPrefix(p, "_") || !strings.HasSuffix(p, ".go")) |
| }) |
|
|
| |
| for _, gt := range gentab { |
| if gt.pkg == pkg { |
| files = append(files, gt.file) |
| } |
| } |
| files = uniq(files) |
|
|
| |
| for i, p := range files { |
| if !filepath.IsAbs(p) { |
| files[i] = pathf("%s/%s", dir, p) |
| } |
| } |
|
|
| |
| var gofiles, sfiles []string |
| stale := rebuildall |
| files = filter(files, func(p string) bool { |
| for _, suf := range depsuffix { |
| if strings.HasSuffix(p, suf) { |
| goto ok |
| } |
| } |
| return false |
| ok: |
| t := mtime(p) |
| if !t.IsZero() && !strings.HasSuffix(p, ".a") && !shouldbuild(p, pkg) { |
| return false |
| } |
| if strings.HasSuffix(p, ".go") { |
| gofiles = append(gofiles, p) |
| } else if strings.HasSuffix(p, ".s") { |
| sfiles = append(sfiles, p) |
| } |
| if t.After(ttarg) { |
| stale = true |
| } |
| return true |
| }) |
|
|
| |
| if len(files) == 0 { |
| return |
| } |
|
|
| if !stale { |
| return |
| } |
|
|
| |
| if pkg == "runtime" { |
| xmkdirall(pathf("%s/pkg/include", goroot)) |
| |
| copyfile(pathf("%s/pkg/include/textflag.h", goroot), |
| pathf("%s/src/runtime/textflag.h", goroot), 0) |
| copyfile(pathf("%s/pkg/include/funcdata.h", goroot), |
| pathf("%s/src/runtime/funcdata.h", goroot), 0) |
| copyfile(pathf("%s/pkg/include/asm_ppc64x.h", goroot), |
| pathf("%s/src/runtime/asm_ppc64x.h", goroot), 0) |
| copyfile(pathf("%s/pkg/include/asm_amd64.h", goroot), |
| pathf("%s/src/runtime/asm_amd64.h", goroot), 0) |
| copyfile(pathf("%s/pkg/include/asm_riscv64.h", goroot), |
| pathf("%s/src/runtime/asm_riscv64.h", goroot), 0) |
| } |
|
|
| |
| for _, gt := range gentab { |
| if gt.pkg != pkg { |
| continue |
| } |
| p := pathf("%s/%s", dir, gt.file) |
| if vflag > 1 { |
| errprintf("generate %s\n", p) |
| } |
| gt.gen(dir, p) |
| |
| |
| |
| |
| |
| |
| |
| } |
|
|
| |
| |
| importMap := make(map[string]string) |
| for _, p := range gofiles { |
| for _, imp := range readimports(p) { |
| if imp == "C" { |
| fatalf("%s imports C", p) |
| } |
| importMap[imp] = resolveVendor(imp, dir) |
| } |
| } |
| sortedImports := make([]string, 0, len(importMap)) |
| for imp := range importMap { |
| sortedImports = append(sortedImports, imp) |
| } |
| sort.Strings(sortedImports) |
|
|
| for _, dep := range importMap { |
| if dep == "C" { |
| fatalf("%s imports C", pkg) |
| } |
| startInstall(dep) |
| } |
| for _, dep := range importMap { |
| install(dep) |
| } |
|
|
| if goos != gohostos || goarch != gohostarch { |
| |
| if vflag > 1 { |
| errprintf("skip build for cross-compile %s\n", pkg) |
| } |
| return |
| } |
|
|
| asmArgs := []string{ |
| pathf("%s/asm", tooldir), |
| "-I", workdir, |
| "-I", pathf("%s/pkg/include", goroot), |
| "-D", "GOOS_" + goos, |
| "-D", "GOARCH_" + goarch, |
| "-D", "GOOS_GOARCH_" + goos + "_" + goarch, |
| "-p", pkg, |
| } |
| if goarch == "mips" || goarch == "mipsle" { |
| |
| asmArgs = append(asmArgs, "-D", "GOMIPS_"+gomips) |
| } |
| if goarch == "mips64" || goarch == "mips64le" { |
| |
| asmArgs = append(asmArgs, "-D", "GOMIPS64_"+gomips64) |
| } |
| if goarch == "ppc64" || goarch == "ppc64le" { |
| |
| switch goppc64 { |
| case "power10": |
| asmArgs = append(asmArgs, "-D", "GOPPC64_power10") |
| fallthrough |
| case "power9": |
| asmArgs = append(asmArgs, "-D", "GOPPC64_power9") |
| fallthrough |
| default: |
| asmArgs = append(asmArgs, "-D", "GOPPC64_power8") |
| } |
| } |
| if goarch == "riscv64" { |
| |
| asmArgs = append(asmArgs, "-D", "GORISCV64_"+goriscv64) |
| } |
| if goarch == "arm" { |
| |
| |
| switch { |
| case strings.Contains(goarm, "7"): |
| asmArgs = append(asmArgs, "-D", "GOARM_7") |
| fallthrough |
| case strings.Contains(goarm, "6"): |
| asmArgs = append(asmArgs, "-D", "GOARM_6") |
| fallthrough |
| default: |
| asmArgs = append(asmArgs, "-D", "GOARM_5") |
| } |
| } |
| goasmh := pathf("%s/go_asm.h", workdir) |
|
|
| |
| var symabis string |
| if len(sfiles) > 0 { |
| symabis = pathf("%s/symabis", workdir) |
| var wg sync.WaitGroup |
| asmabis := append(asmArgs[:len(asmArgs):len(asmArgs)], "-gensymabis", "-o", symabis) |
| asmabis = append(asmabis, sfiles...) |
| if err := os.WriteFile(goasmh, nil, 0666); err != nil { |
| fatalf("cannot write empty go_asm.h: %s", err) |
| } |
| bgrun(&wg, dir, asmabis...) |
| bgwait(&wg) |
| } |
|
|
| |
| buf := &bytes.Buffer{} |
| for _, imp := range sortedImports { |
| if imp == "unsafe" { |
| continue |
| } |
| dep := importMap[imp] |
| if imp != dep { |
| fmt.Fprintf(buf, "importmap %s=%s\n", imp, dep) |
| } |
| fmt.Fprintf(buf, "packagefile %s=%s\n", dep, packagefile(dep)) |
| } |
| importcfg := pathf("%s/importcfg", workdir) |
| if err := os.WriteFile(importcfg, buf.Bytes(), 0666); err != nil { |
| fatalf("cannot write importcfg file: %v", err) |
| } |
|
|
| var archive string |
| |
| |
| |
| |
| pkgName := pkg |
| if strings.HasPrefix(pkg, "cmd/") && strings.Count(pkg, "/") == 1 { |
| pkgName = "main" |
| } |
| b := pathf("%s/_go_.a", workdir) |
| clean = append(clean, b) |
| if !ispackcmd { |
| link = append(link, b) |
| } else { |
| archive = b |
| } |
|
|
| |
| compile := []string{pathf("%s/compile", tooldir), "-std", "-pack", "-o", b, "-p", pkgName, "-importcfg", importcfg} |
| if gogcflags != "" { |
| compile = append(compile, strings.Fields(gogcflags)...) |
| } |
| if len(sfiles) > 0 { |
| compile = append(compile, "-asmhdr", goasmh) |
| } |
| if symabis != "" { |
| compile = append(compile, "-symabis", symabis) |
| } |
| if goos == "android" { |
| compile = append(compile, "-shared") |
| } |
|
|
| compile = append(compile, gofiles...) |
| var wg sync.WaitGroup |
| |
| |
| |
| bgrun(&wg, dir, compile...) |
| bgwait(&wg) |
|
|
| |
| for _, p := range sfiles { |
| |
| compile := asmArgs[:len(asmArgs):len(asmArgs)] |
|
|
| doclean := true |
| b := pathf("%s/%s", workdir, filepath.Base(p)) |
|
|
| |
| b = b[:len(b)-1] + "o" |
| compile = append(compile, "-o", b, p) |
| bgrun(&wg, dir, compile...) |
|
|
| link = append(link, b) |
| if doclean { |
| clean = append(clean, b) |
| } |
| } |
| bgwait(&wg) |
|
|
| if ispackcmd { |
| xremove(link[targ]) |
| dopack(link[targ], archive, link[targ+1:]) |
| return |
| } |
|
|
| |
| xremove(link[targ]) |
| bgrun(&wg, "", link...) |
| bgwait(&wg) |
| } |
|
|
| |
| |
| func packagefile(pkg string) string { |
| return pathf("%s/pkg/obj/go-bootstrap/%s_%s/%s.a", goroot, goos, goarch, pkg) |
| } |
|
|
| |
| |
| var unixOS = map[string]bool{ |
| "aix": true, |
| "android": true, |
| "darwin": true, |
| "dragonfly": true, |
| "freebsd": true, |
| "hurd": true, |
| "illumos": true, |
| "ios": true, |
| "linux": true, |
| "netbsd": true, |
| "openbsd": true, |
| "solaris": true, |
| } |
|
|
| |
| func matchtag(tag string) bool { |
| switch tag { |
| case "gc", "cmd_go_bootstrap", "go1.1": |
| return true |
| case "linux": |
| return goos == "linux" || goos == "android" |
| case "solaris": |
| return goos == "solaris" || goos == "illumos" |
| case "darwin": |
| return goos == "darwin" || goos == "ios" |
| case goos, goarch: |
| return true |
| case "unix": |
| return unixOS[goos] |
| default: |
| return false |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| func shouldbuild(file, pkg string) bool { |
| |
| name := filepath.Base(file) |
| excluded := func(list []string, ok string) bool { |
| for _, x := range list { |
| if x == ok || (ok == "android" && x == "linux") || (ok == "illumos" && x == "solaris") || (ok == "ios" && x == "darwin") { |
| continue |
| } |
| i := strings.Index(name, x) |
| if i <= 0 || name[i-1] != '_' { |
| continue |
| } |
| i += len(x) |
| if i == len(name) || name[i] == '.' || name[i] == '_' { |
| return true |
| } |
| } |
| return false |
| } |
| if excluded(okgoos, goos) || excluded(okgoarch, goarch) { |
| return false |
| } |
|
|
| |
| if strings.Contains(name, "_test") { |
| return false |
| } |
|
|
| |
| for p := range strings.SplitSeq(readfile(file), "\n") { |
| p = strings.TrimSpace(p) |
| if p == "" { |
| continue |
| } |
| code := p |
| i := strings.Index(code, "//") |
| if i > 0 { |
| code = strings.TrimSpace(code[:i]) |
| } |
| if code == "package documentation" { |
| return false |
| } |
| if code == "package main" && pkg != "cmd/go" && pkg != "cmd/cgo" { |
| return false |
| } |
| if !strings.HasPrefix(p, "//") { |
| break |
| } |
| if strings.HasPrefix(p, "//go:build ") { |
| matched, err := matchexpr(p[len("//go:build "):]) |
| if err != nil { |
| errprintf("%s: %v", file, err) |
| } |
| return matched |
| } |
| } |
|
|
| return true |
| } |
|
|
| |
| func copyfile(dst, src string, flag int) { |
| if vflag > 1 { |
| errprintf("cp %s %s\n", src, dst) |
| } |
| writefile(readfile(src), dst, flag) |
| } |
|
|
| |
| |
| |
| func dopack(dst, src string, extra []string) { |
| bdst := bytes.NewBufferString(readfile(src)) |
| for _, file := range extra { |
| b := readfile(file) |
| |
| i := strings.LastIndex(file, "/") + 1 |
| j := strings.LastIndex(file, `\`) + 1 |
| if i < j { |
| i = j |
| } |
| fmt.Fprintf(bdst, "%-16.16s%-12d%-6d%-6d%-8o%-10d`\n", file[i:], 0, 0, 0, 0644, len(b)) |
| bdst.WriteString(b) |
| if len(b)&1 != 0 { |
| bdst.WriteByte(0) |
| } |
| } |
| writefile(bdst.String(), dst, 0) |
| } |
|
|
| func clean() { |
| generated := []byte(generatedHeader) |
|
|
| |
| filepath.WalkDir(pathf("%s/src", goroot), func(path string, d fs.DirEntry, err error) error { |
| switch { |
| case err != nil: |
| |
| case d.IsDir() && (d.Name() == "vendor" || d.Name() == "testdata"): |
| return filepath.SkipDir |
| case d.IsDir() && d.Name() != "dist": |
| |
| exe := filepath.Join(path, d.Name()) |
| if info, err := os.Stat(exe); err == nil && !info.IsDir() { |
| xremove(exe) |
| } |
| xremove(exe + ".exe") |
| case !d.IsDir() && strings.HasPrefix(d.Name(), "z"): |
| |
| head := make([]byte, 512) |
| if f, err := os.Open(path); err == nil { |
| io.ReadFull(f, head) |
| f.Close() |
| } |
| if bytes.HasPrefix(head, generated) { |
| xremove(path) |
| } |
| } |
| return nil |
| }) |
|
|
| if rebuildall { |
| |
| xremoveall(pathf("%s/pkg/obj/%s_%s", goroot, gohostos, gohostarch)) |
|
|
| |
| xremoveall(pathf("%s/pkg/%s_%s", goroot, gohostos, gohostarch)) |
| xremoveall(pathf("%s/pkg/%s_%s", goroot, goos, goarch)) |
| xremoveall(pathf("%s/pkg/%s_%s_race", goroot, gohostos, gohostarch)) |
| xremoveall(pathf("%s/pkg/%s_%s_race", goroot, goos, goarch)) |
| xremoveall(tooldir) |
|
|
| |
| xremove(pathf("%s/VERSION.cache", goroot)) |
|
|
| |
| xremoveall(pathf("%s/pkg/distpack", goroot)) |
| } |
| } |
|
|
| |
| |
| |
|
|
| |
| func cmdenv() { |
| path := flag.Bool("p", false, "emit updated PATH") |
| plan9 := flag.Bool("9", gohostos == "plan9", "emit plan 9 syntax") |
| windows := flag.Bool("w", gohostos == "windows", "emit windows syntax") |
| xflagparse(0) |
|
|
| format := "%s=\"%s\";\n" |
| switch { |
| case *plan9: |
| format = "%s='%s'\n" |
| case *windows: |
| format = "set %s=%s\r\n" |
| } |
|
|
| xprintf(format, "GO111MODULE", "") |
| xprintf(format, "GOARCH", goarch) |
| xprintf(format, "GOBIN", gorootBin) |
| xprintf(format, "GODEBUG", os.Getenv("GODEBUG")) |
| xprintf(format, "GOENV", "off") |
| xprintf(format, "GOFLAGS", "") |
| xprintf(format, "GOHOSTARCH", gohostarch) |
| xprintf(format, "GOHOSTOS", gohostos) |
| xprintf(format, "GOOS", goos) |
| xprintf(format, "GOPROXY", os.Getenv("GOPROXY")) |
| xprintf(format, "GOROOT", goroot) |
| xprintf(format, "GOTMPDIR", os.Getenv("GOTMPDIR")) |
| xprintf(format, "GOTOOLDIR", tooldir) |
| if goarch == "arm" { |
| xprintf(format, "GOARM", goarm) |
| } |
| if goarch == "arm64" { |
| xprintf(format, "GOARM64", goarm64) |
| } |
| if goarch == "386" { |
| xprintf(format, "GO386", go386) |
| } |
| if goarch == "amd64" { |
| xprintf(format, "GOAMD64", goamd64) |
| } |
| if goarch == "mips" || goarch == "mipsle" { |
| xprintf(format, "GOMIPS", gomips) |
| } |
| if goarch == "mips64" || goarch == "mips64le" { |
| xprintf(format, "GOMIPS64", gomips64) |
| } |
| if goarch == "ppc64" || goarch == "ppc64le" { |
| xprintf(format, "GOPPC64", goppc64) |
| } |
| if goarch == "riscv64" { |
| xprintf(format, "GORISCV64", goriscv64) |
| } |
| xprintf(format, "GOWORK", "off") |
|
|
| if *path { |
| sep := ":" |
| if gohostos == "windows" { |
| sep = ";" |
| } |
| xprintf(format, "PATH", fmt.Sprintf("%s%s%s", gorootBin, sep, os.Getenv("PATH"))) |
|
|
| |
| |
| |
| var exportFormat string |
| if !*windows && !*plan9 { |
| exportFormat = "export " + format |
| } else { |
| exportFormat = format |
| } |
| xprintf(exportFormat, "DIST_UNMODIFIED_PATH", os.Getenv("PATH")) |
| } |
| } |
|
|
| var ( |
| timeLogEnabled = os.Getenv("GOBUILDTIMELOGFILE") != "" |
| timeLogMu sync.Mutex |
| timeLogFile *os.File |
| timeLogStart time.Time |
| ) |
|
|
| func timelog(op, name string) { |
| if !timeLogEnabled { |
| return |
| } |
| timeLogMu.Lock() |
| defer timeLogMu.Unlock() |
| if timeLogFile == nil { |
| f, err := os.OpenFile(os.Getenv("GOBUILDTIMELOGFILE"), os.O_RDWR|os.O_APPEND, 0666) |
| if err != nil { |
| log.Fatal(err) |
| } |
| buf := make([]byte, 100) |
| n, _ := f.Read(buf) |
| s := string(buf[:n]) |
| if i := strings.Index(s, "\n"); i >= 0 { |
| s = s[:i] |
| } |
| i := strings.Index(s, " start") |
| if i < 0 { |
| log.Fatalf("time log %s does not begin with start line", os.Getenv("GOBUILDTIMELOGFILE")) |
| } |
| t, err := time.Parse(time.UnixDate, s[:i]) |
| if err != nil { |
| log.Fatalf("cannot parse time log line %q: %v", s, err) |
| } |
| timeLogStart = t |
| timeLogFile = f |
| } |
| t := time.Now() |
| fmt.Fprintf(timeLogFile, "%s %+.1fs %s %s\n", t.Format(time.UnixDate), t.Sub(timeLogStart).Seconds(), op, name) |
| } |
|
|
| |
| |
| |
| |
| |
| func toolenv() []string { |
| var env []string |
| if !mustLinkExternal(goos, goarch, false) { |
| |
| |
| |
| |
| env = append(env, "CGO_ENABLED=0") |
| } |
| if isRelease || os.Getenv("GO_BUILDER_NAME") != "" { |
| |
| |
| |
| |
| |
| env = append(env, "GOFLAGS=-trimpath -ldflags=-w -gcflags=cmd/...=-dwarf=false") |
| } |
| return env |
| } |
|
|
| var ( |
| toolchain = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/link", "cmd/preprofile"} |
|
|
| |
| binExesIncludedInDistpack = []string{"cmd/go", "cmd/gofmt"} |
|
|
| |
| toolsIncludedInDistpack = []string{"cmd/asm", "cmd/cgo", "cmd/compile", "cmd/cover", "cmd/fix", "cmd/link", "cmd/preprofile", "cmd/vet"} |
|
|
| |
| |
| |
| |
| toolsToInstall = slices.Concat(binExesIncludedInDistpack, toolsIncludedInDistpack) |
| ) |
|
|
| |
| |
| |
| |
| |
| |
| |
| func cmdbootstrap() { |
| timelog("start", "dist bootstrap") |
| defer timelog("end", "dist bootstrap") |
|
|
| var debug, distpack, force, noBanner, noClean bool |
| flag.BoolVar(&rebuildall, "a", rebuildall, "rebuild all") |
| flag.BoolVar(&debug, "d", debug, "enable debugging of bootstrap process") |
| flag.BoolVar(&distpack, "distpack", distpack, "write distribution files to pkg/distpack") |
| flag.BoolVar(&force, "force", force, "build even if the port is marked as broken") |
| flag.BoolVar(&noBanner, "no-banner", noBanner, "do not print banner") |
| flag.BoolVar(&noClean, "no-clean", noClean, "print deprecation warning") |
|
|
| xflagparse(0) |
|
|
| if noClean { |
| xprintf("warning: --no-clean is deprecated and has no effect; use 'go install std cmd' instead\n") |
| } |
|
|
| |
| if broken[goos+"/"+goarch] && !force { |
| fatalf("build stopped because the port %s/%s is marked as broken\n\n"+ |
| "Use the -force flag to build anyway.\n", goos, goarch) |
| } |
|
|
| |
| |
| |
| |
| |
| os.Setenv("GOPATH", pathf("%s/pkg/obj/gopath", goroot)) |
|
|
| |
| |
| |
| |
| os.Setenv("GOPROXY", "off") |
|
|
| |
| |
| |
| oldgocache = os.Getenv("GOCACHE") |
| os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot)) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| os.Setenv("GOEXPERIMENT", "none") |
|
|
| if isdir(pathf("%s/src/pkg", goroot)) { |
| fatalf("\n\n"+ |
| "The Go package sources have moved to $GOROOT/src.\n"+ |
| "*** %s still exists. ***\n"+ |
| "It probably contains stale files that may confuse the build.\n"+ |
| "Please (check what's there and) remove it and try again.\n"+ |
| "See https://golang.org/s/go14nopkg\n", |
| pathf("%s/src/pkg", goroot)) |
| } |
|
|
| if rebuildall { |
| clean() |
| } |
|
|
| setup() |
|
|
| timelog("build", "toolchain1") |
| checkCC() |
| bootstrapBuildTools() |
|
|
| |
| oldBinFiles, err := filepath.Glob(pathf("%s/bin/*", goroot)) |
| if err != nil { |
| fatalf("glob: %v", err) |
| } |
|
|
| |
| oldgoos = goos |
| oldgoarch = goarch |
| goos = gohostos |
| goarch = gohostarch |
| os.Setenv("GOHOSTARCH", gohostarch) |
| os.Setenv("GOHOSTOS", gohostos) |
| os.Setenv("GOARCH", goarch) |
| os.Setenv("GOOS", goos) |
|
|
| timelog("build", "go_bootstrap") |
| xprintf("Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.\n") |
| install("runtime") |
| install("time/tzdata") |
| install("cmd/go") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
|
|
| gogcflags = os.Getenv("GO_GCFLAGS") |
| setNoOpt() |
| goldflags = os.Getenv("GO_LDFLAGS") |
| goBootstrap := pathf("%s/go_bootstrap", tooldir) |
| if debug { |
| run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") |
| copyfile(pathf("%s/compile1", tooldir), pathf("%s/compile", tooldir), writeExec) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| timelog("build", "toolchain2") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| xprintf("Building Go toolchain2 using go_bootstrap and Go toolchain1.\n") |
| os.Setenv("CC", compilerEnvLookup("CC", defaultcc, goos, goarch)) |
| |
| os.Setenv("GOEXPERIMENT", goexperiment) |
| |
| goInstall(toolenv(), goBootstrap, append([]string{"-pgo=off"}, toolchain...)...) |
| if debug { |
| run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") |
| copyfile(pathf("%s/compile2", tooldir), pathf("%s/compile", tooldir), writeExec) |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| timelog("build", "toolchain3") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| xprintf("Building Go toolchain3 using go_bootstrap and Go toolchain2.\n") |
| goInstall(toolenv(), goBootstrap, append([]string{"-a"}, toolchain...)...) |
| if debug { |
| run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") |
| copyfile(pathf("%s/compile3", tooldir), pathf("%s/compile", tooldir), writeExec) |
| } |
|
|
| |
| |
| |
| |
| |
| if _, err := os.Stat(pathf("%s/VERSION", goroot)); err == nil { |
| |
| |
| |
| |
| |
| |
| } else { |
| os.Setenv("GOCACHE", oldgocache) |
| } |
|
|
| if goos == oldgoos && goarch == oldgoarch { |
| |
| timelog("build", "toolchain") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| xprintf("Building packages and commands for %s/%s.\n", goos, goarch) |
| } else { |
| |
| |
| |
| timelog("build", "host toolchain") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| xprintf("Building commands for host, %s/%s.\n", goos, goarch) |
| goInstall(toolenv(), goBootstrap, toolsToInstall...) |
| checkNotStale(toolenv(), goBootstrap, toolsToInstall...) |
| checkNotStale(toolenv(), gorootBinGo, toolsToInstall...) |
|
|
| timelog("build", "target toolchain") |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| goos = oldgoos |
| goarch = oldgoarch |
| os.Setenv("GOOS", goos) |
| os.Setenv("GOARCH", goarch) |
| os.Setenv("CC", compilerEnvLookup("CC", defaultcc, goos, goarch)) |
| xprintf("Building packages and commands for target, %s/%s.\n", goos, goarch) |
| } |
| goInstall(nil, goBootstrap, "std") |
| goInstall(toolenv(), goBootstrap, toolsToInstall...) |
| checkNotStale(toolenv(), goBootstrap, toolchain...) |
| checkNotStale(nil, goBootstrap, "std") |
| checkNotStale(toolenv(), goBootstrap, toolsToInstall...) |
| checkNotStale(nil, gorootBinGo, "std") |
| checkNotStale(toolenv(), gorootBinGo, toolsToInstall...) |
| if debug { |
| run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full") |
| checkNotStale(toolenv(), goBootstrap, toolchain...) |
| copyfile(pathf("%s/compile4", tooldir), pathf("%s/compile", tooldir), writeExec) |
| } |
|
|
| |
| |
| binFiles, err := filepath.Glob(pathf("%s/bin/*", goroot)) |
| if err != nil { |
| fatalf("glob: %v", err) |
| } |
|
|
| ok := map[string]bool{} |
| for _, f := range oldBinFiles { |
| ok[f] = true |
| } |
| for _, f := range binFiles { |
| if gohostos == "darwin" && filepath.Base(f) == ".DS_Store" { |
| continue |
| } |
| elem := strings.TrimSuffix(filepath.Base(f), ".exe") |
| if !ok[f] && elem != "go" && elem != "gofmt" && elem != goos+"_"+goarch { |
| fatalf("unexpected new file in $GOROOT/bin: %s", elem) |
| } |
| } |
|
|
| |
| xremove(pathf("%s/go_bootstrap"+exe, tooldir)) |
|
|
| if goos == "android" { |
| |
| xremove(pathf("%s/go_android_exec-adb-sync-status", os.TempDir())) |
| } |
|
|
| if wrapperPath := wrapperPathFor(goos, goarch); wrapperPath != "" { |
| oldcc := os.Getenv("CC") |
| os.Setenv("GOOS", gohostos) |
| os.Setenv("GOARCH", gohostarch) |
| os.Setenv("CC", compilerEnvLookup("CC", defaultcc, gohostos, gohostarch)) |
| goCmd(nil, gorootBinGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath) |
| |
| |
| os.Setenv("GOOS", goos) |
| os.Setenv("GOARCH", goarch) |
| os.Setenv("CC", oldcc) |
| } |
|
|
| if distpack { |
| xprintf("Packaging archives for %s/%s.\n", goos, goarch) |
| run("", ShowOutput|CheckExit, gorootBinGo, "tool", "distpack") |
| } |
|
|
| |
| if !noBanner { |
| banner() |
| } |
| } |
|
|
| func wrapperPathFor(goos, goarch string) string { |
| switch { |
| case goos == "android": |
| if gohostos != "android" { |
| return pathf("%s/misc/go_android_exec/main.go", goroot) |
| } |
| case goos == "ios": |
| if gohostos != "ios" { |
| return pathf("%s/misc/ios/go_ios_exec.go", goroot) |
| } |
| } |
| return "" |
| } |
|
|
| func goInstall(env []string, goBinary string, args ...string) { |
| goCmd(env, goBinary, "install", args...) |
| } |
|
|
| func appendCompilerFlags(args []string) []string { |
| if gogcflags != "" { |
| args = append(args, "-gcflags=all="+gogcflags) |
| } |
| if goldflags != "" { |
| args = append(args, "-ldflags=all="+goldflags) |
| } |
| return args |
| } |
|
|
| func goCmd(env []string, goBinary string, cmd string, args ...string) { |
| goCmd := []string{goBinary, cmd} |
| if noOpt { |
| goCmd = append(goCmd, "-tags=noopt") |
| } |
| goCmd = appendCompilerFlags(goCmd) |
| if vflag > 0 { |
| goCmd = append(goCmd, "-v") |
| } |
|
|
| |
| if gohostos == "plan9" && os.Getenv("sysname") == "vx32" { |
| goCmd = append(goCmd, "-p=1") |
| } |
|
|
| runEnv(workdir, ShowOutput|CheckExit, env, append(goCmd, args...)...) |
| } |
|
|
| func checkNotStale(env []string, goBinary string, targets ...string) { |
| goCmd := []string{goBinary, "list"} |
| if noOpt { |
| goCmd = append(goCmd, "-tags=noopt") |
| } |
| goCmd = appendCompilerFlags(goCmd) |
| goCmd = append(goCmd, "-f={{if .Stale}}\tSTALE {{.ImportPath}}: {{.StaleReason}}{{end}}") |
|
|
| out := runEnv(workdir, CheckExit, env, append(goCmd, targets...)...) |
| if strings.Contains(out, "\tSTALE ") { |
| os.Setenv("GODEBUG", "gocachehash=1") |
| for _, target := range []string{"internal/runtime/sys", "cmd/dist", "cmd/link"} { |
| if strings.Contains(out, "STALE "+target) { |
| run(workdir, ShowOutput|CheckExit, goBinary, "list", "-f={{.ImportPath}} {{.Stale}}", target) |
| break |
| } |
| } |
| fatalf("unexpected stale targets reported by %s list -gcflags=\"%s\" -ldflags=\"%s\" for %v (consider rerunning with GOMAXPROCS=1 GODEBUG=gocachehash=1):\n%s", goBinary, gogcflags, goldflags, targets, out) |
| } |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| var cgoEnabled = map[string]bool{ |
| "aix/ppc64": true, |
| "darwin/amd64": true, |
| "darwin/arm64": true, |
| "dragonfly/amd64": true, |
| "freebsd/386": true, |
| "freebsd/amd64": true, |
| "freebsd/arm": true, |
| "freebsd/arm64": true, |
| "freebsd/riscv64": true, |
| "illumos/amd64": true, |
| "linux/386": true, |
| "linux/amd64": true, |
| "linux/arm": true, |
| "linux/arm64": true, |
| "linux/loong64": true, |
| "linux/ppc64": false, |
| "linux/ppc64le": true, |
| "linux/mips": true, |
| "linux/mipsle": true, |
| "linux/mips64": true, |
| "linux/mips64le": true, |
| "linux/riscv64": true, |
| "linux/s390x": true, |
| "linux/sparc64": true, |
| "android/386": true, |
| "android/amd64": true, |
| "android/arm": true, |
| "android/arm64": true, |
| "ios/arm64": true, |
| "ios/amd64": true, |
| "js/wasm": false, |
| "wasip1/wasm": false, |
| "netbsd/386": true, |
| "netbsd/amd64": true, |
| "netbsd/arm": true, |
| "netbsd/arm64": true, |
| "openbsd/386": true, |
| "openbsd/amd64": true, |
| "openbsd/arm": true, |
| "openbsd/arm64": true, |
| "openbsd/mips64": true, |
| "openbsd/ppc64": false, |
| "openbsd/riscv64": true, |
| "plan9/386": false, |
| "plan9/amd64": false, |
| "plan9/arm": false, |
| "solaris/amd64": true, |
| "windows/386": true, |
| "windows/amd64": true, |
| "windows/arm64": true, |
| } |
|
|
| |
| |
| |
| |
| var broken = map[string]bool{ |
| "freebsd/riscv64": true, |
| "linux/sparc64": true, |
| "openbsd/mips64": true, |
| } |
|
|
| |
| var firstClass = map[string]bool{ |
| "darwin/amd64": true, |
| "darwin/arm64": true, |
| "linux/386": true, |
| "linux/amd64": true, |
| "linux/arm": true, |
| "linux/arm64": true, |
| "windows/386": true, |
| "windows/amd64": true, |
| } |
|
|
| |
| |
| func needCC() bool { |
| return os.Getenv("CGO_ENABLED") == "1" || mustLinkExternal(gohostos, gohostarch, false) |
| } |
|
|
| func checkCC() { |
| if !needCC() { |
| return |
| } |
| cc1 := defaultcc[""] |
| if cc1 == "" { |
| cc1 = "gcc" |
| for _, os := range clangos { |
| if gohostos == os { |
| cc1 = "clang" |
| break |
| } |
| } |
| } |
| cc, err := quotedSplit(cc1) |
| if err != nil { |
| fatalf("split CC: %v", err) |
| } |
| var ccHelp = append(cc, "--help") |
|
|
| if output, err := exec.Command(ccHelp[0], ccHelp[1:]...).CombinedOutput(); err != nil { |
| outputHdr := "" |
| if len(output) > 0 { |
| outputHdr = "\nCommand output:\n\n" |
| } |
| fatalf("cannot invoke C compiler %q: %v\n\n"+ |
| "Go needs a system C compiler for use with cgo.\n"+ |
| "To set a C compiler, set CC=the-compiler.\n"+ |
| "To disable cgo, set CGO_ENABLED=0.\n%s%s", cc, err, outputHdr, output) |
| } |
| } |
|
|
| func defaulttarg() string { |
| |
| |
| |
| |
| pwd := xgetwd() |
| src := pathf("%s/src/", goroot) |
| real_src := xrealwd(src) |
| if !strings.HasPrefix(pwd, real_src) { |
| fatalf("current directory %s is not under %s", pwd, real_src) |
| } |
| pwd = pwd[len(real_src):] |
| |
| pwd = strings.TrimPrefix(pwd, "/") |
|
|
| return pwd |
| } |
|
|
| |
| func cmdinstall() { |
| xflagparse(-1) |
|
|
| if flag.NArg() == 0 { |
| install(defaulttarg()) |
| } |
|
|
| for _, arg := range flag.Args() { |
| install(arg) |
| } |
| } |
|
|
| |
| func cmdclean() { |
| xflagparse(0) |
| clean() |
| } |
|
|
| |
| func cmdbanner() { |
| xflagparse(0) |
| banner() |
| } |
|
|
| func banner() { |
| if vflag > 0 { |
| xprintf("\n") |
| } |
| xprintf("---\n") |
| xprintf("Installed Go for %s/%s in %s\n", goos, goarch, goroot) |
| xprintf("Installed commands in %s\n", gorootBin) |
|
|
| if gohostos == "plan9" { |
| |
| pid := strings.ReplaceAll(readfile("#c/pid"), " ", "") |
| ns := fmt.Sprintf("/proc/%s/ns", pid) |
| if !strings.Contains(readfile(ns), fmt.Sprintf("bind -b %s /bin", gorootBin)) { |
| xprintf("*** You need to bind %s before /bin.\n", gorootBin) |
| } |
| } else { |
| |
| pathsep := ":" |
| if gohostos == "windows" { |
| pathsep = ";" |
| } |
| path := os.Getenv("PATH") |
| if p, ok := os.LookupEnv("DIST_UNMODIFIED_PATH"); ok { |
| |
| |
| |
| |
| path = p |
| } |
| if !strings.Contains(pathsep+path+pathsep, pathsep+gorootBin+pathsep) { |
| xprintf("*** You need to add %s to your PATH.\n", gorootBin) |
| } |
| } |
| } |
|
|
| |
| func cmdversion() { |
| xflagparse(0) |
| xprintf("%s\n", findgoversion()) |
| } |
|
|
| |
| func cmdlist() { |
| jsonFlag := flag.Bool("json", false, "produce JSON output") |
| brokenFlag := flag.Bool("broken", false, "include broken ports") |
| xflagparse(0) |
|
|
| var plats []string |
| for p := range cgoEnabled { |
| if broken[p] && !*brokenFlag { |
| continue |
| } |
| 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 |
| FirstClass bool |
| Broken bool `json:",omitempty"` |
| } |
| var results []jsonResult |
| for _, p := range plats { |
| fields := strings.Split(p, "/") |
| results = append(results, jsonResult{ |
| GOOS: fields[0], |
| GOARCH: fields[1], |
| CgoSupported: cgoEnabled[p], |
| FirstClass: firstClass[p], |
| Broken: broken[p], |
| }) |
| } |
| out, err := json.MarshalIndent(results, "", "\t") |
| if err != nil { |
| fatalf("json marshal error: %v", err) |
| } |
| if _, err := os.Stdout.Write(out); err != nil { |
| fatalf("write failed: %v", err) |
| } |
| } |
|
|
| func setNoOpt() { |
| for gcflag := range strings.SplitSeq(gogcflags, " ") { |
| if gcflag == "-N" || gcflag == "-l" { |
| noOpt = true |
| break |
| } |
| } |
| } |
|
|