1 // Copyright 2019 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package bootstrap_test verifies that the current GOROOT can be used to bootstrap
22 func TestRepeatBootstrap(t *testing.T) {
24 t.Skipf("skipping test that rebuilds the entire toolchain")
27 case "android", "ios", "js", "wasip1":
28 t.Skipf("skipping because the toolchain does not have to bootstrap on GOOS=%s", runtime.GOOS)
31 realGoroot := testenv.GOROOT(t)
33 // To ensure that bootstrapping doesn't unexpectedly depend
34 // on the Go repo's git metadata, add a fake (unreadable) git
35 // directory above the simulated GOROOT.
36 // This mimics the configuration one much have when
37 // building from distro-packaged source code
38 // (see https://go.dev/issue/54852).
40 dotGit := filepath.Join(parent, ".git")
41 if err := os.Mkdir(dotGit, 000); err != nil {
45 overlayStart := time.Now()
47 goroot := filepath.Join(parent, "goroot")
49 gorootSrc := filepath.Join(goroot, "src")
50 if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
54 gorootLib := filepath.Join(goroot, "lib")
55 if err := overlayDir(gorootLib, filepath.Join(realGoroot, "lib")); err != nil {
59 t.Logf("GOROOT overlay set up in %s", time.Since(overlayStart))
61 if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte(runtime.Version()), 0666); err != nil {
68 makeScript = "make.bat"
70 makeScript = "make.rc"
72 makeScript = "make.bash"
75 var stdout strings.Builder
76 cmd := exec.Command(filepath.Join(goroot, "src", makeScript))
78 cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_FINAL=", "GOROOT_BOOTSTRAP="+realGoroot)
79 cmd.Stderr = os.Stderr
80 cmd.Stdout = io.MultiWriter(os.Stdout, &stdout)
81 if err := cmd.Run(); err != nil {
85 // Test that go.dev/issue/42563 hasn't regressed.
86 t.Run("PATH reminder", func(t *testing.T) {
88 switch gorootBin := filepath.Join(goroot, "bin"); runtime.GOOS {
90 want = fmt.Sprintf("*** You need to add %s to your PATH.", gorootBin)
92 want = fmt.Sprintf("*** You need to bind %s before /bin.", gorootBin)
94 if got := stdout.String(); !strings.Contains(got, want) {
95 t.Errorf("reminder %q is missing from %s stdout:\n%s", want, makeScript, got)