Move all output through StatusOutput
Write log output through StatusOutput so that the status implementation can synchronize it with its own output. Test: status_test.go Change-Id: I917bdeeea4759a12b6b4aa6d6d86ee18a2771723
This commit is contained in:
parent
097ed2a37c
commit
e0df1a36b2
|
@ -158,7 +158,10 @@ type mpContext struct {
|
|||
func main() {
|
||||
stdio := terminal.StdioImpl{}
|
||||
|
||||
log := logger.New(stdio.Stdout())
|
||||
output := terminal.NewStatusOutput(stdio.Stdout(), "",
|
||||
build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))
|
||||
|
||||
log := logger.New(output)
|
||||
defer log.Cleanup()
|
||||
|
||||
flag.Parse()
|
||||
|
@ -171,8 +174,7 @@ func main() {
|
|||
|
||||
stat := &status.Status{}
|
||||
defer stat.Finish()
|
||||
stat.AddOutput(terminal.NewStatusOutput(stdio.Stdout(), "",
|
||||
build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD")))
|
||||
stat.AddOutput(output)
|
||||
|
||||
var failures failureCount
|
||||
stat.AddOutput(&failures)
|
||||
|
@ -187,7 +189,7 @@ func main() {
|
|||
Context: ctx,
|
||||
Logger: log,
|
||||
Tracer: trace,
|
||||
Writer: stdio.Stdout(),
|
||||
Writer: output,
|
||||
Status: stat,
|
||||
}}
|
||||
|
||||
|
@ -340,7 +342,7 @@ func main() {
|
|||
} else if failures > 1 {
|
||||
log.Fatalf("%d failures", failures)
|
||||
} else {
|
||||
fmt.Fprintln(stdio.Stdout(), "Success")
|
||||
fmt.Fprintln(output, "Success")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,3 +467,8 @@ func (f *failureCount) Message(level status.MsgLevel, message string) {
|
|||
}
|
||||
|
||||
func (f *failureCount) Flush() {}
|
||||
|
||||
func (f *failureCount) Write(p []byte) (int, error) {
|
||||
// discard writes
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
@ -109,7 +109,10 @@ func main() {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
log := logger.New(c.stdio().Stdout())
|
||||
output := terminal.NewStatusOutput(c.stdio().Stdout(), os.Getenv("NINJA_STATUS"),
|
||||
build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD"))
|
||||
|
||||
log := logger.New(output)
|
||||
defer log.Cleanup()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -122,8 +125,7 @@ func main() {
|
|||
|
||||
stat := &status.Status{}
|
||||
defer stat.Finish()
|
||||
stat.AddOutput(terminal.NewStatusOutput(c.stdio().Stdout(), os.Getenv("NINJA_STATUS"),
|
||||
build.OsEnvironment().IsEnvTrue("ANDROID_QUIET_BUILD")))
|
||||
stat.AddOutput(output)
|
||||
stat.AddOutput(trace.StatusTracer())
|
||||
|
||||
build.SetupSignals(log, cancel, func() {
|
||||
|
@ -137,7 +139,7 @@ func main() {
|
|||
Logger: log,
|
||||
Metrics: met,
|
||||
Tracer: trace,
|
||||
Writer: c.stdio().Stdout(),
|
||||
Writer: output,
|
||||
Status: stat,
|
||||
}}
|
||||
|
||||
|
|
|
@ -71,6 +71,11 @@ func (v *verboseLog) Message(level MsgLevel, message string) {
|
|||
fmt.Fprintf(v.w, "%s%s\n", level.Prefix(), message)
|
||||
}
|
||||
|
||||
func (v *verboseLog) Write(p []byte) (int, error) {
|
||||
fmt.Fprint(v.w, string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
type errorLog struct {
|
||||
w io.WriteCloser
|
||||
|
||||
|
@ -134,3 +139,8 @@ func (e *errorLog) Message(level MsgLevel, message string) {
|
|||
|
||||
fmt.Fprintf(e.w, "error: %s\n", message)
|
||||
}
|
||||
|
||||
func (e *errorLog) Write(p []byte) (int, error) {
|
||||
fmt.Fprint(e.w, string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
@ -173,6 +173,9 @@ type StatusOutput interface {
|
|||
// Flush is called when your outputs should be flushed / closed. No
|
||||
// output is expected after this call.
|
||||
Flush()
|
||||
|
||||
// Write lets StatusOutput implement io.Writer
|
||||
Write(p []byte) (n int, err error)
|
||||
}
|
||||
|
||||
// Status is the multiplexer / accumulator between ToolStatus instances (via
|
||||
|
|
|
@ -27,6 +27,11 @@ func (c *counterOutput) FinishAction(result ActionResult, counts Counts) {
|
|||
func (c counterOutput) Message(level MsgLevel, msg string) {}
|
||||
func (c counterOutput) Flush() {}
|
||||
|
||||
func (c counterOutput) Write(p []byte) (int, error) {
|
||||
// Discard writes
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (c counterOutput) Expect(t *testing.T, counts Counts) {
|
||||
if Counts(c) == counts {
|
||||
return
|
||||
|
|
|
@ -64,3 +64,8 @@ func (s *dumbStatusOutput) FinishAction(result status.ActionResult, counts statu
|
|||
}
|
||||
|
||||
func (s *dumbStatusOutput) Flush() {}
|
||||
|
||||
func (s *dumbStatusOutput) Write(p []byte) (int, error) {
|
||||
fmt.Fprint(s.writer, string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
|
@ -104,6 +104,13 @@ func (s *smartStatusOutput) Flush() {
|
|||
s.requestLine()
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) Write(p []byte) (int, error) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
s.print(string(p))
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
func (s *smartStatusOutput) requestLine() {
|
||||
if !s.haveBlankLine {
|
||||
fmt.Fprintln(s.writer)
|
||||
|
|
|
@ -85,3 +85,8 @@ func (s *statusOutput) FinishAction(result status.ActionResult, counts status.Co
|
|||
|
||||
func (s *statusOutput) Flush() {}
|
||||
func (s *statusOutput) Message(level status.MsgLevel, message string) {}
|
||||
|
||||
func (s *statusOutput) Write(p []byte) (int, error) {
|
||||
// Discard writes
|
||||
return len(p), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue