Skip to content

Commit 507d1b2

Browse files
iwdgogopherbot
authored andcommitted
cmd: remove support for GOROOT_FINAL
Fixes #62047 Change-Id: If7811c1eb9073fb09b7006076998f8b2e1810bfb Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/539975 Auto-Submit: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 05c0579 commit 507d1b2

31 files changed

+71
-262
lines changed

doc/next/3-tools.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22

33
### Go command {#go-command}
44

5+
Setting the `GOROOT_FINAL` environment variable no longer has an effect
6+
([#62047](https://go.dev/issue/62047)).
7+
Distributions that install the `go` command to a location other than
8+
`$GOROOT/bin/go` should install a symlink instead of relocating
9+
or copying the `go` binary.
10+
511
### Cgo {#cgo}
612

src/cmd/addr2line/addr2line_test.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,32 +109,18 @@ func testAddr2Line(t *testing.T, dbgExePath, addr string) {
109109
srcPath = filepath.FromSlash(srcPath)
110110
fi2, err := os.Stat(srcPath)
111111

112-
// If GOROOT_FINAL is set and srcPath is not the file we expect, perhaps
113-
// srcPath has had GOROOT_FINAL substituted for GOROOT and GOROOT hasn't been
114-
// moved to its final location yet. If so, try the original location instead.
115-
if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" &&
116-
(os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2))) {
117-
// srcPath is clean, but GOROOT_FINAL itself might not be.
118-
// (See https://golang.org/issue/41447.)
119-
gorootFinal = filepath.Clean(gorootFinal)
120-
121-
if strings.HasPrefix(srcPath, gorootFinal) {
122-
fi2, err = os.Stat(runtime.GOROOT() + strings.TrimPrefix(srcPath, gorootFinal))
123-
}
124-
}
125-
126112
if err != nil {
127113
t.Fatalf("Stat failed: %v", err)
128114
}
129115
if !os.SameFile(fi1, fi2) {
130116
t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
131117
}
132-
if srcLineNo != "138" {
133-
t.Fatalf("line number = %v; want 138", srcLineNo)
118+
if want := "124"; srcLineNo != want {
119+
t.Fatalf("line number = %v; want %s", srcLineNo, want)
134120
}
135121
}
136122

137-
// This is line 137. The test depends on that.
123+
// This is line 123. The test depends on that.
138124
func TestAddr2Line(t *testing.T) {
139125
testenv.MustHaveGoBuild(t)
140126

src/cmd/dist/build.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var (
4040
goppc64 string
4141
goriscv64 string
4242
goroot string
43-
goroot_final string
4443
goextlinkenabled string
4544
gogcflags string // For running built compiler
4645
goldflags string
@@ -127,12 +126,6 @@ func xinit() {
127126
// All exec calls rewrite "go" into gorootBinGo.
128127
gorootBinGo = pathf("%s/bin/go", goroot)
129128

130-
b = os.Getenv("GOROOT_FINAL")
131-
if b == "" {
132-
b = goroot
133-
}
134-
goroot_final = b
135-
136129
b = os.Getenv("GOOS")
137130
if b == "" {
138131
b = gohostos
@@ -245,7 +238,6 @@ func xinit() {
245238
os.Setenv("GOPPC64", goppc64)
246239
os.Setenv("GORISCV64", goriscv64)
247240
os.Setenv("GOROOT", goroot)
248-
os.Setenv("GOROOT_FINAL", goroot_final)
249241

250242
// Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
251243
// (see https://go.dev/issue/3269, https://go.dev/cl/183058,
@@ -1879,10 +1871,7 @@ func banner() {
18791871
xprintf("Installed Go for %s/%s in %s\n", goos, goarch, goroot)
18801872
xprintf("Installed commands in %s\n", gorootBin)
18811873

1882-
if !xsamefile(goroot_final, goroot) {
1883-
// If the files are to be moved, don't check that gobin
1884-
// is on PATH; assume they know what they are doing.
1885-
} else if gohostos == "plan9" {
1874+
if gohostos == "plan9" {
18861875
// Check that GOROOT/bin is bound before /bin.
18871876
pid := strings.Replace(readfile("#c/pid"), " ", "", -1)
18881877
ns := fmt.Sprintf("/proc/%s/ns", pid)
@@ -1907,12 +1896,6 @@ func banner() {
19071896
xprintf("*** You need to add %s to your PATH.\n", gorootBin)
19081897
}
19091898
}
1910-
1911-
if !xsamefile(goroot_final, goroot) {
1912-
xprintf("\n"+
1913-
"The binaries expect %s to be copied or moved to %s\n",
1914-
goroot, goroot_final)
1915-
}
19161899
}
19171900

19181901
// Version prints the Go version.

src/cmd/go/alldocs.go

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/go_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ func tooSlow(t *testing.T, reason string) {
9090
// (temp) directory.
9191
var testGOROOT string
9292

93-
// testGOROOT_FINAL is the GOROOT_FINAL with which the test binary is assumed to
94-
// have been built.
95-
var testGOROOT_FINAL = os.Getenv("GOROOT_FINAL")
96-
9793
var testGOCACHE string
9894

9995
var testGo string
@@ -223,10 +219,6 @@ func TestMain(m *testing.M) {
223219
}
224220
testGOROOT = goEnv("GOROOT")
225221
os.Setenv("TESTGO_GOROOT", testGOROOT)
226-
// Ensure that GOROOT is set explicitly.
227-
// Otherwise, if the toolchain was built with GOROOT_FINAL set but has not
228-
// yet been moved to its final location, programs that invoke runtime.GOROOT
229-
// may accidentally use the wrong path.
230222
os.Setenv("GOROOT", testGOROOT)
231223

232224
// The whole GOROOT/pkg tree was installed using the GOHOSTOS/GOHOSTARCH

src/cmd/go/internal/cfg/cfg.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ func SetGOROOT(goroot string, isTestGo bool) {
199199
GOROOTpkg = filepath.Join(goroot, "pkg")
200200
GOROOTsrc = filepath.Join(goroot, "src")
201201
}
202-
GOROOT_FINAL = findGOROOT_FINAL(goroot)
203202

204203
installedGOOS = runtime.GOOS
205204
installedGOARCH = runtime.GOARCH
@@ -398,8 +397,6 @@ var (
398397
GOROOTpkg string
399398
GOROOTsrc string
400399

401-
GOROOT_FINAL string
402-
403400
GOBIN = Getenv("GOBIN")
404401
GOMODCACHE = envOr("GOMODCACHE", gopathDir("pkg/mod"))
405402

@@ -532,16 +529,6 @@ func findGOROOT(env string) string {
532529
return def
533530
}
534531

535-
func findGOROOT_FINAL(goroot string) string {
536-
// $GOROOT_FINAL is only for use during make.bash
537-
// so it is not settable using go/env, so we use os.Getenv here.
538-
def := goroot
539-
if env := os.Getenv("GOROOT_FINAL"); env != "" {
540-
def = filepath.Clean(env)
541-
}
542-
return def
543-
}
544-
545532
// isSameDir reports whether dir1 and dir2 are the same directory.
546533
func isSameDir(dir1, dir2 string) bool {
547534
if dir1 == dir2 {

src/cmd/go/internal/help/helpdoc.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -645,11 +645,6 @@ Special-purpose environment variables:
645645
See src/internal/goexperiment/flags.go for currently valid values.
646646
Warning: This variable is provided for the development and testing
647647
of the Go toolchain itself. Use beyond that purpose is unsupported.
648-
GOROOT_FINAL
649-
The root of the installed Go tree, when it is
650-
installed in a location other than where it is built.
651-
File names in stack traces are rewritten from GOROOT to
652-
GOROOT_FINAL.
653648
GO_EXTLINK_ENABLED
654649
Whether the linker should use external linking mode
655650
when using -linkmode=auto with code that uses cgo.

src/cmd/go/internal/work/exec.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,12 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
258258
// when building things in GOROOT.
259259
//
260260
// The C compiler does not, but for packages in GOROOT we rewrite the path
261-
// as though -trimpath were set, so that we don't invalidate the build cache
262-
// (and especially any precompiled C archive files) when changing
263-
// GOROOT_FINAL. (See https://go.dev/issue/50183.)
261+
// as though -trimpath were set. This used to be so that we did not invalidate
262+
// the build cache (and especially precompiled archive files) when changing
263+
// GOROOT_FINAL, but we no longer ship precompiled archive files as of Go 1.20
264+
// (https://go.dev/issue/47257) and no longer support GOROOT_FINAL
265+
// (https://go.dev/issue/62047).
266+
// TODO(bcmills): Figure out whether this behavior is still useful.
264267
//
265268
// b.WorkDir is always either trimmed or rewritten to
266269
// the literal string "/tmp/go-build".
@@ -1403,11 +1406,11 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
14031406
fmt.Fprintf(h, "GOEXPERIMENT=%q\n", cfg.CleanGOEXPERIMENT)
14041407
}
14051408

1406-
// The linker writes source file paths that say GOROOT_FINAL, but
1407-
// only if -trimpath is not specified (see ld() in gc.go).
1408-
gorootFinal := cfg.GOROOT_FINAL
1409+
// The linker writes source file paths that refer to GOROOT,
1410+
// but only if -trimpath is not specified (see [gctoolchain.ld] in gc.go).
1411+
gorootFinal := cfg.GOROOT
14091412
if cfg.BuildTrimpath {
1410-
gorootFinal = trimPathGoRootFinal
1413+
gorootFinal = ""
14111414
}
14121415
fmt.Fprintf(h, "GOROOT=%s\n", gorootFinal)
14131416

@@ -2130,7 +2133,7 @@ func (b *Builder) ccompile(a *Action, outfile string, flags []string, file strin
21302133
file = mkAbs(p.Dir, file)
21312134
outfile = mkAbs(p.Dir, outfile)
21322135

2133-
// Elide source directory paths if -trimpath or GOROOT_FINAL is set.
2136+
// Elide source directory paths if -trimpath is set.
21342137
// This is needed for source files (e.g., a .c file in a package directory).
21352138
// TODO(golang.org/issue/36072): cgo also generates files with #line
21362139
// directives pointing to the source directory. It should not generate those

src/cmd/go/internal/work/gc.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ import (
2929
// Tests can override this by setting $TESTGO_TOOLCHAIN_VERSION.
3030
var ToolchainVersion = runtime.Version()
3131

32-
// The 'path' used for GOROOT_FINAL when -trimpath is specified
33-
const trimPathGoRootFinal string = "$GOROOT"
34-
3532
// The Go toolchain.
3633

3734
type gcToolchain struct{}
@@ -669,8 +666,11 @@ func (gcToolchain) ld(b *Builder, root *Action, targetPath, importcfg, mainpkg s
669666
}
670667

671668
env := []string{}
669+
// When -trimpath is used, GOROOT is cleared
672670
if cfg.BuildTrimpath {
673-
env = append(env, "GOROOT_FINAL="+trimPathGoRootFinal)
671+
env = append(env, "GOROOT=")
672+
} else {
673+
env = append(env, "GOROOT="+cfg.GOROOT)
674674
}
675675
return b.Shell(root).run(dir, root.Package.ImportPath, env, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags, mainpkg)
676676
}

src/cmd/go/script_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ func scriptEnv(srv *vcstest.Server, srvCertFile string) ([]string, error) {
223223
"GOPROXY=" + proxyURL,
224224
"GOPRIVATE=",
225225
"GOROOT=" + testGOROOT,
226-
"GOROOT_FINAL=" + testGOROOT_FINAL, // causes spurious rebuilds and breaks the "stale" built-in if not propagated
227226
"GOTRACEBACK=system",
228227
"TESTGONETWORK=panic", // allow only local connections by default; the [net] condition resets this
229228
"TESTGO_GOROOT=" + testGOROOT,

src/cmd/go/scriptconds_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ func scriptConditions() map[string]script.Cond {
5151
add("GOEXPERIMENT", script.PrefixCondition("GOEXPERIMENT <suffix> is enabled", hasGoexperiment))
5252
add("go-builder", script.BoolCondition("GO_BUILDER_NAME is non-empty", testenv.Builder() != ""))
5353
add("link", lazyBool("testenv.HasLink()", testenv.HasLink))
54-
add("mismatched-goroot", script.Condition("test's GOROOT_FINAL does not match the real GOROOT", isMismatchedGoroot))
5554
add("msan", sysCondition("-msan", platform.MSanSupported, true))
5655
add("mustlinkext", script.Condition("platform always requires external linking", mustLinkExt))
5756
add("net", script.PrefixCondition("can connect to external network host <suffix>", hasNet))
@@ -85,14 +84,6 @@ func ccIs(s *script.State, want string) (bool, error) {
8584
return cfg.DefaultCC(GOOS, GOARCH) == want, nil
8685
}
8786

88-
func isMismatchedGoroot(s *script.State) (bool, error) {
89-
gorootFinal, _ := s.LookupEnv("GOROOT_FINAL")
90-
if gorootFinal == "" {
91-
gorootFinal, _ = s.LookupEnv("GOROOT")
92-
}
93-
return gorootFinal != testGOROOT, nil
94-
}
95-
9687
func sysCondition(flag string, f func(goos, goarch string) bool, needsCgo bool) script.Cond {
9788
return script.Condition(
9889
"GOOS/GOARCH supports "+flag,

src/cmd/go/scriptreadme_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ Scripts also have access to other environment variables, including:
120120
GOPATH=$WORK/gopath
121121
GOPROXY=<local module proxy serving from cmd/go/testdata/mod>
122122
GOROOT=<actual GOROOT>
123-
GOROOT_FINAL=<actual GOROOT_FINAL>
124123
TESTGO_GOROOT=<GOROOT used to build cmd/go, for use in tests that may change GOROOT>
125124
HOME=/no-home
126125
PATH=<actual PATH>

src/cmd/go/testdata/script/README

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Scripts also have access to other environment variables, including:
3535
GOPATH=$WORK/gopath
3636
GOPROXY=<local module proxy serving from cmd/go/testdata/mod>
3737
GOROOT=<actual GOROOT>
38-
GOROOT_FINAL=<actual GOROOT_FINAL>
3938
TESTGO_GOROOT=<GOROOT used to build cmd/go, for use in tests that may change GOROOT>
4039
HOME=/no-home
4140
PATH=<actual PATH>
@@ -402,8 +401,6 @@ The available conditions are:
402401
GO_BUILDER_NAME is non-empty
403402
[link]
404403
testenv.HasLink()
405-
[mismatched-goroot]
406-
test's GOROOT_FINAL does not match the real GOROOT
407404
[msan]
408405
GOOS/GOARCH supports -msan
409406
[mustlinkext]

src/cmd/go/testdata/script/build_issue48319.txt

Lines changed: 0 additions & 53 deletions
This file was deleted.

0 commit comments

Comments
 (0)