[Concept,13/18] buildman: Move error delta calculation to ResultHandler

Message ID 20260110200828.168672-14-sjg@u-boot.org
State New
Headers
Series buildman: Split up the enormous Builder class |

Commit Message

Simon Glass Jan. 10, 2026, 8:08 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Move the _calc_error_delta() function and its helper _board_list() from
the nested functions in print_result_summary() to ResultHandler. Also
move the ErrLine namedtuple from builder.py to resulthandler.py since it
is used by calc_error_delta().

This continues the extraction of display-related code from builder.py
into the ResultHandler class. The list_error_boards parameter is now
passed explicitly instead of being accessed via self._list_error_boards.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/buildman/builder.py       | 63 +++---------------------------
 tools/buildman/resulthandler.py | 68 ++++++++++++++++++++++++++++++++-
 2 files changed, 72 insertions(+), 59 deletions(-)
  

Patch

diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py
index 53f1c6bde98..a2d4470b70c 100644
--- a/tools/buildman/builder.py
+++ b/tools/buildman/builder.py
@@ -1071,67 +1071,16 @@  class Builder:
             show_config (bool): Show config changes
             show_environment (bool): Show environment changes
         """
-        def _board_list(line, line_boards):
-            """Helper function to get a line of boards containing a line
-
-            Args:
-                line: Error line to search for
-                line_boards: boards to search, each a Board
-            Return:
-                List of boards with that error line, or [] if the user has not
-                    requested such a list
-            """
-            brds = []
-            board_set = set()
-            if self._opts.list_error_boards:
-                for brd in line_boards[line]:
-                    if not brd in board_set:
-                        brds.append(brd)
-                        board_set.add(brd)
-            return brds
-
-        def _calc_error_delta(base_lines, base_line_boards, lines, line_boards,
-                            char):
-            """Calculate the required output based on changes in errors
-
-            Args:
-                base_lines: List of errors/warnings for previous commit
-                base_line_boards: Dict keyed by error line, containing a list
-                    of the Board objects with that error in the previous commit
-                lines: List of errors/warning for this commit, each a str
-                line_boards: Dict keyed by error line, containing a list
-                    of the Board objects with that error in this commit
-                char: Character representing error ('') or warning ('w'). The
-                    broken ('+') or fixed ('-') characters are added in this
-                    function
-
-            Returns:
-                Tuple
-                    List of ErrLine objects for 'better' lines
-                    List of ErrLine objects for 'worse' lines
-            """
-            better_lines = []
-            worse_lines = []
-            for line in lines:
-                if line not in base_lines:
-                    errline = ErrLine(
-                        char + '+', _board_list(line, line_boards), line)
-                    worse_lines.append(errline)
-            for line in base_lines:
-                if line not in lines:
-                    errline = ErrLine(char + '-',
-                                      _board_list(line, base_line_boards), line)
-                    better_lines.append(errline)
-            return better_lines, worse_lines
-
         brd_status = ResultHandler.classify_boards(
             board_selected, board_dict, self._base_board_dict)
 
         # Get a list of errors and warnings that have appeared, and disappeared
-        better_err, worse_err = _calc_error_delta(self._base_err_lines,
-                self._base_err_line_boards, err_lines, err_line_boards, '')
-        better_warn, worse_warn = _calc_error_delta(self._base_warn_lines,
-                self._base_warn_line_boards, warn_lines, warn_line_boards, 'w')
+        better_err, worse_err = ResultHandler.calc_error_delta(
+            self._base_err_lines, self._base_err_line_boards, err_lines,
+            err_line_boards, '', self._opts.list_error_boards)
+        better_warn, worse_warn = ResultHandler.calc_error_delta(
+            self._base_warn_lines, self._base_warn_line_boards, warn_lines,
+            warn_line_boards, 'w', self._opts.list_error_boards)
 
         # For the IDE mode, print out all the output
         if self._opts.ide:
diff --git a/tools/buildman/resulthandler.py b/tools/buildman/resulthandler.py
index 197f4d87003..a2064986729 100644
--- a/tools/buildman/resulthandler.py
+++ b/tools/buildman/resulthandler.py
@@ -8,8 +8,8 @@ 
 
 import sys
 
-from buildman.outcome import (BoardStatus, OUTCOME_OK, OUTCOME_WARNING,
-                              OUTCOME_ERROR, OUTCOME_UNKNOWN)
+from buildman.outcome import (BoardStatus, ErrLine, OUTCOME_OK,
+                              OUTCOME_WARNING, OUTCOME_ERROR, OUTCOME_UNKNOWN)
 from u_boot_pylib.terminal import tprint
 
 
@@ -745,3 +745,67 @@  class ResultHandler:
         if not_built:
             tprint(f"Boards not built ({len(not_built)}): "
                    f"{', '.join(not_built)}")
+
+    @staticmethod
+    def _board_list(line, line_boards, list_error_boards):
+        """Get a list of boards containing a particular error/warning line
+
+        Args:
+            line (str): Error line to search for
+            line_boards (dict): Dict keyed by line, containing list of Board
+                objects with that line
+            list_error_boards (bool): True to return the board list, False to
+                return empty list
+
+        Returns:
+            list: List of Board objects with that error line, or [] if
+                list_error_boards is False
+        """
+        brds = []
+        board_set = set()
+        if list_error_boards:
+            for brd in line_boards[line]:
+                if brd not in board_set:
+                    brds.append(brd)
+                    board_set.add(brd)
+        return brds
+
+    @classmethod
+    def calc_error_delta(cls, base_lines, base_line_boards, lines, line_boards,
+                         char, list_error_boards):
+        """Calculate the required output based on changes in errors
+
+        Args:
+            base_lines (list): List of errors/warnings for previous commit
+            base_line_boards (dict): Dict keyed by error line, containing a
+                list of the Board objects with that error in the previous
+                commit
+            lines (list): List of errors/warning for this commit, each a str
+            line_boards (dict): Dict keyed by error line, containing a list
+                of the Board objects with that error in this commit
+            char (str): Character representing error ('') or warning ('w'). The
+                broken ('+') or fixed ('-') characters are added in this
+                function
+            list_error_boards (bool): True to include board list in output
+
+        Returns:
+            tuple: (better_lines, worse_lines) where each is a list of
+                ErrLine objects
+        """
+        better_lines = []
+        worse_lines = []
+        for line in lines:
+            if line not in base_lines:
+                errline = ErrLine(
+                    char + '+',
+                    cls._board_list(line, line_boards, list_error_boards),
+                    line)
+                worse_lines.append(errline)
+        for line in base_lines:
+            if line not in lines:
+                errline = ErrLine(
+                    char + '-',
+                    cls._board_list(line, base_line_boards, list_error_boards),
+                    line)
+                better_lines.append(errline)
+        return better_lines, worse_lines