]> Cypherpunks repositories - gostls13.git/commitdiff
cmd: remove support for GOROOT_FINAL
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Sun, 5 Nov 2023 09:35:12 +0000 (10:35 +0100)
committerGopher Robot <gobot@golang.org>
Wed, 21 Feb 2024 22:16:54 +0000 (22:16 +0000)
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 <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
31 files changed:
doc/next/3-tools.md
src/cmd/addr2line/addr2line_test.go
src/cmd/dist/build.go
src/cmd/go/alldocs.go
src/cmd/go/go_test.go
src/cmd/go/internal/cfg/cfg.go
src/cmd/go/internal/help/helpdoc.go
src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/script_test.go
src/cmd/go/scriptconds_test.go
src/cmd/go/scriptreadme_test.go
src/cmd/go/testdata/script/README
src/cmd/go/testdata/script/build_issue48319.txt [deleted file]
src/cmd/go/testdata/script/build_trimpath.txt
src/cmd/go/testdata/script/build_trimpath_goroot.txt
src/cmd/go/testdata/script/cgo_stale_precompiled.txt
src/cmd/go/testdata/script/goroot_executable.txt
src/cmd/go/testdata/script/goroot_executable_trimpath.txt
src/cmd/internal/bootstrap_test/reboot_test.go
src/cmd/internal/moddeps/moddeps_test.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/ld/pcln.go
src/cmd/objdump/objdump_test.go
src/internal/buildcfg/cfg.go
src/internal/testenv/testenv.go
src/make.bash
src/make.bat
src/make.rc
src/runtime/runtime-gdb_test.go
src/runtime/runtime-lldb_test.go

index 5638f240a5b12744564781b99e1ce4878df6ca41..bdbe6c077173d05ac85cc18410702060400f51aa 100644 (file)
@@ -2,5 +2,11 @@
 
 ### Go command {#go-command}
 
+Setting the `GOROOT_FINAL` environment variable no longer has an effect
+([#62047](https://go.dev/issue/62047)).
+Distributions that install the `go` command to a location other than
+`$GOROOT/bin/go` should install a symlink instead of relocating
+or copying the `go` binary.
+
 ### Cgo {#cgo}
 
index 0ea8994b6a0c757e6077ec81320a03187c86ca29..e5b0a0fdae01e040ea8ce89d18208244d3be1126 100644 (file)
@@ -109,32 +109,18 @@ func testAddr2Line(t *testing.T, dbgExePath, addr string) {
        srcPath = filepath.FromSlash(srcPath)
        fi2, err := os.Stat(srcPath)
 
-       // If GOROOT_FINAL is set and srcPath is not the file we expect, perhaps
-       // srcPath has had GOROOT_FINAL substituted for GOROOT and GOROOT hasn't been
-       // moved to its final location yet. If so, try the original location instead.
-       if gorootFinal := os.Getenv("GOROOT_FINAL"); gorootFinal != "" &&
-               (os.IsNotExist(err) || (err == nil && !os.SameFile(fi1, fi2))) {
-               // srcPath is clean, but GOROOT_FINAL itself might not be.
-               // (See https://golang.org/issue/41447.)
-               gorootFinal = filepath.Clean(gorootFinal)
-
-               if strings.HasPrefix(srcPath, gorootFinal) {
-                       fi2, err = os.Stat(runtime.GOROOT() + strings.TrimPrefix(srcPath, gorootFinal))
-               }
-       }
-
        if err != nil {
                t.Fatalf("Stat failed: %v", err)
        }
        if !os.SameFile(fi1, fi2) {
                t.Fatalf("addr2line_test.go and %s are not same file", srcPath)
        }
-       if srcLineNo != "138" {
-               t.Fatalf("line number = %v; want 138", srcLineNo)
+       if want := "124"; srcLineNo != want {
+               t.Fatalf("line number = %v; want %s", srcLineNo, want)
        }
 }
 
-// This is line 137. The test depends on that.
+// This is line 123. The test depends on that.
 func TestAddr2Line(t *testing.T) {
        testenv.MustHaveGoBuild(t)
 
index 4181d331129a4c1878481ebce565aae9488d12a0..d4d1bd8f0b512cb85f4d7bd9368762db0a56f6a1 100644 (file)
@@ -40,7 +40,6 @@ var (
        goppc64          string
        goriscv64        string
        goroot           string
-       goroot_final     string
        goextlinkenabled string
        gogcflags        string // For running built compiler
        goldflags        string
@@ -127,12 +126,6 @@ func xinit() {
        // All exec calls rewrite "go" into gorootBinGo.
        gorootBinGo = pathf("%s/bin/go", goroot)
 
-       b = os.Getenv("GOROOT_FINAL")
-       if b == "" {
-               b = goroot
-       }
-       goroot_final = b
-
        b = os.Getenv("GOOS")
        if b == "" {
                b = gohostos
@@ -245,7 +238,6 @@ func xinit() {
        os.Setenv("GOPPC64", goppc64)
        os.Setenv("GORISCV64", goriscv64)
        os.Setenv("GOROOT", goroot)
-       os.Setenv("GOROOT_FINAL", goroot_final)
 
        // Set GOBIN to GOROOT/bin. The meaning of GOBIN has drifted over time
        // (see https://go.dev/issue/3269, https://go.dev/cl/183058,
@@ -1879,10 +1871,7 @@ func banner() {
        xprintf("Installed Go for %s/%s in %s\n", goos, goarch, goroot)
        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" {
+       if gohostos == "plan9" {
                // Check that GOROOT/bin is bound before /bin.
                pid := strings.Replace(readfile("#c/pid"), " ", "", -1)
                ns := fmt.Sprintf("/proc/%s/ns", pid)
@@ -1907,12 +1896,6 @@ func banner() {
                        xprintf("*** You need to add %s to your PATH.\n", gorootBin)
                }
        }
-
-       if !xsamefile(goroot_final, goroot) {
-               xprintf("\n"+
-                       "The binaries expect %s to be copied or moved to %s\n",
-                       goroot, goroot_final)
-       }
 }
 
 // Version prints the Go version.
index 5e6d54ee2e7c01ae89058afe4b7cecbda00b4347..153128e715151b3f709c006b60848e8e497e49df 100644 (file)
 //             See src/internal/goexperiment/flags.go for currently valid values.
 //             Warning: This variable is provided for the development and testing
 //             of the Go toolchain itself. Use beyond that purpose is unsupported.
-//     GOROOT_FINAL
-//             The root of the installed Go tree, when it is
-//             installed in a location other than where it is built.
-//             File names in stack traces are rewritten from GOROOT to
-//             GOROOT_FINAL.
 //     GO_EXTLINK_ENABLED
 //             Whether the linker should use external linking mode
 //             when using -linkmode=auto with code that uses cgo.
index 32822950f10a42f9515be05565144e2f8bad9961..4f38ec3defabccd8cb8569bf56860b8faa791736 100644 (file)
@@ -90,10 +90,6 @@ func tooSlow(t *testing.T, reason string) {
 // (temp) directory.
 var testGOROOT string
 
-// testGOROOT_FINAL is the GOROOT_FINAL with which the test binary is assumed to
-// have been built.
-var testGOROOT_FINAL = os.Getenv("GOROOT_FINAL")
-
 var testGOCACHE string
 
 var testGo string
@@ -223,10 +219,6 @@ func TestMain(m *testing.M) {
                }
                testGOROOT = goEnv("GOROOT")
                os.Setenv("TESTGO_GOROOT", testGOROOT)
-               // Ensure that GOROOT is set explicitly.
-               // Otherwise, if the toolchain was built with GOROOT_FINAL set but has not
-               // yet been moved to its final location, programs that invoke runtime.GOROOT
-               // may accidentally use the wrong path.
                os.Setenv("GOROOT", testGOROOT)
 
                // The whole GOROOT/pkg tree was installed using the GOHOSTOS/GOHOSTARCH
index 58432335e4106fa177d6ed634485db0718579db6..e0da810c738a54fe1c1a77e525358abdec85ea01 100644 (file)
@@ -199,7 +199,6 @@ func SetGOROOT(goroot string, isTestGo bool) {
                GOROOTpkg = filepath.Join(goroot, "pkg")
                GOROOTsrc = filepath.Join(goroot, "src")
        }
-       GOROOT_FINAL = findGOROOT_FINAL(goroot)
 
        installedGOOS = runtime.GOOS
        installedGOARCH = runtime.GOARCH
@@ -398,8 +397,6 @@ var (
        GOROOTpkg string
        GOROOTsrc string
 
-       GOROOT_FINAL string
-
        GOBIN      = Getenv("GOBIN")
        GOMODCACHE = envOr("GOMODCACHE", gopathDir("pkg/mod"))
 
@@ -532,16 +529,6 @@ func findGOROOT(env string) string {
        return def
 }
 
-func findGOROOT_FINAL(goroot string) string {
-       // $GOROOT_FINAL is only for use during make.bash
-       // so it is not settable using go/env, so we use os.Getenv here.
-       def := goroot
-       if env := os.Getenv("GOROOT_FINAL"); env != "" {
-               def = filepath.Clean(env)
-       }
-       return def
-}
-
 // isSameDir reports whether dir1 and dir2 are the same directory.
 func isSameDir(dir1, dir2 string) bool {
        if dir1 == dir2 {
index a53e078d7955bdf546b97615a905c3e6e345dbca..ddaca3807af7afd46badd9327bb3c99ebcaea944 100644 (file)
@@ -645,11 +645,6 @@ Special-purpose environment variables:
                See src/internal/goexperiment/flags.go for currently valid values.
                Warning: This variable is provided for the development and testing
                of the Go toolchain itself. Use beyond that purpose is unsupported.
-       GOROOT_FINAL
-               The root of the installed Go tree, when it is
-               installed in a location other than where it is built.
-               File names in stack traces are rewritten from GOROOT to
-               GOROOT_FINAL.
        GO_EXTLINK_ENABLED
                Whether the linker should use external linking mode
                when using -linkmode=auto with code that uses cgo.
index f6aa2b353433501f643602b1781dd6f77dd53362..92aa0c1dc50583e82b376f6279969ef197a57952 100644 (file)
@@ -258,9 +258,12 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
                // when building things in GOROOT.
                //
                // The C compiler does not, but for packages in GOROOT we rewrite the path
-               // as though -trimpath were set, so that we don't invalidate the build cache
-               // (and especially any precompiled C archive files) when changing
-               // GOROOT_FINAL. (See https://go.dev/issue/50183.)
+               // as though -trimpath were set. This used to be so that we did not invalidate
+               // the build cache (and especially precompiled archive files) when changing
+               // GOROOT_FINAL, but we no longer ship precompiled archive files as of Go 1.20
+               // (https://go.dev/issue/47257) and no longer support GOROOT_FINAL
+               // (https://go.dev/issue/62047).
+               // TODO(bcmills): Figure out whether this behavior is still useful.
                //
                // b.WorkDir is always either trimmed or rewritten to
                // the literal string "/tmp/go-build".
@@ -1403,11 +1406,11 @@ func (b *Builder) printLinkerConfig(h io.Writer, p *load.Package) {
                        fmt.Fprintf(h, "GOEXPERIMENT=%q\n", cfg.CleanGOEXPERIMENT)
                }
 
-               // The linker writes source file paths that say GOROOT_FINAL, but
-               // only if -trimpath is not specified (see ld() in gc.go).
-               gorootFinal := cfg.GOROOT_FINAL
+               // The linker writes source file paths that refer to GOROOT,
+               // but only if -trimpath is not specified (see [gctoolchain.ld] in gc.go).
+               gorootFinal := cfg.GOROOT
                if cfg.BuildTrimpath {
-                       gorootFinal = trimPathGoRootFinal
+                       gorootFinal = ""
                }
                fmt.Fprintf(h, "GOROOT=%s\n", gorootFinal)
 
@@ -2130,7 +2133,7 @@ func (b *Builder) ccompile(a *Action, outfile string, flags []string, file strin
        file = mkAbs(p.Dir, file)
        outfile = mkAbs(p.Dir, outfile)
 
-       // Elide source directory paths if -trimpath or GOROOT_FINAL is set.
+       // Elide source directory paths if -trimpath is set.
        // This is needed for source files (e.g., a .c file in a package directory).
        // TODO(golang.org/issue/36072): cgo also generates files with #line
        // directives pointing to the source directory. It should not generate those
index a054f44cbe0e46f7612a8d73db30e54b4024d947..a85b262374a1b3f4832bf6a879addaaba9e2c532 100644 (file)
@@ -29,9 +29,6 @@ import (
 // Tests can override this by setting $TESTGO_TOOLCHAIN_VERSION.
 var ToolchainVersion = runtime.Version()
 
-// The 'path' used for GOROOT_FINAL when -trimpath is specified
-const trimPathGoRootFinal string = "$GOROOT"
-
 // The Go toolchain.
 
 type gcToolchain struct{}
@@ -669,8 +666,11 @@ func (gcToolchain) ld(b *Builder, root *Action, targetPath, importcfg, mainpkg s
        }
 
        env := []string{}
+       // When -trimpath is used, GOROOT is cleared
        if cfg.BuildTrimpath {
-               env = append(env, "GOROOT_FINAL="+trimPathGoRootFinal)
+               env = append(env, "GOROOT=")
+       } else {
+               env = append(env, "GOROOT="+cfg.GOROOT)
        }
        return b.Shell(root).run(dir, root.Package.ImportPath, env, cfg.BuildToolexec, base.Tool("link"), "-o", targetPath, "-importcfg", importcfg, ldflags, mainpkg)
 }
index 624c5bf50106202ef24b6f1b90517cb63e71c8f9..f50e85f575f197ade2591ae67654225d1339e2c0 100644 (file)
@@ -223,7 +223,6 @@ func scriptEnv(srv *vcstest.Server, srvCertFile string) ([]string, error) {
                "GOPROXY=" + proxyURL,
                "GOPRIVATE=",
                "GOROOT=" + testGOROOT,
-               "GOROOT_FINAL=" + testGOROOT_FINAL, // causes spurious rebuilds and breaks the "stale" built-in if not propagated
                "GOTRACEBACK=system",
                "TESTGONETWORK=panic", // allow only local connections by default; the [net] condition resets this
                "TESTGO_GOROOT=" + testGOROOT,
index 13007daba5188a88903f91a048fae9a199c85f07..3f11af272bd4d2dc9bafe012de49a533e9c84243 100644 (file)
@@ -51,7 +51,6 @@ func scriptConditions() map[string]script.Cond {
        add("GOEXPERIMENT", script.PrefixCondition("GOEXPERIMENT <suffix> is enabled", hasGoexperiment))
        add("go-builder", script.BoolCondition("GO_BUILDER_NAME is non-empty", testenv.Builder() != ""))
        add("link", lazyBool("testenv.HasLink()", testenv.HasLink))
-       add("mismatched-goroot", script.Condition("test's GOROOT_FINAL does not match the real GOROOT", isMismatchedGoroot))
        add("msan", sysCondition("-msan", platform.MSanSupported, true))
        add("mustlinkext", script.Condition("platform always requires external linking", mustLinkExt))
        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) {
        return cfg.DefaultCC(GOOS, GOARCH) == want, nil
 }
 
-func isMismatchedGoroot(s *script.State) (bool, error) {
-       gorootFinal, _ := s.LookupEnv("GOROOT_FINAL")
-       if gorootFinal == "" {
-               gorootFinal, _ = s.LookupEnv("GOROOT")
-       }
-       return gorootFinal != testGOROOT, nil
-}
-
 func sysCondition(flag string, f func(goos, goarch string) bool, needsCgo bool) script.Cond {
        return script.Condition(
                "GOOS/GOARCH supports "+flag,
index 2a842fbc0f7b636d92ce644586b1e3e5c7084dd3..26c7aa19f0788650b1036906dbac59424f9ea55a 100644 (file)
@@ -120,7 +120,6 @@ Scripts also have access to other environment variables, including:
        GOPATH=$WORK/gopath
        GOPROXY=<local module proxy serving from cmd/go/testdata/mod>
        GOROOT=<actual GOROOT>
-       GOROOT_FINAL=<actual GOROOT_FINAL>
        TESTGO_GOROOT=<GOROOT used to build cmd/go, for use in tests that may change GOROOT>
        HOME=/no-home
        PATH=<actual PATH>
index 39971f8029e4a85bddc9f03822ae821c1683a02e..8c95945ebe0761a7cb0613418e154b1dd0ef076d 100644 (file)
@@ -35,7 +35,6 @@ Scripts also have access to other environment variables, including:
        GOPATH=$WORK/gopath
        GOPROXY=<local module proxy serving from cmd/go/testdata/mod>
        GOROOT=<actual GOROOT>
-       GOROOT_FINAL=<actual GOROOT_FINAL>
        TESTGO_GOROOT=<GOROOT used to build cmd/go, for use in tests that may change GOROOT>
        HOME=/no-home
        PATH=<actual PATH>
@@ -402,8 +401,6 @@ The available conditions are:
        GO_BUILDER_NAME is non-empty
 [link]
        testenv.HasLink()
-[mismatched-goroot]
-       test's GOROOT_FINAL does not match the real GOROOT
 [msan]
        GOOS/GOARCH supports -msan
 [mustlinkext]
diff --git a/src/cmd/go/testdata/script/build_issue48319.txt b/src/cmd/go/testdata/script/build_issue48319.txt
deleted file mode 100644 (file)
index 148d8f0..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-# Regression test for https://go.dev/issue/48319:
-# cgo builds should not include debug information from a stale GOROOT_FINAL.
-
-[short] skip
-[!cgo] skip
-
-# This test has problems when run on the LUCI darwin longtest builder,
-# which uses a more contemporary Xcode version that is unfriendly to
-# reproducible builds (see issue #64947 for the gory details). Note
-# that individual developers running "go test cmd/go" on Darwin may
-# still run into failures depending on their Xcode version.
-[GOOS:darwin] [go-builder] skip
-
-# This test is sensitive to cache invalidation,
-# so use a separate build cache that we can control.
-env GOCACHE=$WORK/gocache
-mkdir $GOCACHE
-
-# Build a binary using a specific value of GOROOT_FINAL.
-env GOROOT_FINAL=$WORK${/}goroot1
-go build -o main.exe
-mv main.exe main1.exe
-
-# Now clean the cache and build using a different GOROOT_FINAL.
-# The resulting binaries should differ in their debug metadata.
-go clean -cache
-env GOROOT_FINAL=$WORK${/}goroot2
-go build -o main.exe
-mv main.exe main2.exe
-! cmp -q main2.exe main1.exe
-
-# Set GOROOT_FINAL back to the first value.
-# If the build is properly reproducible, the two binaries should match.
-env GOROOT_FINAL=$WORK${/}goroot1
-go build -o main.exe
-cmp -q main.exe main1.exe
-
--- go.mod --
-module main
-
-go 1.18
--- main.go --
-package main
-
-import "C"
-
-import "runtime"
-
-var _ C.int
-
-func main() {
-       println(runtime.GOROOT())
-}
index 2a2aa2080a14113a003bce14132aeda41db5b9c9..1f4dde98cb816295049104a7f2bd79a26a312d26 100644 (file)
@@ -1,8 +1,8 @@
 [short] skip
 
-# If GOROOT_FINAL is set, 'go build -trimpath' bakes that into the resulting
-# binary instead of GOROOT. Explicitly unset it here.
-env GOROOT_FINAL=
+# If GOROOT is set, 'go build -trimpath' bakes that into the resulting
+# binary. Explicitly unset it here.
+env GOROOT=
 
 # Set up two identical directories that can be used as GOPATH.
 env GO111MODULE=on
@@ -21,14 +21,13 @@ cd $WORK/a/src/paths
 go build -o $WORK/paths-dbg.exe .
 exec $WORK/paths-dbg.exe $WORK/paths-dbg.exe
 stdout 'binary contains module root: true'
-stdout 'binary contains GOROOT: true'
+stdout 'binary contains an empty GOROOT'
 
-# A binary built with -trimpath should not contain the current workspace
-# or GOROOT.
+# A binary built with -trimpath should not contain the current workspace.
 go build -trimpath -o $WORK/paths-a.exe .
 exec $WORK/paths-a.exe $WORK/paths-a.exe
 stdout 'binary contains module root: false'
-stdout 'binary contains GOROOT: false'
+stdout 'binary contains an empty GOROOT'
 
 # A binary from an external module built with -trimpath should not contain
 # the current workspace or GOROOT.
@@ -36,7 +35,7 @@ go get rsc.io/fortune
 go install -trimpath rsc.io/fortune
 exec $WORK/paths-a.exe $GOPATH/bin/fortune$GOEXE
 stdout 'binary contains module root: false'
-stdout 'binary contains GOROOT: false'
+stdout 'binary contains an empty GOROOT'
 go mod edit -droprequire rsc.io/fortune
 
 # Two binaries built from identical packages in different directories
@@ -53,14 +52,13 @@ cd $WORK/a/src/paths
 go build -overlay overlay.json -o $WORK/paths-dbg.exe ./overlaydir
 exec $WORK/paths-dbg.exe $WORK/paths-dbg.exe
 stdout 'binary contains module root: true'
-stdout 'binary contains GOROOT: true'
+stdout 'binary contains an empty GOROOT'
 
-# A binary built with -trimpath should not contain the current workspace
-# or GOROOT.
+# A binary built with -trimpath should not contain the current workspace.
 go build -overlay overlay.json -trimpath -o $WORK/paths-a.exe ./overlaydir
 exec $WORK/paths-a.exe $WORK/paths-a.exe
 stdout 'binary contains module root: false'
-stdout 'binary contains GOROOT: false'
+stdout 'binary contains an empty GOROOT'
 
 # Two binaries built from identical packages in different directories
 # should be identical.
@@ -77,13 +75,13 @@ env GOPATH=$WORK/a
 go build -o paths-dbg.exe paths
 exec ./paths-dbg.exe paths-dbg.exe
 stdout 'binary contains GOPATH: true'
-stdout 'binary contains GOROOT: true'
+stdout 'binary contains an empty GOROOT'
 
-# A binary built with -trimpath should not contain GOPATH or GOROOT.
+# A binary built with -trimpath should not contain GOPATH.
 go build -trimpath -o paths-a.exe paths
 exec ./paths-a.exe paths-a.exe
 stdout 'binary contains GOPATH: false'
-stdout 'binary contains GOROOT: false'
+stdout 'binary contains an empty GOROOT'
 
 # Two binaries built from identical packages in different GOPATH roots
 # should be identical.
@@ -103,13 +101,14 @@ env GOPATH=$WORK/a
 go build -compiler=gccgo -o paths-dbg.exe paths
 exec ./paths-dbg.exe paths-dbg.exe
 stdout 'binary contains GOPATH: true'
-stdout 'binary contains GOROOT: false' # gccgo doesn't load std from GOROOT.
+stdout 'binary contains an empty GOROOT'
 
+# gccgo doesn't load std from GOROOT.
 # A binary built with gccgo with -trimpath should not contain GOPATH or GOROOT.
 go build -compiler=gccgo -trimpath -o paths-a.exe paths
 exec ./paths-a.exe paths-a.exe
 stdout 'binary contains GOPATH: false'
-stdout 'binary contains GOROOT: false'
+stdout 'binary contains an empty GOROOT'
 
 # Two binaries built from identical packages in different directories
 # should be identical.
@@ -152,6 +151,10 @@ func main() {
 }
 
 func check(data []byte, desc, dir string) {
+       if dir == "" {
+               fmt.Printf("binary contains an empty %s\n", desc)
+               return
+       }
        containsDir := bytes.Contains(data, []byte(dir))
        containsSlashDir := bytes.Contains(data, []byte(filepath.ToSlash(dir)))
        fmt.Printf("binary contains %s: %v\n", desc, containsDir || containsSlashDir)
index a26cfd23be488cdf90afba4b270e9ad7469483c2..e31eccec06eec0377209257bd9db4409d8174692 100644 (file)
@@ -4,11 +4,6 @@
 # if GOROOT was not set explicitly in the environment.
 # It should instead return the empty string, since we know that we don't
 # have a valid path to return.
-#
-# TODO(#51483): when runtime.GOROOT() returns the empty string,
-# go/build should default to 'go env GOROOT' instead.
-
-env GOROOT_FINAL=
 
 [trimpath] env GOROOT=
 [trimpath] ! go env GOROOT
@@ -17,7 +12,7 @@ env GOROOT_FINAL=
 
 [short] stop
 
-# With GOROOT still set but GOROOT_FINAL unset, 'go build' and 'go test -c'
+# With GOROOT still set, 'go build' and 'go test -c'
 # should cause runtime.GOROOT() to report either the correct GOROOT
 # (without -trimpath) or no GOROOT at all (with -trimpath).
 
@@ -52,7 +47,6 @@ stderr 'cannot find package "runtime" in any of:\n\t\(\$GOROOT not set\)\n\t'$WO
 # code).
 
 [trimpath] stop
-[mismatched-goroot] stop
 
 ! go run -trimpath .
 stdout '^GOROOT $'
index b2a0e0c8d578ad135e44ba091773e82969aedaa6..7f0b515f2e55142988ccb707ab89222e9a88afd3 100644 (file)
@@ -1,5 +1,5 @@
 # Regression test for https://go.dev/issue/47215 and https://go.dev/issue/50183:
-# A mismatched $GOROOT_FINAL or missing $CC caused the C dependencies of the net
+# A missing $CC caused the C dependencies of the net
 # package to appear stale, and it could not be rebuilt due to a missing $CC.
 
 [!cgo] skip
 go build -x runtime/cgo
 [!short] stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo'
 
-# https://go.dev/issue/50183: a mismatched GOROOT_FINAL caused net to be stale.
-env oldGOROOT_FINAL=$GOROOT_FINAL
-env GOROOT_FINAL=$WORK${/}goroot
-go build -x runtime/cgo
-! stderr '[/\\]cgo'$GOEXE'["]? .* -importpath runtime/cgo'
-
-env GOROOT_FINAL=$oldGOROOT_FINAL
-
 # https://go.dev/issue/47215: a missing $(go env CC) caused the precompiled net
 # to be stale. But as of https://go.dev/cl/452457 the precompiled libraries are
 # no longer installed anyway! Since we're requiring a C compiler in order to
index e20dbd87ac4ce6b9fbbaabf14d6398017b0e4764..ea0f920a3764c9d61bc71124fa1cbb6e58449141 100644 (file)
@@ -3,16 +3,9 @@
 
 mkdir $WORK/new/bin
 
-# In this test, we are specifically checking the logic for deriving
-# the value of GOROOT from runtime.GOROOT.
-# GOROOT_FINAL changes the default behavior of runtime.GOROOT,
-# and will thus cause the test to fail if it is set when our
-# new cmd/go is built.
-env GOROOT_FINAL=
-
 # $GOROOT/bin/go is whatever the user has already installed
 # (using make.bash or similar). We can't make assumptions about what
-# options it may have been built with, such as -trimpath or GOROOT_FINAL.
+# options it may have been built with, such as -trimpath or not.
 # Instead, we build a fresh copy of the binary with known settings.
 go build -o $WORK/new/bin/go$GOEXE cmd/go &
 go build -trimpath -o $WORK/bin/check$GOEXE check.go &
index a3f0c39a836d6cdce58a9a9dd463b88f254c8c4c..6b859a6207d08941d5034bd843dc48a6fbc9cf9a 100644 (file)
@@ -14,13 +14,10 @@ mkdir $WORK/new/bin/${GOOS}_${GOARCH}
 # In this test, we are specifically checking the logic for deriving
 # the value of GOROOT from os.Executable when runtime.GOROOT is
 # trimmed away.
-# GOROOT_FINAL changes the default behavior of runtime.GOROOT,
-# so we explicitly clear it to remove it as a confounding variable.
-env GOROOT_FINAL=
 
 # $GOROOT/bin/go is whatever the user has already installed
 # (using make.bash or similar). We can't make assumptions about what
-# options it may have been built with, such as -trimpath or GOROOT_FINAL.
+# options it may have been built with, such as -trimpath or not.
 # Instead, we build a fresh copy of the binary with known settings.
 go build -trimpath -o $WORK/new/bin/go$GOEXE cmd/go &
 go build -trimpath -o $WORK/bin/check$GOEXE check.go &
index fedf58c05c8b9eed9161fda97242e70aac4c3a72..6b2b58d1c6479304f95e453d46709ac11521770b 100644 (file)
@@ -75,7 +75,7 @@ func TestRepeatBootstrap(t *testing.T) {
        var stdout strings.Builder
        cmd := exec.Command(filepath.Join(goroot, "src", makeScript))
        cmd.Dir = gorootSrc
-       cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_FINAL=", "GOROOT_BOOTSTRAP="+realGoroot)
+       cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+realGoroot)
        cmd.Stderr = os.Stderr
        cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
        if err := cmd.Run(); err != nil {
index f9693a49545427eb07c3226da6963dbd3e2174a1..2def029325be558f9da0998b3ba520ae98326269 100644 (file)
@@ -195,8 +195,6 @@ func TestAllDependencies(t *testing.T) {
                                Env: append(append(os.Environ(), modcacheEnv...),
                                        // Set GOROOT.
                                        "GOROOT="+gorootCopyDir,
-                                       // Explicitly clear GOROOT_FINAL so that GOROOT=gorootCopyDir is definitely used.
-                                       "GOROOT_FINAL=",
                                        // Add GOROOTcopy/bin and bundleDir to front of PATH.
                                        "PATH="+filepath.Join(gorootCopyDir, "bin")+string(filepath.ListSeparator)+
                                                bundleDir+string(filepath.ListSeparator)+os.Getenv("PATH"),
index 877b3a6be844fece3571d98eb88ed58f984d981d..a0cc52a02922640f17f04e8a5f6b19a8a7569fb6 100644 (file)
@@ -168,12 +168,12 @@ func Main(arch *sys.Arch, theArch Arch) {
                }
        }
 
-       if final := gorootFinal(); final == "$GOROOT" {
-               // cmd/go sets GOROOT_FINAL to the dummy value "$GOROOT" when -trimpath is set,
-               // but runtime.GOROOT() should return the empty string, not a bogus value.
-               // (See https://go.dev/issue/51461.)
+       if buildcfg.GOROOT == "" {
+               // cmd/go clears the GOROOT variable when -trimpath is set,
+               // so omit it from the binary even if cmd/link itself has an
+               // embedded GOROOT value reported by runtime.GOROOT.
        } else {
-               addstrdata1(ctxt, "runtime.defaultGOROOT="+final)
+               addstrdata1(ctxt, "runtime.defaultGOROOT="+buildcfg.GOROOT)
        }
 
        buildVersion := buildcfg.Version
index c5996f11d32cdd13f66a4dd723454f80f8093b4c..57c88c03aff64b87cda0ae6df133fe74f0028ecf 100644 (file)
@@ -13,7 +13,6 @@ import (
        "fmt"
        "internal/abi"
        "internal/buildcfg"
-       "os"
        "path/filepath"
        "strings"
 )
@@ -808,18 +807,10 @@ func (ctxt *Link) pclntab(container loader.Bitmap) *pclntab {
        return state
 }
 
-func gorootFinal() string {
-       root := buildcfg.GOROOT
-       if final := os.Getenv("GOROOT_FINAL"); final != "" {
-               root = final
-       }
-       return root
-}
-
 func expandGoroot(s string) string {
        const n = len("$GOROOT")
        if len(s) >= n+1 && s[:n] == "$GOROOT" && (s[n] == '/' || s[n] == '\\') {
-               if final := gorootFinal(); final != "" {
+               if final := buildcfg.GOROOT; final != "" {
                        return filepath.ToSlash(filepath.Join(final, s[n:]))
                }
        }
index 6e781c924d297017152ee60db28c71d236e802b5..a755ec3b64400e3a968b1e611d1deb155265545b 100644 (file)
@@ -152,9 +152,6 @@ func testDisasm(t *testing.T, srcfname string, printCode bool, printGnuAsm bool,
        cmd := testenv.Command(t, testenv.GoToolPath(t), args...)
        // "Bad line" bug #36683 is sensitive to being run in the source directory.
        cmd.Dir = "testdata"
-       // Ensure that the source file location embedded in the binary matches our
-       // actual current GOROOT, instead of GOROOT_FINAL if set.
-       cmd.Env = append(os.Environ(), "GOROOT_FINAL=")
        t.Logf("Running %v", cmd.Args)
        out, err := cmd.CombinedOutput()
        if err != nil {
index 0bf5b8f75c2e9a76e9185e30bee4fe956976a5bd..ac731f0e997e5edea77bf4021c2758722e1e5e67 100644 (file)
@@ -15,26 +15,25 @@ import (
        "fmt"
        "os"
        "path/filepath"
-       "runtime"
        "strconv"
        "strings"
 )
 
 var (
-       GOROOT    = runtime.GOROOT() // cached for efficiency
-       GOARCH    = envOr("GOARCH", defaultGOARCH)
-       GOOS      = envOr("GOOS", defaultGOOS)
-       GO386     = envOr("GO386", defaultGO386)
-       GOAMD64   = goamd64()
-       GOARM     = goarm()
-       GOMIPS    = gomips()
-       GOMIPS64  = gomips64()
-       GOPPC64   = goppc64()
+       GOROOT   = os.Getenv("GOROOT") // cached for efficiency
+       GOARCH   = envOr("GOARCH", defaultGOARCH)
+       GOOS     = envOr("GOOS", defaultGOOS)
+       GO386    = envOr("GO386", defaultGO386)
+       GOAMD64  = goamd64()
+       GOARM    = goarm()
+       GOMIPS   = gomips()
+       GOMIPS64 = gomips64()
+       GOPPC64  = goppc64()
        GORISCV64 = goriscv64()
-       GOWASM    = gowasm()
-       ToolTags  = toolTags()
-       GO_LDSO   = defaultGO_LDSO
-       Version   = version
+       GOWASM   = gowasm()
+       ToolTags = toolTags()
+       GO_LDSO  = defaultGO_LDSO
+       Version  = version
 )
 
 // Error is one of the errors found (if any) in the build configuration.
index 5c8013740e584aadd1bd7659aa03b7337bc0f2d6..f767ac590ca53c39c2f442c2e35e56faff49eefd 100644 (file)
@@ -189,15 +189,13 @@ func findGOROOT() (string, error) {
                        // If runtime.GOROOT() is non-empty, assume that it is valid.
                        //
                        // (It might not be: for example, the user may have explicitly set GOROOT
-                       // to the wrong directory, or explicitly set GOROOT_FINAL but not GOROOT
-                       // and hasn't moved the tree to GOROOT_FINAL yet. But those cases are
+                       // to the wrong directory. But this case is
                        // rare, and if that happens the user can fix what they broke.)
                        return
                }
 
                // runtime.GOROOT doesn't know where GOROOT is (perhaps because the test
-               // binary was built with -trimpath, or perhaps because GOROOT_FINAL was set
-               // without GOROOT and the tree hasn't been moved there yet).
+               // binary was built with -trimpath).
                //
                // Since this is internal/testenv, we can cheat and assume that the caller
                // is a test of some package in a subdirectory of GOROOT/src. ('go test'
index 76ad51624ac6eefa927c467f1afaccf45a1124c7..933573dd9d2e1b445355d0449901b74310b9689d 100755 (executable)
@@ -7,9 +7,6 @@
 
 # Environment variables that control make.bash:
 #
-# GOROOT_FINAL: The expected final Go root, baked into binaries.
-# The default is the location of the Go tree during the build.
-#
 # GOHOSTARCH: The architecture for host tools (compilers and
 # binaries).  Binaries of this type must be executable on the current
 # system, so the only common reason to set this is to set
index d9f9b6cb6aa252e7d695a9e94c8efd529587641e..53122cbaefd0c3f72fd4cf5d5cc1a08025749b45 100644 (file)
@@ -4,9 +4,6 @@
 \r
 :: Environment variables that control make.bat:\r
 ::\r
-:: GOROOT_FINAL: The expected final Go root, baked into binaries.\r
-:: The default is the location of the Go tree during the build.\r
-::\r
 :: GOHOSTARCH: The architecture for host tools (compilers and\r
 :: binaries).  Binaries of this type must be executable on the current\r
 :: system, so the only common reason to set this is to set\r
index b10be7dbd177c797102552436caf357278df8366..607e9360dc11ea54a5d93858e29d9083382842fe 100755 (executable)
@@ -7,9 +7,6 @@
 
 # Environment variables that control make.rc:
 #
-# GOROOT_FINAL: The expected final Go root, baked into binaries.
-# The default is the location of the Go tree during the build.
-#
 # GOHOSTARCH: The architecture for host tools (compilers and
 # binaries).  Binaries of this type must be executable on the current
 # system, so the only common reason to set this is to set
index 1ae6ff041a90f4c65400a31774f197f372f62280..5defe2f615eaa45e69764495d0fe0dcc45387f72 100644 (file)
@@ -54,9 +54,6 @@ func checkGdbEnvironment(t *testing.T) {
        case "plan9":
                t.Skip("there is no gdb on Plan 9")
        }
-       if final := os.Getenv("GOROOT_FINAL"); final != "" && testenv.GOROOT(t) != final {
-               t.Skip("gdb test can fail with GOROOT_FINAL pending")
-       }
 }
 
 func checkGdbVersion(t *testing.T) {
@@ -297,24 +294,6 @@ func testGdbPython(t *testing.T, cgo bool) {
        }
 
        got = bytes.ReplaceAll(got, []byte("\r\n"), []byte("\n")) // normalize line endings
-       firstLine, _, _ := bytes.Cut(got, []byte("\n"))
-       if string(firstLine) != "Loading Go Runtime support." {
-               // This can happen when using all.bash with
-               // GOROOT_FINAL set, because the tests are run before
-               // the final installation of the files.
-               cmd := exec.Command(testenv.GoToolPath(t), "env", "GOROOT")
-               cmd.Env = []string{}
-               out, err := cmd.CombinedOutput()
-               if err != nil && bytes.Contains(out, []byte("cannot find GOROOT")) {
-                       t.Skipf("skipping because GOROOT=%s does not exist", testenv.GOROOT(t))
-               }
-
-               _, file, _, _ := runtime.Caller(1)
-
-               t.Logf("package testing source file: %s", file)
-               t.Fatalf("failed to load Go runtime support: %s\n%s", firstLine, got)
-       }
-
        // Extract named BEGIN...END blocks from output
        partRe := regexp.MustCompile(`(?ms)^BEGIN ([^\n]*)\n(.*?)\nEND`)
        blocks := map[string]string{}
index 19a6cc6f8d385a2aede64c36c6a888c1ea9edb5b..e00d6cf202dda81e286f5c454c7838e30da879ad 100644 (file)
@@ -135,9 +135,6 @@ intvar = 42
 
 func TestLldbPython(t *testing.T) {
        testenv.MustHaveGoBuild(t)
-       if final := os.Getenv("GOROOT_FINAL"); final != "" && runtime.GOROOT() != final {
-               t.Skip("gdb test can fail with GOROOT_FINAL pending")
-       }
        testenv.SkipFlaky(t, 31188)
 
        checkLldbPython(t)