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.
8 // This test verifies that GOEXPERIMENT settings built
9 // into the toolchain influence tool ids in the Go command.
10 // This test requires bootstrapping the toolchain twice, so it's very expensive.
11 // It must be run explicitly with -tags=explicit.
12 // Verifies golang.org/issue/33091.
14 package bootstrap_test
25 func TestExperimentToolID(t *testing.T) {
27 goroot, err := os.MkdirTemp("", "experiment-goroot")
31 defer os.RemoveAll(goroot)
33 gorootSrc := filepath.Join(goroot, "src")
34 if err := overlayDir(gorootSrc, filepath.Join(runtime.GOROOT(), "src")); err != nil {
38 if err := os.WriteFile(filepath.Join(goroot, "VERSION"), []byte("go1.999"), 0666); err != nil {
41 env := append(os.Environ(), "GOROOT=", "GOROOT_BOOTSTRAP="+runtime.GOROOT())
44 gocache, err := os.MkdirTemp("", "experiment-gocache")
48 defer os.RemoveAll(gocache)
49 env = append(env, "GOCACHE="+gocache)
51 // Build the toolchain without GOEXPERIMENT.
55 makeScript = "make.bat"
57 makeScript = "make.rc"
59 makeScript = "make.bash"
61 makeScriptPath := filepath.Join(runtime.GOROOT(), "src", makeScript)
62 runCmd(t, gorootSrc, env, makeScriptPath)
64 // Verify compiler version string.
65 goCmdPath := filepath.Join(goroot, "bin", "go")
66 if runtime.GOOS == "windows" {
69 gotVersion := bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
70 wantVersion := []byte(`compile version go1.999`)
71 if !bytes.Equal(gotVersion, wantVersion) {
72 t.Errorf("compile version without experiment: got %q, want %q", gotVersion, wantVersion)
75 // Build a package in a mode not handled by the make script.
76 runCmd(t, gorootSrc, env, goCmdPath, "build", "-race", "archive/tar")
78 // Rebuild the toolchain with GOEXPERIMENT.
79 env = append(env, "GOEXPERIMENT=fieldtrack")
80 runCmd(t, gorootSrc, env, makeScriptPath)
82 // Verify compiler version string.
83 gotVersion = bytes.TrimSpace(runCmd(t, gorootSrc, env, goCmdPath, "tool", "compile", "-V=full"))
84 wantVersion = []byte(`compile version go1.999 X:fieldtrack,framepointer`)
85 if !bytes.Equal(gotVersion, wantVersion) {
86 t.Errorf("compile version with experiment: got %q, want %q", gotVersion, wantVersion)
89 // Build the same package. We should not get a cache conflict.
90 runCmd(t, gorootSrc, env, goCmdPath, "build", "-race", "archive/tar")
93 func runCmd(t *testing.T, dir string, env []string, path string, args ...string) []byte {
94 cmd := exec.Command(path, args...)
97 out, err := cmd.Output()