Highlight build failures in soong output

Summary: When build failures occur, it can be hard to find where the error message begins. We now highlight "FAILURE" in red to make it easier to see what exactly has failed in the output.

Test: execute automated tests with m nothing --no-skip-soong-tests, can also manually test with a build failure and observe red text in the output

Change-Id: Iad3b94cc1c385f0afdebdf12c44843db04ff2bdc
Signed-off-by: Cherokee Toole <cherokee@meta.com>
This commit is contained in:
cherokeeMeta
2024-07-11 16:52:18 -07:00
committed by Cherokee Toole
parent e7485b871a
commit f7119b57ac
3 changed files with 28 additions and 17 deletions

View File

@@ -23,26 +23,28 @@ import (
)
type formatter struct {
format string
quiet bool
start time.Time
colorize bool
format string
quiet bool
start time.Time
}
// newFormatter returns a formatter for formatting output to
// the terminal in a format similar to Ninja.
// format takes nearly all the same options as NINJA_STATUS.
// %c is currently unsupported.
func newFormatter(format string, quiet bool) formatter {
func newFormatter(colorize bool, format string, quiet bool) formatter {
return formatter{
format: format,
quiet: quiet,
start: time.Now(),
colorize: colorize,
format: format,
quiet: quiet,
start: time.Now(),
}
}
func (s formatter) message(level status.MsgLevel, message string) string {
if level >= status.ErrorLvl {
return fmt.Sprintf("FAILED: %s", message)
return fmt.Sprintf("%s %s", s.failedString(), message)
} else if level > status.StatusLvl {
return fmt.Sprintf("%s%s", level.Prefix(), message)
} else if level == status.StatusLvl {
@@ -127,9 +129,9 @@ func (s formatter) result(result status.ActionResult) string {
if result.Error != nil {
targets := strings.Join(result.Outputs, " ")
if s.quiet || result.Command == "" {
ret = fmt.Sprintf("FAILED: %s\n%s", targets, result.Output)
ret = fmt.Sprintf("%s %s\n%s", s.failedString(), targets, result.Output)
} else {
ret = fmt.Sprintf("FAILED: %s\n%s\n%s", targets, result.Command, result.Output)
ret = fmt.Sprintf("%s %s\n%s\n%s", s.failedString(), targets, result.Command, result.Output)
}
} else if result.Output != "" {
ret = result.Output
@@ -141,3 +143,11 @@ func (s formatter) result(result status.ActionResult) string {
return ret
}
func (s formatter) failedString() string {
failed := "FAILED:"
if s.colorize {
failed = ansi.red() + ansi.bold() + failed + ansi.regular()
}
return failed
}