]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: omit VCS stamping during bootstrap
authorBryan C. Mills <bcmills@google.com>
Fri, 9 Sep 2022 21:29:12 +0000 (17:29 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 22 Sep 2022 18:55:06 +0000 (18:55 +0000)
cmd/dist can't easily hard-code -buildvcs=false because not all
versions of cmd/go supported for bootstrapping recognize that flag.

However, we don't want to stamp the bootstrap binaries: the stamping
is redundant with the VERSION file writted during bootstrapping (which
is why it is normally omitted for standard-library packages and
commands), and it may also interfere with building the Go repo from a
source tarball or zip file.

Fixes #54852.

Change-Id: If223f094af137c4c202d6bf622619bd2da397ec4
Reviewed-on: https://go-review.googlesource.com/c/go/+/432435
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

misc/reboot/reboot_test.go
src/cmd/go/internal/load/pkg.go

index a134affbc244558bb1dd83ee34baab60ce28b1c1..a1b513b4324abfc2e6a1c0c48154d75919f2e663 100644 (file)
@@ -20,11 +20,27 @@ func TestRepeatBootstrap(t *testing.T) {
                t.Skipf("skipping test that rebuilds the entire toolchain")
        }
 
-       goroot := t.TempDir()
+       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)
+       }
+       goroot := filepath.Join(parent, "goroot")
 
        gorootSrc := filepath.Join(goroot, "src")
        overlayStart := time.Now()
-       if err := overlayDir(gorootSrc, filepath.Join(runtime.GOROOT(), "src")); err != nil {
+       if err := overlayDir(gorootSrc, filepath.Join(realGoroot, "src")); err != nil {
                t.Fatal(err)
        }
        t.Logf("GOROOT/src overlay set up in %s", time.Since(overlayStart))
@@ -43,9 +59,9 @@ func TestRepeatBootstrap(t *testing.T) {
                makeScript = "make.bash"
        }
 
-       cmd := exec.Command(filepath.Join(runtime.GOROOT(), "src", makeScript))
+       cmd := exec.Command(filepath.Join(goroot, "src", makeScript))
        cmd.Dir = gorootSrc
-       cmd.Env = append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
+       cmd.Env = append(cmd.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+realGoroot)
        cmd.Stderr = os.Stderr
        cmd.Stdout = os.Stdout
        if err := cmd.Run(); err != nil {
index b1e4549d71deadcfd66bd46e7118fec4e0722745..a6e380b89f002dd867c49b745f44a9c86669b9e9 100644 (file)
@@ -2441,6 +2441,12 @@ func (p *Package) setBuildInfo(autoVCS bool) {
        }
 
        if wantVCS && p.Module != nil && p.Module.Version == "" && !p.Standard {
+               if p.Module.Path == "bootstrap" && cfg.GOROOT == os.Getenv("GOROOT_BOOTSTRAP") {
+                       // During bootstrapping, the bootstrap toolchain is built in module
+                       // "bootstrap" (instead of "std"), with GOROOT set to GOROOT_BOOTSTRAP
+                       // (so the bootstrap toolchain packages don't even appear to be in GOROOT).
+                       goto omitVCS
+               }
                repoDir, vcsCmd, err = vcs.FromDir(base.Cwd(), "", allowNesting)
                if err != nil && !errors.Is(err, os.ErrNotExist) {
                        setVCSError(err)