diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index bae83eb92fa2e..32822950f10a4 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -881,22 +881,17 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) { // Copy the runtime packages into a temporary GOROOT // so that we can change files. - for _, copydir := range []string{ - "src/runtime", - "src/internal/abi", - "src/internal/bytealg", - "src/internal/coverage/rtcov", - "src/internal/cpu", - "src/internal/goarch", - "src/internal/godebugs", - "src/internal/goexperiment", - "src/internal/goos", - "src/internal/coverage/rtcov", - "src/math/bits", - "src/unsafe", + var dirs []string + tg.run("list", "-deps", "runtime") + pkgs := strings.Split(strings.TrimSpace(tg.getStdout()), "\n") + for _, pkg := range pkgs { + dirs = append(dirs, filepath.Join("src", pkg)) + } + dirs = append(dirs, filepath.Join("pkg/tool", goHostOS+"_"+goHostArch), "pkg/include", - } { + ) + for _, copydir := range dirs { srcdir := filepath.Join(testGOROOT, copydir) tg.tempDir(filepath.Join("goroot", copydir)) err := filepath.WalkDir(srcdir, @@ -912,6 +907,9 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) { return err } dest := filepath.Join("goroot", copydir, srcrel) + if _, err := os.Stat(dest); err == nil { + return nil + } data, err := os.ReadFile(path) if err != nil { return err