mirror of
https://github.com/golang/go
synced 2024-11-21 21:44:40 -07:00
goplay: fix to run under windows.
Fixes #1204. R=golang-dev, brainman, Joe Poirier, alex.brainman, adg CC=golang-dev, math-nuts https://golang.org/cl/2532041
This commit is contained in:
parent
91e69efb0d
commit
e64280ecfa
@ -74,15 +74,21 @@ func FrontPage(w http.ResponseWriter, req *http.Request) {
|
|||||||
// and sends the program's output as the HTTP response.
|
// and sends the program's output as the HTTP response.
|
||||||
func Compile(w http.ResponseWriter, req *http.Request) {
|
func Compile(w http.ResponseWriter, req *http.Request) {
|
||||||
// x is the base name for .go, .6, executable files
|
// x is the base name for .go, .6, executable files
|
||||||
x := "/tmp/compile" + strconv.Itoa(<-uniq)
|
x := os.TempDir() + "/compile" + strconv.Itoa(<-uniq)
|
||||||
|
src := x + ".go"
|
||||||
|
obj := x + "." + archChar
|
||||||
|
bin := x
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
bin += ".exe"
|
||||||
|
}
|
||||||
|
|
||||||
// write request Body to x.go
|
// write request Body to x.go
|
||||||
f, err := os.Open(x+".go", os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0666)
|
f, err := os.Open(src, os.O_CREAT|os.O_WRONLY|os.O_TRUNC, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(w, nil, err)
|
error(w, nil, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer os.Remove(x + ".go")
|
defer os.Remove(src)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
_, err = io.Copy(f, req.Body)
|
_, err = io.Copy(f, req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,23 +98,23 @@ func Compile(w http.ResponseWriter, req *http.Request) {
|
|||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
// build x.go, creating x.6
|
// build x.go, creating x.6
|
||||||
out, err := run(archChar+"g", "-o", x+"."+archChar, x+".go")
|
out, err := run(archChar+"g", "-o", obj, src)
|
||||||
defer os.Remove(x + "." + archChar)
|
defer os.Remove(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(w, out, err)
|
error(w, out, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// link x.6, creating x (the program binary)
|
// link x.6, creating x (the program binary)
|
||||||
out, err = run(archChar+"l", "-o", x, x+"."+archChar)
|
out, err = run(archChar+"l", "-o", bin, obj)
|
||||||
defer os.Remove(x)
|
defer os.Remove(bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(w, out, err)
|
error(w, out, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// run x
|
// run x
|
||||||
out, err = run(x)
|
out, err = run(bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
error(w, out, err)
|
error(w, out, err)
|
||||||
}
|
}
|
||||||
@ -150,6 +156,9 @@ func run(cmd ...string) ([]byte, os.Error) {
|
|||||||
io.Copy(&buf, p.Stdout)
|
io.Copy(&buf, p.Stdout)
|
||||||
w, err := p.Wait(0)
|
w, err := p.Wait(0)
|
||||||
p.Close()
|
p.Close()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// set the error return value if the program had a non-zero exit status
|
// set the error return value if the program had a non-zero exit status
|
||||||
if !w.Exited() || w.ExitStatus() != 0 {
|
if !w.Exited() || w.ExitStatus() != 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user