mirror of
https://github.com/golang/go
synced 2024-11-22 03:54:39 -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:
parent
63f54ae3c2
commit
8529d99e1d
@ -14,7 +14,6 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"text/template"
|
"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 is the base name for .go, .6, executable files
|
||||||
x := filepath.Join(tmpdir, "compile"+strconv.Itoa(<-uniq))
|
x := filepath.Join(tmpdir, "compile"+strconv.Itoa(<-uniq))
|
||||||
src := x + ".go"
|
src := x + ".go"
|
||||||
bin := x
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
bin += ".exe"
|
|
||||||
}
|
|
||||||
|
|
||||||
// rewrite filename in error output
|
// rewrite filename in error output
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -116,16 +111,13 @@ func compile(req *http.Request) (out []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// build x.go, creating x
|
// go run x.go
|
||||||
dir, file := filepath.Split(src)
|
dir, file := filepath.Split(src)
|
||||||
out, err = run(dir, "go", "build", "-o", bin, file)
|
out, err = run(dir, "go", "run", file)
|
||||||
defer os.Remove(bin)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
return out, nil
|
||||||
// run x
|
|
||||||
return run("", bin)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// error writes compile, link, or runtime errors to the HTTP connection.
|
// error writes compile, link, or runtime errors to the HTTP connection.
|
||||||
|
Loading…
Reference in New Issue
Block a user