mirror of
https://github.com/golang/go
synced 2024-11-26 03:37:57 -07:00
9cad0cc6e6
Previously, all.bash and all.bat restored the original $PATH before calling 'dist banner', so that it would do its job of checking whether the user still needs to add $GOROOT/bin to their $PATH. That worked for those scripts, but had no effect on make.bash nor make.bat. Instead of trying to extend that logic to more scripts, change the approach to provide dist an unmodified copy of $PATH via an internal to dist environment variable $DIST_UNMODIFIED_PATH. The make.bash and make.bat scripts happen to use dist env -p to modify $PATH, making it viable to add the internal variable there instead of in each script. It currently works by adding semicolon terminators to dist env output so that make.bash's 'eval $(dist env -p)' works as before but is able to export DIST_UNMODIFIED_PATH for following dist invocations to observe. Nothing needs to be done for Windows since its 'set ENV=val' format already has that effect. Plan 9 doesn't use the -p flag of dist env, and checks that GOROOT/bin is bound before /bin rather than looking at the $PATH env var like other OSes, so it may not have this bug. I don't have easy access to Plan 9 and haven't tried to confirm. Fixes #42563. Change-Id: I74691931167e974a930f7589d22a48bb6b931163 Reviewed-on: https://go-review.googlesource.com/c/go/+/485896 Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
97 lines
2.5 KiB
Go
97 lines
2.5 KiB
Go
// Copyright 2019 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package reboot_test verifies that the current GOROOT can be used to bootstrap
|
|
// itself.
|
|
package reboot_test
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRepeatBootstrap(t *testing.T) {
|
|
if testing.Short() {
|
|
t.Skipf("skipping test that rebuilds the entire toolchain")
|
|
}
|
|
|
|
realGoroot, err := filepath.Abs(filepath.Join("..", ".."))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// To ensure that bootstrapping doesn't unexpectedly depend
|
|
// on the Go repo's git metadata, add a fake (unreadable) git
|
|
// directory above the simulated GOROOT.
|
|
// This mimics the configuration one much have when
|
|
// building from distro-packaged source code
|
|
// (see https://go.dev/issue/54852).
|
|
parent := t.TempDir()
|
|
dotGit := filepath.Join(parent, ".git")
|
|
if err := os.Mkdir(dotGit, 000); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
overlayStart := time.Now()
|
|
|
|
goroot := filepath.Join(parent, "goroot")
|
|
|
|
gorootSrc := filepath.Join(goroot, "src")
|
|
if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
gorootLib := filepath.Join(goroot, "lib")
|
|
if err := overlayDir(gorootLib, filepath.Join(realGoroot, "lib")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
t.Logf("GOROOT overlay set up in %s", time.Since(overlayStart))
|
|
|
|
if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
var makeScript string
|
|
switch runtime.GOOS {
|
|
case "windows":
|
|
makeScript = "make.bat"
|
|
case "plan9":
|
|
makeScript = "make.rc"
|
|
default:
|
|
makeScript = "make.bash"
|
|
}
|
|
|
|
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.Stderr = os.Stderr
|
|
cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
|
|
if err := cmd.Run(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// Test that go.dev/issue/42563 hasn't regressed.
|
|
t.Run("PATH reminder", func(t *testing.T) {
|
|
var want string
|
|
switch gorootBin := filepath.Join(goroot, "bin"); runtime.GOOS {
|
|
default:
|
|
want = fmt.Sprintf("*** You need to add %s to your PATH.", gorootBin)
|
|
case "plan9":
|
|
want = fmt.Sprintf("*** You need to bind %s before /bin.", gorootBin)
|
|
}
|
|
if got := stdout.String(); !strings.Contains(got, want) {
|
|
t.Errorf("reminder %q is missing from %s stdout:\n%s", want, makeScript, got)
|
|
}
|
|
})
|
|
}
|