| Index: ct/go/util/util.go
|
| diff --git a/ct/go/util/util.go b/ct/go/util/util.go
|
| index 1a22fe57b2d2f767d0805136488ecb911c4f74c2..6b9afb013281967fb67bba823466be8718185ffd 100644
|
| --- a/ct/go/util/util.go
|
| +++ b/ct/go/util/util.go
|
| @@ -6,12 +6,11 @@ import (
|
| "fmt"
|
| "io/ioutil"
|
| "os"
|
| - "os/exec"
|
| "path/filepath"
|
| "strconv"
|
| - "strings"
|
| "time"
|
|
|
| + "go.skia.org/infra/go/exec"
|
| "go.skia.org/infra/go/util"
|
|
|
| "github.com/skia-dev/glog"
|
| @@ -86,63 +85,23 @@ func TimeTrack(start time.Time, name string) {
|
| glog.Infof("===== %s took %s =====", name, elapsed)
|
| }
|
|
|
| -// WriteLog implements the io.Writer interface and writes to glog and an output
|
| -// file (if specified).
|
| -type WriteLog struct {
|
| - LogFunc func(format string, args ...interface{})
|
| - OutputFile *os.File
|
| -}
|
| -
|
| -func (wl WriteLog) Write(p []byte) (n int, err error) {
|
| - wl.LogFunc("%s", string(p))
|
| - // Write to file if specified.
|
| - if wl.OutputFile != nil {
|
| - if n, err := wl.OutputFile.WriteString(string(p)); err != nil {
|
| - glog.Errorf("Could not write to %s: %s", wl.OutputFile.Name(), err)
|
| - return n, err
|
| - }
|
| - }
|
| - return len(p), nil
|
| -}
|
| -
|
| // ExecuteCmd executes the specified binary with the specified args and env.
|
| // Stdout and Stderr are written to stdoutFile and stderrFile respectively if
|
| // specified. If not specified then stdout and stderr will be outputted only to
|
| // glog. Note: It is the responsibility of the caller to close stdoutFile and
|
| // stderrFile.
|
| func ExecuteCmd(binary string, args, env []string, timeout time.Duration, stdoutFile, stderrFile *os.File) error {
|
| - // Add the current PATH to the env.
|
| - env = append(env, "PATH="+os.Getenv("PATH"))
|
| -
|
| - // Create the cmd obj.
|
| - cmd := exec.Command(binary, args...)
|
| - cmd.Env = env
|
| -
|
| - // Attach WriteLog to command.
|
| - cmd.Stdout = WriteLog{LogFunc: glog.Infof, OutputFile: stdoutFile}
|
| - cmd.Stderr = WriteLog{LogFunc: glog.Errorf, OutputFile: stderrFile}
|
| -
|
| - // Execute cmd.
|
| - glog.Infof("Executing %s %s", strings.Join(cmd.Env, " "), strings.Join(cmd.Args, " "))
|
| - util.LogErr(cmd.Start())
|
| - done := make(chan error)
|
| - go func() {
|
| - done <- cmd.Wait()
|
| - }()
|
| - select {
|
| - case <-time.After(timeout):
|
| - if err := cmd.Process.Kill(); err != nil {
|
| - return fmt.Errorf("Failed to kill timed out process: %s", err)
|
| - }
|
| - <-done // allow goroutine to exit
|
| - glog.Errorf("Command killed since it took longer than %f secs", timeout.Seconds())
|
| - return fmt.Errorf("Command killed since it took longer than %f secs", timeout.Seconds())
|
| - case err := <-done:
|
| - if err != nil {
|
| - return fmt.Errorf("Process done with error: %s", err)
|
| - }
|
| - }
|
| - return nil
|
| + return exec.Run(&exec.Command{
|
| + Name: binary,
|
| + Args: args,
|
| + Env: env,
|
| + InheritPath: true,
|
| + Timeout: timeout,
|
| + LogStdout: true,
|
| + Stdout: stdoutFile,
|
| + LogStderr: true,
|
| + Stderr: stderrFile,
|
| + })
|
| }
|
|
|
| // SyncDir runs "git pull" and "gclient sync" on the specified directory.
|
|
|