Print ninja stdout live during the build
When running ninja stream stdout to the status writer. This improves the ninja -d explain behavior, and will also allow Soong to be put into the ninja console pool letting it print timely output to the console. Bug: 80165685 Test: NINJA_ARGS="-d explain" m Change-Id: I40f03fc01d837ad91d400eae378007a7ce807705
This commit is contained in:
@@ -15,7 +15,10 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Cmd is a wrapper of os/exec.Cmd that integrates with the build context for
|
// Cmd is a wrapper of os/exec.Cmd that integrates with the build context for
|
||||||
@@ -139,3 +142,34 @@ func (c *Cmd) RunAndPrintOrFatal() {
|
|||||||
st.Finish()
|
st.Finish()
|
||||||
c.reportError(err)
|
c.reportError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunAndStreamOrFatal will run the command, while running print
|
||||||
|
// any output, then handle any errors with a call to ctx.Fatal
|
||||||
|
func (c *Cmd) RunAndStreamOrFatal() {
|
||||||
|
out, err := c.StdoutPipe()
|
||||||
|
if err != nil {
|
||||||
|
c.ctx.Fatal(err)
|
||||||
|
}
|
||||||
|
c.Stderr = c.Stdout
|
||||||
|
|
||||||
|
st := c.ctx.Status.StartTool()
|
||||||
|
|
||||||
|
c.StartOrFatal()
|
||||||
|
|
||||||
|
buf := bufio.NewReaderSize(out, 2*1024*1024)
|
||||||
|
for {
|
||||||
|
// Attempt to read whole lines, but write partial lines that are too long to fit in the buffer or hit EOF
|
||||||
|
line, err := buf.ReadString('\n')
|
||||||
|
if line != "" {
|
||||||
|
st.Print(strings.TrimSuffix(line, "\n"))
|
||||||
|
} else if err == io.EOF {
|
||||||
|
break
|
||||||
|
} else if err != nil {
|
||||||
|
c.ctx.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
err = c.Wait()
|
||||||
|
st.Finish()
|
||||||
|
c.reportError(err)
|
||||||
|
}
|
||||||
|
@@ -103,7 +103,7 @@ func runNinja(ctx Context, config Config) {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
ctx.Status.Status("Starting ninja...")
|
ctx.Status.Status("Starting ninja...")
|
||||||
cmd.RunAndPrintOrFatal()
|
cmd.RunAndStreamOrFatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
type statusChecker struct {
|
type statusChecker struct {
|
||||||
|
@@ -120,7 +120,7 @@ func runSoong(ctx Context, config Config) {
|
|||||||
"--frontend_file", fifo,
|
"--frontend_file", fifo,
|
||||||
"-f", filepath.Join(config.SoongOutDir(), file))
|
"-f", filepath.Join(config.SoongOutDir(), file))
|
||||||
cmd.Sandbox = soongSandbox
|
cmd.Sandbox = soongSandbox
|
||||||
cmd.RunAndPrintOrFatal()
|
cmd.RunAndStreamOrFatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
ninja("minibootstrap", ".minibootstrap/build.ninja")
|
ninja("minibootstrap", ".minibootstrap/build.ninja")
|
||||||
|
Reference in New Issue
Block a user