1
0
mirror of https://github.com/golang/go synced 2024-10-03 14:11:21 -06:00
go/misc/dashboard/builder/exec.go
Russ Cox 12c3afc1ae dashboard: fix for branches
In the new world, one builder runs
        gobuilder -commit
which uploads information about commits to the dashboard,
which then hands the work out to the builders by hash.
There is no assumption anymore that the commit numbers
are consistent across builders.

New builders will need to be deployed.  For now darwin-amd64
is running the new builder to test the code.

The new JSON-based protocol for handing out work via /todo
should be easy to extend if we want to add support for sending
trial CLs to the builders.

This code is already running on godashboard.appspot.com.

R=adg, dave
CC=golang-dev
https://golang.org/cl/4519047
2011-05-12 11:21:34 -04:00

77 lines
1.7 KiB
Go

// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bytes"
"exec"
"io"
"log"
"os"
"strings"
)
// run is a simple wrapper for exec.Run/Close
func run(envv []string, dir string, argv ...string) os.Error {
if *verbose {
log.Println("run", argv)
}
bin, err := lookPath(argv[0])
if err != nil {
return err
}
p, err := exec.Run(bin, argv, envv, dir,
exec.DevNull, exec.DevNull, exec.PassThrough)
if err != nil {
return err
}
return p.Close()
}
// runLog runs a process and returns the combined stdout/stderr,
// as well as writing it to logfile (if specified).
func runLog(envv []string, logfile, dir string, argv ...string) (output string, exitStatus int, err os.Error) {
if *verbose {
log.Println("runLog", argv)
}
bin, err := lookPath(argv[0])
if err != nil {
return
}
p, err := exec.Run(bin, argv, envv, dir,
exec.DevNull, exec.Pipe, exec.MergeWithStdout)
if err != nil {
return
}
defer p.Close()
b := new(bytes.Buffer)
var w io.Writer = b
if logfile != "" {
f, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return
}
defer f.Close()
w = io.MultiWriter(f, b)
}
_, err = io.Copy(w, p.Stdout)
if err != nil {
return
}
wait, err := p.Wait(0)
if err != nil {
return
}
return b.String(), wait.WaitStatus.ExitStatus(), nil
}
// lookPath looks for cmd in $PATH if cmd does not begin with / or ./ or ../.
func lookPath(cmd string) (string, os.Error) {
if strings.HasPrefix(cmd, "/") || strings.HasPrefix(cmd, "./") || strings.HasPrefix(cmd, "../") {
return cmd, nil
}
return exec.LookPath(cmd)
}