@@ -26,7 +26,7 @@ import (
26
26
// The usual variables.
27
27
var (
28
28
goarch string
29
- gobin string
29
+ gorootBin string
30
30
gohostarch string
31
31
gohostos string
32
32
goos string
@@ -112,19 +112,14 @@ func xinit() {
112
112
fatalf ("$GOROOT must be set" )
113
113
}
114
114
goroot = filepath .Clean (b )
115
+ gorootBin = pathf ("%s/bin" , goroot )
115
116
116
117
b = os .Getenv ("GOROOT_FINAL" )
117
118
if b == "" {
118
119
b = goroot
119
120
}
120
121
goroot_final = b
121
122
122
- b = os .Getenv ("GOBIN" )
123
- if b == "" {
124
- b = pathf ("%s/bin" , goroot )
125
- }
126
- gobin = b
127
-
128
123
b = os .Getenv ("GOOS" )
129
124
if b == "" {
130
125
b = gohostos
@@ -241,9 +236,19 @@ func xinit() {
241
236
// make.bash really does start from a clean slate.
242
237
os .Setenv ("GOCACHE" , pathf ("%s/pkg/obj/go-build" , goroot ))
243
238
239
+ // Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
240
+ // (see https://go.dev/issue/3269, https://go.dev/cl/183058,
241
+ // https://go.dev/issue/31576). Since we want binaries installed by 'dist' to
242
+ // always go to GOROOT/bin anyway.
243
+ os .Setenv ("GOBIN" , gorootBin )
244
+
244
245
// Make the environment more predictable.
245
246
os .Setenv ("LANG" , "C" )
246
247
os .Setenv ("LANGUAGE" , "en_US.UTF8" )
248
+ os .Unsetenv ("GO111MODULE" )
249
+ os .Setenv ("GOENV" , "off" )
250
+ os .Unsetenv ("GOFLAGS" )
251
+ os .Setenv ("GOWORK" , "off" )
247
252
248
253
workdir = xworkdir ()
249
254
if err := ioutil .WriteFile (pathf ("%s/go.mod" , workdir ), []byte ("module bootstrap" ), 0666 ); err != nil {
@@ -490,16 +495,6 @@ func setup() {
490
495
xremove (pathf ("%s/bin/%s" , goroot , old ))
491
496
}
492
497
493
- // If $GOBIN is set and has a Go compiler, it must be cleaned.
494
- for _ , char := range "56789" {
495
- if isfile (pathf ("%s/%c%s" , gobin , char , "g" )) {
496
- for _ , old := range oldtool {
497
- xremove (pathf ("%s/%s" , gobin , old ))
498
- }
499
- break
500
- }
501
- }
502
-
503
498
// For release, make sure excluded things are excluded.
504
499
goversion := findgoversion ()
505
500
if strings .HasPrefix (goversion , "release." ) || (strings .HasPrefix (goversion , "go" ) && ! strings .Contains (goversion , "beta" )) {
@@ -1126,8 +1121,8 @@ func clean() {
1126
1121
// The env command prints the default environment.
1127
1122
func cmdenv () {
1128
1123
path := flag .Bool ("p" , false , "emit updated PATH" )
1129
- plan9 := flag .Bool ("9" , false , "emit plan 9 syntax" )
1130
- windows := flag .Bool ("w" , false , "emit windows syntax" )
1124
+ plan9 := flag .Bool ("9" , gohostos == "plan9" , "emit plan 9 syntax" )
1125
+ windows := flag .Bool ("w" , gohostos == "windows" , "emit windows syntax" )
1131
1126
xflagparse (0 )
1132
1127
1133
1128
format := "%s=\" %s\" \n "
@@ -1138,10 +1133,13 @@ func cmdenv() {
1138
1133
format = "set %s=%s\r \n "
1139
1134
}
1140
1135
1136
+ xprintf (format , "GO111MODULE" , "" )
1141
1137
xprintf (format , "GOARCH" , goarch )
1142
- xprintf (format , "GOBIN" , gobin )
1138
+ xprintf (format , "GOBIN" , gorootBin )
1143
1139
xprintf (format , "GOCACHE" , os .Getenv ("GOCACHE" ))
1144
1140
xprintf (format , "GODEBUG" , os .Getenv ("GODEBUG" ))
1141
+ xprintf (format , "GOENV" , "off" )
1142
+ xprintf (format , "GOFLAGS" , "" )
1145
1143
xprintf (format , "GOHOSTARCH" , gohostarch )
1146
1144
xprintf (format , "GOHOSTOS" , gohostos )
1147
1145
xprintf (format , "GOOS" , goos )
@@ -1167,13 +1165,14 @@ func cmdenv() {
1167
1165
if goarch == "ppc64" || goarch == "ppc64le" {
1168
1166
xprintf (format , "GOPPC64" , goppc64 )
1169
1167
}
1168
+ xprintf (format , "GOWORK" , "off" )
1170
1169
1171
1170
if * path {
1172
1171
sep := ":"
1173
1172
if gohostos == "windows" {
1174
1173
sep = ";"
1175
1174
}
1176
- xprintf (format , "PATH" , fmt .Sprintf ("%s%s%s" , gobin , sep , os .Getenv ("PATH" )))
1175
+ xprintf (format , "PATH" , fmt .Sprintf ("%s%s%s" , gorootBin , sep , os .Getenv ("PATH" )))
1177
1176
}
1178
1177
}
1179
1178
@@ -1318,7 +1317,7 @@ func cmdbootstrap() {
1318
1317
gogcflags = os .Getenv ("GO_GCFLAGS" ) // we were using $BOOT_GO_GCFLAGS until now
1319
1318
goldflags = os .Getenv ("GO_LDFLAGS" ) // we were using $BOOT_GO_LDFLAGS until now
1320
1319
goBootstrap := pathf ("%s/go_bootstrap" , tooldir )
1321
- cmdGo := pathf ("%s/go" , gobin )
1320
+ cmdGo := pathf ("%s/go" , gorootBin )
1322
1321
if debug {
1323
1322
run ("" , ShowOutput | CheckExit , pathf ("%s/compile" , tooldir ), "-V=full" )
1324
1323
copyfile (pathf ("%s/compile1" , tooldir ), pathf ("%s/compile" , tooldir ), writeExec )
@@ -1457,7 +1456,7 @@ func cmdbootstrap() {
1457
1456
os .Setenv ("GOOS" , gohostos )
1458
1457
os .Setenv ("GOARCH" , gohostarch )
1459
1458
os .Setenv ("CC" , compilerEnvLookup (defaultcc , gohostos , gohostarch ))
1460
- goCmd (cmdGo , "build" , "-o" , pathf ("%s/go_%s_%s_exec%s" , gobin , goos , goarch , exe ), wrapperPath )
1459
+ goCmd (cmdGo , "build" , "-o" , pathf ("%s/go_%s_%s_exec%s" , gorootBin , goos , goarch , exe ), wrapperPath )
1461
1460
// Restore environment.
1462
1461
// TODO(elias.naur): support environment variables in goCmd?
1463
1462
os .Setenv ("GOOS" , goos )
@@ -1681,26 +1680,26 @@ func banner() {
1681
1680
}
1682
1681
xprintf ("---\n " )
1683
1682
xprintf ("Installed Go for %s/%s in %s\n " , goos , goarch , goroot )
1684
- xprintf ("Installed commands in %s\n " , gobin )
1683
+ xprintf ("Installed commands in %s\n " , gorootBin )
1685
1684
1686
1685
if ! xsamefile (goroot_final , goroot ) {
1687
1686
// If the files are to be moved, don't check that gobin
1688
1687
// is on PATH; assume they know what they are doing.
1689
1688
} else if gohostos == "plan9" {
1690
- // Check that gobin is bound before /bin.
1689
+ // Check that GOROOT/bin is bound before /bin.
1691
1690
pid := strings .Replace (readfile ("#c/pid" ), " " , "" , - 1 )
1692
1691
ns := fmt .Sprintf ("/proc/%s/ns" , pid )
1693
- if ! strings .Contains (readfile (ns ), fmt .Sprintf ("bind -b %s /bin" , gobin )) {
1694
- xprintf ("*** You need to bind %s before /bin.\n " , gobin )
1692
+ if ! strings .Contains (readfile (ns ), fmt .Sprintf ("bind -b %s /bin" , gorootBin )) {
1693
+ xprintf ("*** You need to bind %s before /bin.\n " , gorootBin )
1695
1694
}
1696
1695
} else {
1697
- // Check that gobin appears in $PATH.
1696
+ // Check that GOROOT/bin appears in $PATH.
1698
1697
pathsep := ":"
1699
1698
if gohostos == "windows" {
1700
1699
pathsep = ";"
1701
1700
}
1702
- if ! strings .Contains (pathsep + os .Getenv ("PATH" )+ pathsep , pathsep + gobin + pathsep ) {
1703
- xprintf ("*** You need to add %s to your PATH.\n " , gobin )
1701
+ if ! strings .Contains (pathsep + os .Getenv ("PATH" )+ pathsep , pathsep + gorootBin + pathsep ) {
1702
+ xprintf ("*** You need to add %s to your PATH.\n " , gorootBin )
1704
1703
}
1705
1704
}
1706
1705
0 commit comments