Skip to content

Commit c077c74

Browse files
cmd/go: don't modify GOROOT in TestNewReleaseRebuildsStalePackagesInGOPATH
Fixes #29263 Change-Id: I06ba135dc491fd01fc06ccaad4ef98103d4b86c4 Reviewed-on: https://go-review.googlesource.com/c/154460 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent dd1889c commit c077c74

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

src/cmd/go/go_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -866,12 +866,54 @@ func (tg *testgoData) failSSH() {
866866

867867
func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
868868
if testing.Short() {
869-
t.Skip("don't rebuild the standard library in short mode")
869+
t.Skip("skipping lengthy test in short mode")
870870
}
871871

872872
tg := testgo(t)
873873
defer tg.cleanup()
874874

875+
// Copy the runtime packages into a temporary GOROOT
876+
// so that we can change files.
877+
for _, copydir := range []string{
878+
"src/runtime",
879+
"src/internal/bytealg",
880+
"src/internal/cpu",
881+
"src/unsafe",
882+
filepath.Join("pkg", runtime.GOOS+"_"+runtime.GOARCH),
883+
filepath.Join("pkg/tool", runtime.GOOS+"_"+runtime.GOARCH),
884+
"pkg/include",
885+
} {
886+
srcdir := filepath.Join(testGOROOT, copydir)
887+
tg.tempDir(filepath.Join("goroot", copydir))
888+
err := filepath.Walk(srcdir,
889+
func(path string, info os.FileInfo, err error) error {
890+
if err != nil {
891+
return err
892+
}
893+
if info.IsDir() {
894+
return nil
895+
}
896+
srcrel, err := filepath.Rel(srcdir, path)
897+
if err != nil {
898+
return err
899+
}
900+
dest := filepath.Join("goroot", copydir, srcrel)
901+
data, err := ioutil.ReadFile(path)
902+
if err != nil {
903+
return err
904+
}
905+
tg.tempFile(dest, string(data))
906+
if err := os.Chmod(tg.path(dest), info.Mode()); err != nil {
907+
return err
908+
}
909+
return nil
910+
})
911+
if err != nil {
912+
t.Fatal(err)
913+
}
914+
}
915+
tg.setenv("GOROOT", tg.path("goroot"))
916+
875917
addVar := func(name string, idx int) (restore func()) {
876918
data, err := ioutil.ReadFile(name)
877919
if err != nil {
@@ -900,7 +942,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
900942
// Changing mtime of runtime/internal/sys/sys.go
901943
// should have no effect: only the content matters.
902944
// In fact this should be true even outside a release branch.
903-
sys := runtime.GOROOT() + "/src/runtime/internal/sys/sys.go"
945+
sys := tg.path("goroot/src/runtime/internal/sys/sys.go")
904946
tg.sleep()
905947
restore := addVar(sys, 0)
906948
restore()
@@ -915,7 +957,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
915957
restore()
916958
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale, incorrectly, after changing back to old release")
917959
addVar(sys, 2)
918-
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
960+
tg.wantStale("p1", "stale dependency: runtime", "./testgo list claims p1 is NOT stale, incorrectly, after changing sys.go again")
919961
tg.run("install", "-i", "p1")
920962
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with new release")
921963

@@ -924,9 +966,6 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
924966
tg.wantStale("p1", "stale dependency: runtime/internal/sys", "./testgo list claims p1 is NOT stale, incorrectly, after restoring sys.go")
925967
tg.run("install", "-i", "p1")
926968
tg.wantNotStale("p1", "", "./testgo list claims p1 is stale after building with old release")
927-
928-
// Everything is out of date. Rebuild to leave things in a better state.
929-
tg.run("install", "std")
930969
}
931970

932971
func testLocalRun(tg *testgoData, exepath, local, match string) {

0 commit comments

Comments
 (0)