]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
Pipe build output directly to a file
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 7 Nov 2018 14:55:24 +0000 (14:55 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 7 Nov 2018 14:55:24 +0000 (14:55 +0000)
Open `build.log` and pipe stdout and stderr to it when building,
rather than using CombinedOutput (which will send it to a memory
buffer instead).  This will cause output to be written to the file as
it goes along, rather than only at the end.

Signed-off-by: George Dunlap <george.dunalp@citrix.com>
README.md
recipe.go

index eb5b14b926c79d8550893743ea5097a468e225d6..9d4375515ea25fa60eba7c55ffd1988918425c81 100644 (file)
--- a/README.md
+++ b/README.md
@@ -366,7 +366,7 @@ Individual versions can be specified as well: `xsatool 213 test-apply 4.6 4.5`
 For each version in `<versionlist>`, it will attempt to check out a
 tree based on `test/213/$v` and do a build.  If the branch does not
 exist it will throw an error.  (If no `<versionlist>` is supplied, it
-defaults to `all`.)
+defaults to `all`.)  Output will be redirected to `build.log`.
 
 `xsatool 213 test [<versionlist>]`
 
index e15e6347d924e4acadaf9ce18de80d65bfab6b13..651cef7c184891885915f686fef9b2627351709b 100644 (file)
--- a/recipe.go
+++ b/recipe.go
@@ -3,7 +3,6 @@ package main
 import (
        "fmt"
        "io"
-       "io/ioutil"
        "os"
        "os/exec"
        "path"
@@ -605,24 +604,34 @@ func (r *Recipe) Build(prefix string) (err error) {
        // Configure
        os.Chdir(xenrepo.GetPath())
 
-       out, err := exec.Command("./configure").CombinedOutput()
+       logfile, err := os.Create("build.log")
+       if err != nil {
+               return fmt.Errorf("Opening log file: %v", err)
+       }
+       defer logfile.Close()
+
+       cmd := exec.Command("./configure")
+       cmd.Stdout = logfile
+       cmd.Stderr = logfile
+       err = cmd.Run()
        if err != nil {
-               ioutil.WriteFile("build.log", out, 0666)
                return fmt.Errorf("Configuring xen: %v\n", err)
        }
 
        // Build
-       out, err = exec.Command("make", "-j", "8").CombinedOutput()
+       cmd = exec.Command("make", "-j", "8")
+       cmd.Stdout = logfile
+       cmd.Stderr = logfile
+       err = cmd.Run()
        if err != nil {
-               ioutil.WriteFile("build.log", out, 0666)
                return fmt.Errorf("Building: %v\n", err)
        }
 
-       out, err = xenrepo.Checkout("master")
+       _, err = xenrepo.Checkout("master")
        if err != nil {
                return
        }
-       out, err = xenrepo.DeleteBranch(tmpBranch)
+       _, err = xenrepo.DeleteBranch(tmpBranch)
        if err != nil {
                return
        }