]> Cypherpunks repositories - gostls13.git/commitdiff
misc/goplay: use `go run x.go` instead of `go build x.go`
authorChaiShushan <chaishushan@gmail.com>
Thu, 11 Jul 2013 23:41:10 +0000 (09:41 +1000)
committerAndrew Gerrand <adg@golang.org>
Thu, 11 Jul 2013 23:41:10 +0000 (09:41 +1000)
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

misc/goplay/goplay.go

index 94d04139dd6a063534db687e138378129806d1be..9cb7d7bfb8a938ebeacdad7d1efa59f1814878ed 100644 (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.