1
0
mirror of https://github.com/golang/go synced 2024-11-24 21:00:09 -07:00

misc/goplay: use go run x.go instead of go build x.go

when the program is not main package, `go run x.go` can't return the
link error message. so use `go run x.go` in instead `go build x.go`.

Fixes #5865.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/11165043
This commit is contained in:
ChaiShushan 2013-07-12 09:41:10 +10:00 committed by Andrew Gerrand
parent 63f54ae3c2
commit 8529d99e1d

View File

@ -14,7 +14,6 @@ import (
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strconv"
"text/template"
)
@ -92,10 +91,6 @@ func compile(req *http.Request) (out []byte, err error) {
// x is the base name for .go, .6, executable files
x := filepath.Join(tmpdir, "compile"+strconv.Itoa(<-uniq))
src := x + ".go"
bin := x
if runtime.GOOS == "windows" {
bin += ".exe"
}
// rewrite filename in error output
defer func() {
@ -116,16 +111,13 @@ func compile(req *http.Request) (out []byte, err error) {
return
}
// build x.go, creating x
// go run x.go
dir, file := filepath.Split(src)
out, err = run(dir, "go", "build", "-o", bin, file)
defer os.Remove(bin)
out, err = run(dir, "go", "run", file)
if err != nil {
return
}
// run x
return run("", bin)
return out, nil
}
// error writes compile, link, or runtime errors to the HTTP connection.