diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go index c976dcb45..1171a6521 100644 --- a/cmd/multiproduct_kati/main.go +++ b/cmd/multiproduct_kati/main.go @@ -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 +} diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index 58d8d345e..f5276c335 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -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, }} diff --git a/ui/status/log.go b/ui/status/log.go index 921aa4401..7badac73c 100644 --- a/ui/status/log.go +++ b/ui/status/log.go @@ -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 +} diff --git a/ui/status/status.go b/ui/status/status.go index 46ec72e80..3d8cd7a2c 100644 --- a/ui/status/status.go +++ b/ui/status/status.go @@ -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 diff --git a/ui/status/status_test.go b/ui/status/status_test.go index e62785f43..949458222 100644 --- a/ui/status/status_test.go +++ b/ui/status/status_test.go @@ -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 diff --git a/ui/terminal/dumb_status.go b/ui/terminal/dumb_status.go index 08ef3733a..201770fac 100644 --- a/ui/terminal/dumb_status.go +++ b/ui/terminal/dumb_status.go @@ -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 +} diff --git a/ui/terminal/smart_status.go b/ui/terminal/smart_status.go index a52fdc2b5..9a4931c01 100644 --- a/ui/terminal/smart_status.go +++ b/ui/terminal/smart_status.go @@ -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) diff --git a/ui/tracer/status.go b/ui/tracer/status.go index af50e2d4d..c83125514 100644 --- a/ui/tracer/status.go +++ b/ui/tracer/status.go @@ -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 +}