Skip to content

Commit 72f333a

Browse files
author
Bryan C. Mills
committed
Revert "test: avoid writing temporary files to GOROOT"
This reverts CL 207352 Reason for revert: broke more builders than it fixed. 😞 Change-Id: Ic5adefe92edfa2230b9c7d750c922473a6a5ded4 Reviewed-on: https://go-review.googlesource.com/c/go/+/207477 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent dab1a10 commit 72f333a

File tree

6 files changed

+41
-73
lines changed

6 files changed

+41
-73
lines changed

src/cmd/dist/test.go

+5-9
Original file line numberDiff line numberDiff line change
@@ -1358,21 +1358,17 @@ var runtest struct {
13581358

13591359
func (t *tester) testDirTest(dt *distTest, shard, shards int) error {
13601360
runtest.Do(func() {
1361-
f, err := ioutil.TempFile("", "runtest-*.exe") // named exe for Windows, but harmless elsewhere
1362-
if err != nil {
1361+
const exe = "runtest.exe" // named exe for Windows, but harmless elsewhere
1362+
cmd := t.dirCmd("test", "go", "build", "-o", exe, "run.go")
1363+
cmd.Env = append(os.Environ(), "GOOS="+gohostos, "GOARCH="+gohostarch)
1364+
runtest.exe = filepath.Join(cmd.Dir, exe)
1365+
if err := cmd.Run(); err != nil {
13631366
runtest.err = err
13641367
return
13651368
}
1366-
f.Close()
1367-
1368-
runtest.exe = f.Name()
13691369
xatexit(func() {
13701370
os.Remove(runtest.exe)
13711371
})
1372-
1373-
cmd := t.dirCmd("test", "go", "build", "-o", runtest.exe, "run.go")
1374-
cmd.Env = append(os.Environ(), "GOOS="+gohostos, "GOARCH="+gohostarch)
1375-
runtest.err = cmd.Run()
13761372
})
13771373
if runtest.err != nil {
13781374
return runtest.err

test/fixedbugs/bug302.go

+6-18
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,22 @@ package main
99

1010
import (
1111
"fmt"
12-
"io/ioutil"
1312
"os"
1413
"os/exec"
1514
"path/filepath"
1615
)
1716

18-
var tmpDir string
19-
2017
func main() {
21-
fb, err := filepath.Abs("fixedbugs")
22-
if err == nil {
23-
tmpDir, err = ioutil.TempDir("", "bug302")
24-
}
25-
if err != nil {
26-
fmt.Println(err)
27-
os.Exit(1)
28-
}
29-
defer os.RemoveAll(tmpDir)
30-
31-
run("go", "tool", "compile", filepath.Join(fb, "bug302.dir", "p.go"))
18+
run("go", "tool", "compile", filepath.Join("fixedbugs", "bug302.dir", "p.go"))
3219
run("go", "tool", "pack", "grc", "pp.a", "p.o")
33-
run("go", "tool", "compile", "-I", ".", filepath.Join(fb, "bug302.dir", "main.go"))
20+
run("go", "tool", "compile", "-I", ".", filepath.Join("fixedbugs", "bug302.dir", "main.go"))
21+
os.Remove("p.o")
22+
os.Remove("pp.a")
23+
os.Remove("main.o")
3424
}
3525

3626
func run(cmd string, args ...string) {
37-
c := exec.Command(cmd, args...)
38-
c.Dir = tmpDir
39-
out, err := c.CombinedOutput()
27+
out, err := exec.Command(cmd, args...).CombinedOutput()
4028
if err != nil {
4129
fmt.Println(string(out))
4230
fmt.Println(err)

test/fixedbugs/bug369.go

+9-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package main
1111

1212
import (
1313
"fmt"
14-
"io/ioutil"
1514
"os"
1615
"os/exec"
1716
"path/filepath"
@@ -21,19 +20,16 @@ func main() {
2120
err := os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir"))
2221
check(err)
2322

24-
tmpDir, err := ioutil.TempDir("", "bug369")
25-
check(err)
26-
defer os.RemoveAll(tmpDir)
27-
28-
tmp := func(name string) string {
29-
return filepath.Join(tmpDir, name)
30-
}
23+
run("go", "tool", "compile", "-N", "-o", "slow.o", "pkg.go")
24+
run("go", "tool", "compile", "-o", "fast.o", "pkg.go")
25+
run("go", "tool", "compile", "-o", "main.o", "main.go")
26+
run("go", "tool", "link", "-o", "a.exe", "main.o")
27+
run("." + string(filepath.Separator) + "a.exe")
3128

32-
run("go", "tool", "compile", "-N", "-o", tmp("slow.o"), "pkg.go")
33-
run("go", "tool", "compile", "-o", tmp("fast.o"), "pkg.go")
34-
run("go", "tool", "compile", "-D", tmpDir, "-o", tmp("main.o"), "main.go")
35-
run("go", "tool", "link", "-o", tmp("a.exe"), tmp("main.o"))
36-
run(tmp("a.exe"))
29+
os.Remove("slow.o")
30+
os.Remove("fast.o")
31+
os.Remove("main.o")
32+
os.Remove("a.exe")
3733
}
3834

3935
func run(name string, args ...string) {

test/fixedbugs/issue9355.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func main() {
2323
err := os.Chdir(filepath.Join("fixedbugs", "issue9355.dir"))
2424
check(err)
2525

26-
out := run("go", "tool", "compile", "-o", os.DevNull, "-S", "a.go")
26+
out := run("go", "tool", "compile", "-S", "a.go")
27+
os.Remove("a.o")
2728

2829
// 6g/8g print the offset as dec, but 5g/9g print the offset as hex.
2930
patterns := []string{

test/linkmain_run.go

+17-27
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ package main
1111

1212
import (
1313
"fmt"
14-
"io/ioutil"
1514
"os"
1615
"os/exec"
17-
"path/filepath"
1816
"strings"
1917
)
2018

21-
var tmpDir string
22-
2319
func cleanup() {
24-
os.RemoveAll(tmpDir)
20+
os.Remove("linkmain.o")
21+
os.Remove("linkmain.a")
22+
os.Remove("linkmain1.o")
23+
os.Remove("linkmain1.a")
24+
os.Remove("linkmain.exe")
2525
}
2626

27-
func run(cmdline ...string) {
28-
args := strings.Fields(strings.Join(cmdline, " "))
27+
func run(cmdline string) {
28+
args := strings.Fields(cmdline)
2929
cmd := exec.Command(args[0], args[1:]...)
3030
out, err := cmd.CombinedOutput()
3131
if err != nil {
@@ -37,8 +37,8 @@ func run(cmdline ...string) {
3737
}
3838
}
3939

40-
func runFail(cmdline ...string) {
41-
args := strings.Fields(strings.Join(cmdline, " "))
40+
func runFail(cmdline string) {
41+
args := strings.Fields(cmdline)
4242
cmd := exec.Command(args[0], args[1:]...)
4343
out, err := cmd.CombinedOutput()
4444
if err == nil {
@@ -51,26 +51,16 @@ func runFail(cmdline ...string) {
5151
}
5252

5353
func main() {
54-
var err error
55-
tmpDir, err = ioutil.TempDir("", "")
56-
if err != nil {
57-
fmt.Println(err)
58-
os.Exit(1)
59-
}
60-
tmp := func(name string) string {
61-
return filepath.Join(tmpDir, name)
62-
}
63-
6454
// helloworld.go is package main
65-
run("go tool compile -o", tmp("linkmain.o"), "helloworld.go")
66-
run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go")
67-
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o"))
68-
run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a"))
55+
run("go tool compile -o linkmain.o helloworld.go")
56+
run("go tool compile -pack -o linkmain.a helloworld.go")
57+
run("go tool link -o linkmain.exe linkmain.o")
58+
run("go tool link -o linkmain.exe linkmain.a")
6959

7060
// linkmain.go is not
71-
run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go")
72-
run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go")
73-
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o"))
74-
runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a"))
61+
run("go tool compile -o linkmain1.o linkmain.go")
62+
run("go tool compile -pack -o linkmain1.a linkmain.go")
63+
runFail("go tool link -o linkmain.exe linkmain1.o")
64+
runFail("go tool link -o linkmain.exe linkmain1.a")
7565
cleanup()
7666
}

test/sinit_run.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ import (
1717
)
1818

1919
func main() {
20-
cmd := exec.Command("go", "tool", "compile", "-o", os.DevNull, "-S", "sinit.go")
20+
cmd := exec.Command("go", "tool", "compile", "-S", "sinit.go")
2121
out, err := cmd.CombinedOutput()
2222
if err != nil {
2323
fmt.Println(string(out))
2424
fmt.Println(err)
2525
os.Exit(1)
2626
}
27+
os.Remove("sinit.o")
2728

28-
if len(bytes.TrimSpace(out)) == 0 {
29-
fmt.Println("'go tool compile -S sinit.go' printed no output")
30-
os.Exit(1)
31-
}
3229
if bytes.Contains(out, []byte("initdone")) {
3330
fmt.Println("sinit generated an init function")
3431
os.Exit(1)

0 commit comments

Comments
 (0)