// The usual variables.
var (
goarch string
- gobin string
+ gorootBin string
gohostarch string
gohostos string
goos string
fatalf("$GOROOT must be set")
}
goroot = filepath.Clean(b)
+ gorootBin = pathf("%s/bin", goroot)
b = os.Getenv("GOROOT_FINAL")
if b == "" {
}
goroot_final = b
- b = os.Getenv("GOBIN")
- if b == "" {
- b = pathf("%s/bin", goroot)
- }
- gobin = b
-
b = os.Getenv("GOOS")
if b == "" {
b = gohostos
// make.bash really does start from a clean slate.
os.Setenv("GOCACHE", pathf("%s/pkg/obj/go-build", goroot))
+ // Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
+ // (see https://go.dev/issue/3269, https://go.dev/cl/183058,
+ // https://go.dev/issue/31576). Since we want binaries installed by 'dist' to
+ // always go to GOROOT/bin anyway.
+ os.Setenv("GOBIN", gorootBin)
+
// Make the environment more predictable.
os.Setenv("LANG", "C")
os.Setenv("LANGUAGE", "en_US.UTF8")
+ os.Unsetenv("GO111MODULE")
+ os.Setenv("GOENV", "off")
+ os.Unsetenv("GOFLAGS")
+ os.Setenv("GOWORK", "off")
workdir = xworkdir()
if err := ioutil.WriteFile(pathf("%s/go.mod", workdir), []byte("module bootstrap"), 0666); err != nil {
xremove(pathf("%s/bin/%s", goroot, old))
}
- // If $GOBIN is set and has a Go compiler, it must be cleaned.
- for _, char := range "56789" {
- if isfile(pathf("%s/%c%s", gobin, char, "g")) {
- for _, old := range oldtool {
- xremove(pathf("%s/%s", gobin, old))
- }
- break
- }
- }
-
// For release, make sure excluded things are excluded.
goversion := findgoversion()
if strings.HasPrefix(goversion, "release.") || (strings.HasPrefix(goversion, "go") && !strings.Contains(goversion, "beta")) {
// The env command prints the default environment.
func cmdenv() {
path := flag.Bool("p", false, "emit updated PATH")
- plan9 := flag.Bool("9", false, "emit plan 9 syntax")
- windows := flag.Bool("w", false, "emit windows syntax")
+ 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"
format = "set %s=%s\r\n"
}
+ xprintf(format, "GO111MODULE", "")
xprintf(format, "GOARCH", goarch)
- xprintf(format, "GOBIN", gobin)
+ xprintf(format, "GOBIN", gorootBin)
xprintf(format, "GOCACHE", os.Getenv("GOCACHE"))
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)
if goarch == "ppc64" || goarch == "ppc64le" {
xprintf(format, "GOPPC64", goppc64)
}
+ xprintf(format, "GOWORK", "off")
if *path {
sep := ":"
if gohostos == "windows" {
sep = ";"
}
- xprintf(format, "PATH", fmt.Sprintf("%s%s%s", gobin, sep, os.Getenv("PATH")))
+ xprintf(format, "PATH", fmt.Sprintf("%s%s%s", gorootBin, sep, os.Getenv("PATH")))
}
}
gogcflags = os.Getenv("GO_GCFLAGS") // we were using $BOOT_GO_GCFLAGS until now
goldflags = os.Getenv("GO_LDFLAGS") // we were using $BOOT_GO_LDFLAGS until now
goBootstrap := pathf("%s/go_bootstrap", tooldir)
- cmdGo := pathf("%s/go", gobin)
+ cmdGo := pathf("%s/go", gorootBin)
if debug {
run("", ShowOutput|CheckExit, pathf("%s/compile", tooldir), "-V=full")
copyfile(pathf("%s/compile1", tooldir), pathf("%s/compile", tooldir), writeExec)
os.Setenv("GOOS", gohostos)
os.Setenv("GOARCH", gohostarch)
os.Setenv("CC", compilerEnvLookup(defaultcc, gohostos, gohostarch))
- goCmd(cmdGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gobin, goos, goarch, exe), wrapperPath)
+ goCmd(cmdGo, "build", "-o", pathf("%s/go_%s_%s_exec%s", gorootBin, goos, goarch, exe), wrapperPath)
// Restore environment.
// TODO(elias.naur): support environment variables in goCmd?
os.Setenv("GOOS", goos)
}
xprintf("---\n")
xprintf("Installed Go for %s/%s in %s\n", goos, goarch, goroot)
- xprintf("Installed commands in %s\n", gobin)
+ xprintf("Installed commands in %s\n", gorootBin)
if !xsamefile(goroot_final, goroot) {
// If the files are to be moved, don't check that gobin
// is on PATH; assume they know what they are doing.
} else if gohostos == "plan9" {
- // Check that gobin is bound before /bin.
+ // Check that GOROOT/bin is bound before /bin.
pid := strings.Replace(readfile("#c/pid"), " ", "", -1)
ns := fmt.Sprintf("/proc/%s/ns", pid)
- if !strings.Contains(readfile(ns), fmt.Sprintf("bind -b %s /bin", gobin)) {
- xprintf("*** You need to bind %s before /bin.\n", gobin)
+ if !strings.Contains(readfile(ns), fmt.Sprintf("bind -b %s /bin", gorootBin)) {
+ xprintf("*** You need to bind %s before /bin.\n", gorootBin)
}
} else {
- // Check that gobin appears in $PATH.
+ // Check that GOROOT/bin appears in $PATH.
pathsep := ":"
if gohostos == "windows" {
pathsep = ";"
}
- if !strings.Contains(pathsep+os.Getenv("PATH")+pathsep, pathsep+gobin+pathsep) {
- xprintf("*** You need to add %s to your PATH.\n", gobin)
+ if !strings.Contains(pathsep+os.Getenv("PATH")+pathsep, pathsep+gorootBin+pathsep) {
+ xprintf("*** You need to add %s to your PATH.\n", gorootBin)
}
}