[Concept,07/12] buildman: Extract target checking from scan() into _check_targets()

Message ID 20260103203243.3727493-8-sjg@u-boot.org
State New
Headers
Series buildman: Fix pylint warnings in board.py and boards.py |

Commit Message

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

Move the logic that verifies exactly one TARGET_xxx option is set into
a separate method to reduce complexity of scan()

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

 tools/buildman/boards.py | 45 ++++++++++++++++++++++++++--------------
 1 file changed, 30 insertions(+), 15 deletions(-)
  

Patch

diff --git a/tools/buildman/boards.py b/tools/buildman/boards.py
index e7844f0e5e7..74f654c6813 100644
--- a/tools/buildman/boards.py
+++ b/tools/buildman/boards.py
@@ -294,21 +294,7 @@  class KconfigScanner:
 
         # Check there is exactly one TARGET_xxx set
         if warn_targets:
-            target = None
-            for name, sym in self._conf.syms.items():
-                if name.startswith('TARGET_') and sym.str_value == 'y':
-                    tname = name[7:].lower()
-                    if target:
-                        warnings.append(
-                            f'WARNING: {leaf}: Duplicate TARGET_xxx: '
-                            f'{target} and {tname}')
-                    else:
-                        target = tname
-
-            if not target:
-                cfg_name = expect_target.replace('-', '_').upper()
-                warnings.append(
-                    f'WARNING: {leaf}: No TARGET_{cfg_name} enabled')
+            warnings += self._check_targets(leaf, expect_target)
 
         params['target'] = expect_target
 
@@ -340,6 +326,35 @@  class KconfigScanner:
             else:
                 params['arch'] = 'riscv64'
 
+    def _check_targets(self, leaf, expect_target):
+        """Check that exactly one TARGET_xxx option is set
+
+        Args:
+            leaf (str): Leaf name of defconfig file (for warnings)
+            expect_target (str): Expected target name
+
+        Returns:
+            list of str: List of warnings found
+        """
+        warnings = []
+        target = None
+        for name, sym in self._conf.syms.items():
+            if name.startswith('TARGET_') and sym.str_value == 'y':
+                tname = name[7:].lower()
+                if target:
+                    warnings.append(
+                        f'WARNING: {leaf}: Duplicate TARGET_xxx: '
+                        f'{target} and {tname}')
+                else:
+                    target = tname
+
+        if not target:
+            cfg_name = expect_target.replace('-', '_').upper()
+            warnings.append(
+                f'WARNING: {leaf}: No TARGET_{cfg_name} enabled')
+
+        return warnings
+
 
 class MaintainersDatabase: