Commit 548e3d03 authored by Alex Brainman's avatar Alex Brainman

gobuilder: number of fixes

1) runLog to return err==nil if program runs, but returns exitcode!=0;
2) runLog to return err!=nil when fails to create log file;
3) print failed program name, not just "all.bash".

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/4532117
parent 60a4b5e4
......@@ -27,8 +27,11 @@ func run(envv []string, dir string, argv ...string) os.Error {
}
// 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) {
// as well as writing it to logfile (if specified). It returns
// process combined stdout and stderr output, exit status and error.
// The error returned is nil, if process is started successfully,
// even if exit status is not 0.
func runLog(envv []string, logfile, dir string, argv ...string) (string, int, os.Error) {
if *verbose {
log.Println("runLog", argv)
}
......@@ -39,7 +42,7 @@ func runLog(envv []string, logfile, dir string, argv ...string) (output string,
if logfile != "" {
f, err := os.OpenFile(logfile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
return
return "", 0, err
}
defer f.Close()
w = io.MultiWriter(f, b)
......@@ -51,15 +54,13 @@ func runLog(envv []string, logfile, dir string, argv ...string) (output string,
cmd.Stdout = w
cmd.Stderr = w
err = cmd.Run()
output = b.String()
err := cmd.Run()
if err != nil {
if ws, ok := err.(*os.Waitmsg); ok {
exitStatus = ws.ExitStatus()
return b.String(), ws.ExitStatus(), nil
}
return
}
return
return b.String(), 0, nil
}
// useBash prefixes a list of args with 'bash' if the first argument
......
......@@ -294,7 +294,7 @@ func (b *Builder) buildHash(hash string) (err os.Error) {
logfile := path.Join(workpath, "build.log")
buildLog, status, err := runLog(b.envv(), logfile, srcDir, *buildCmd)
if err != nil {
return fmt.Errorf("all.bash: %s", err)
return fmt.Errorf("%s: %s", *buildCmd, err)
}
// if we're in external mode, build all packages and return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment