diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-11-18 13:58:58 +0000 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-11-18 14:40:07 +0000 |
commit | afac2c0508208ce0baf0cf2f0ba9b86ee7b60469 (patch) | |
tree | 5b36426e150e74235bb481e99528475f82d5c9d4 /test/linkmain_run.go | |
parent | 2bde3c13f6e31662c682f1b5830c5e3fd9f5494c (diff) | |
download | go-afac2c0508208ce0baf0cf2f0ba9b86ee7b60469.tar.gz go-afac2c0508208ce0baf0cf2f0ba9b86ee7b60469.zip |
test: avoid writing temporary files to GOROOT
This reverts CL 207477, restoring CL 207352 with a fix for the
regression observed in the Windows builders.
cmd/compile evidently does not fully support NUL as an output on
Windows, so this time we write ignored 'compile' outputs
to temporary files (instead of os.DevNull as in CL 207352).
Updates #28387
Fixes #35619
Change-Id: I2edc5727c3738fa1bccb4b74e50d114cf2a7fcff
Reviewed-on: https://go-review.googlesource.com/c/go/+/207602
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test/linkmain_run.go')
-rw-r--r-- | test/linkmain_run.go | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/test/linkmain_run.go b/test/linkmain_run.go index 68d53e8cad..077f7ee917 100644 --- a/test/linkmain_run.go +++ b/test/linkmain_run.go @@ -11,21 +11,21 @@ package main import ( "fmt" + "io/ioutil" "os" "os/exec" + "path/filepath" "strings" ) +var tmpDir string + func cleanup() { - os.Remove("linkmain.o") - os.Remove("linkmain.a") - os.Remove("linkmain1.o") - os.Remove("linkmain1.a") - os.Remove("linkmain.exe") + os.RemoveAll(tmpDir) } -func run(cmdline string) { - args := strings.Fields(cmdline) +func run(cmdline ...string) { + args := strings.Fields(strings.Join(cmdline, " ")) cmd := exec.Command(args[0], args[1:]...) out, err := cmd.CombinedOutput() if err != nil { @@ -37,8 +37,8 @@ func run(cmdline string) { } } -func runFail(cmdline string) { - args := strings.Fields(cmdline) +func runFail(cmdline ...string) { + args := strings.Fields(strings.Join(cmdline, " ")) cmd := exec.Command(args[0], args[1:]...) out, err := cmd.CombinedOutput() if err == nil { @@ -51,16 +51,26 @@ func runFail(cmdline string) { } func main() { + var err error + tmpDir, err = ioutil.TempDir("", "") + if err != nil { + fmt.Println(err) + os.Exit(1) + } + tmp := func(name string) string { + return filepath.Join(tmpDir, name) + } + // helloworld.go is package main - run("go tool compile -o linkmain.o helloworld.go") - run("go tool compile -pack -o linkmain.a helloworld.go") - run("go tool link -o linkmain.exe linkmain.o") - run("go tool link -o linkmain.exe linkmain.a") + run("go tool compile -o", tmp("linkmain.o"), "helloworld.go") + run("go tool compile -pack -o", tmp("linkmain.a"), "helloworld.go") + run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.o")) + run("go tool link -o", tmp("linkmain.exe"), tmp("linkmain.a")) // linkmain.go is not - run("go tool compile -o linkmain1.o linkmain.go") - run("go tool compile -pack -o linkmain1.a linkmain.go") - runFail("go tool link -o linkmain.exe linkmain1.o") - runFail("go tool link -o linkmain.exe linkmain1.a") + run("go tool compile -o", tmp("linkmain1.o"), "linkmain.go") + run("go tool compile -pack -o", tmp("linkmain1.a"), "linkmain.go") + runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.o")) + runFail("go tool link -o", tmp("linkmain.exe"), tmp("linkmain1.a")) cleanup() } |