[PATCH v3 24/81] buildman: Move fetch-arch code into a separate function

Simon Glass sjg at chromium.org
Sun Jul 16 02:35:52 CEST 2023


Reduce the size of the do_buildman() function a little by moving the code
that handles --fetch-arch into a separate function.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

(no changes since v1)

 tools/buildman/control.py | 49 +++++++++++++++++++++++++--------------
 1 file changed, 31 insertions(+), 18 deletions(-)

diff --git a/tools/buildman/control.py b/tools/buildman/control.py
index d8fead93e730..5762ec90c0bd 100644
--- a/tools/buildman/control.py
+++ b/tools/buildman/control.py
@@ -192,6 +192,36 @@ def determine_series(count, has_range, branch, git_dir):
     return series
 
 
+def do_fetch_arch(toolchains, col, fetch_arch):
+    """Handle the --fetch-arch option
+
+    Args:
+        toolchains (Toolchains): Tool chains to use
+        col (terminal.Color): Color object to build
+        fetch_arch (str): Argument passed to the --fetch-arch option
+
+    Returns:
+        int: Return code for buildman
+    """
+    if fetch_arch == 'list':
+        sorted_list = toolchains.ListArchs()
+        print(col.build(
+            col.BLUE,
+            f"Available architectures: {' '.join(sorted_list)}\n"))
+        return 0
+
+    if fetch_arch == 'all':
+        fetch_arch = ','.join(toolchains.ListArchs())
+        print(col.build(col.CYAN,
+                        f'\nDownloading toolchains: {fetch_arch}'))
+    for arch in fetch_arch.split(','):
+        print()
+        ret = toolchains.FetchAndInstall(arch)
+        if ret:
+            return ret
+    return 0
+
+
 def do_buildman(options, args, toolchains=None, make_func=None, brds=None,
                 clean_dir=False, test_thread_exceptions=False):
     """The main control code for buildman
@@ -226,24 +256,7 @@ def do_buildman(options, args, toolchains=None, make_func=None, brds=None,
         toolchains = toolchain.Toolchains(options.override_toolchain)
 
     if options.fetch_arch:
-        if options.fetch_arch == 'list':
-            sorted_list = toolchains.ListArchs()
-            print(col.build(
-                col.BLUE,
-                f"Available architectures: {' '.join(sorted_list)}\n"))
-            return 0
-
-        fetch_arch = options.fetch_arch
-        if fetch_arch == 'all':
-            fetch_arch = ','.join(toolchains.ListArchs())
-            print(col.build(col.CYAN,
-                            f'\nDownloading toolchains: {fetch_arch}'))
-        for arch in fetch_arch.split(','):
-            print()
-            ret = toolchains.FetchAndInstall(arch)
-            if ret:
-                return ret
-        return 0
+        return do_fetch_arch(toolchains, col, options.fetch_arch)
 
     if no_toolchains:
         toolchains.GetSettings()
-- 
2.41.0.455.g037347b96a-goog



More information about the U-Boot mailing list