diff mbox series

[3/4] knotty: convert warnings to errors when -W is passed

Message ID 20261013-warn-as-errors-v1-3-ab3658758ceb@bootlin.com
State New
Headers show
Series Add -W to treat warnings as errors | expand

Commit Message

Antonin Godard Oct. 13, 2026, 12:13 p.m. UTC
When -W is passed, modify the handlers to show warnings in red and set
the return value to 1. Add a summary line informing the user that the -W
option was used as it might not be obvious when looking at the bottom
the end of the console log.

Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
 lib/bb/ui/knotty.py | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/ui/knotty.py b/lib/bb/ui/knotty.py
index 1a3198b5c02..a3a5c374a35 100644
--- a/lib/bb/ui/knotty.py
+++ b/lib/bb/ui/knotty.py
@@ -662,6 +662,14 @@  def main(server, eventHandler, params, tf = TerminalFilter):
     # terminal handler
     console_handlers = [h for h in conf.config['handlers'].values() if getattr(h, 'is_console', False)]
 
+    if params.werror:
+        # Change the color of warning/warnonce messages to red when -W is passed
+        for h in console_handlers:
+            try:
+                h.formatter.set_warn_color_red()
+            except AttributeError:
+                pass
+
     bb.utils.set_process_name("KnottyUI")
 
     if params.options.remote_server and params.options.kill_server:
@@ -782,6 +790,8 @@  def main(server, eventHandler, params, tf = TerminalFilter):
                     return_value = 1
                 elif event.levelno == bb.msg.BBLogFormatter.WARNING:
                     warnings = warnings + 1
+                    if params.werror:
+                        return_value = 1
 
                 if event.taskpid != 0:
                     # For "normal" logging conditions, don't show note logs from tasks
@@ -1054,6 +1064,10 @@  def main(server, eventHandler, params, tf = TerminalFilter):
         if return_value and errors:
             summary += pluralise("\nSummary: There was %s ERROR message, returning a non-zero exit code.",
                                  "\nSummary: There were %s ERROR messages, returning a non-zero exit code.", errors)
+
+        if params.werror and warnings:
+            summary += "\nSummary: Warnings were treated as errors (-W)."
+
         if summary and params.options.quiet == 0:
             print(summary)