diff mbox series

[RFC,v2,4/7] fetch2: call functions within loops of Fetch class

Message ID 20250905064419.2589111-5-stefan.herbrechtsmeier-oss@weidmueller.com
State New
Headers show
Series fetch2: add support for implicit urls | expand

Commit Message

Stefan Herbrechtsmeier Sept. 5, 2025, 6:44 a.m. UTC
From: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

Call functions within the for all URLs loops of the Fetch class to
simplify subsequent changes.

Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>

---

Changes in v2:
- Fix UnboundLocalError of urldata in expand_urldata function

 lib/bb/fetch2/__init__.py | 43 ++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/fetch2/__init__.py b/lib/bb/fetch2/__init__.py
index bc9808da1..3ff08f817 100644
--- a/lib/bb/fetch2/__init__.py
+++ b/lib/bb/fetch2/__init__.py
@@ -1841,11 +1841,14 @@  class Fetch(object):
         """
         local = []
 
-        for url in self.urls:
+        def localpath(url):
             ud = self.ud[url]
             ud.setup_localpath(self.d)
             local.append(ud.localpath)
 
+        for url in self.urls:
+            localpath(url)
+
         return local
 
     def download(self, urls=None):
@@ -1859,7 +1862,7 @@  class Fetch(object):
         premirroronly = bb.utils.to_boolean(self.d.getVar("BB_FETCH_PREMIRRORONLY"))
 
         checksum_missing_messages = []
-        for url in urls:
+        def download(url):
             ud = self.ud[url]
             ud.setup_localpath(self.d)
             m = ud.method
@@ -1947,14 +1950,18 @@  class Fetch(object):
                 if isinstance(e, NoChecksumError):
                     (message, _) = e.args
                     checksum_missing_messages.append(message)
-                    continue
-                elif isinstance(e, ChecksumError):
-                    logger.error("Checksum failure fetching %s" % url)
-                raise
+                else:
+                    if isinstance(e, ChecksumError):
+                        logger.error("Checksum failure fetching %s" % url)
+                    raise
 
             finally:
                 if ud.lockfile:
                     bb.utils.unlockfile(lf)
+
+        for url in urls:
+            download(url)
+
         if checksum_missing_messages:
             logger.error("Missing SRC_URI checksum, please add those to the recipe: \n%s", "\n".join(checksum_missing_messages))
             raise BBFetchException("There was some missing checksums in the recipe")
@@ -1971,7 +1978,7 @@  class Fetch(object):
         if not urls:
             urls = self.urls
 
-        for url in urls:
+        def checkstatus(url):
             ud = self.ud[url]
             ud.setup_localpath(self.d)
             m = ud.method
@@ -1990,6 +1997,9 @@  class Fetch(object):
             if not ret:
                 raise FetchError("URL doesn't work", url)
 
+        for url in urls:
+            checkstatus(url)
+
     def unpack(self, root, urls=None):
         """
         Unpack urls to root
@@ -2000,7 +2010,7 @@  class Fetch(object):
 
         unpack_tracer.start(root, self.ud, self.d)
 
-        for url in urls:
+        def unpack(url):
             ud = self.ud[url]
             ud.setup_localpath(self.d)
 
@@ -2014,6 +2024,9 @@  class Fetch(object):
             if ud.lockfile:
                 bb.utils.unlockfile(lf)
 
+        for url in urls:
+            unpack(url)
+
         unpack_tracer.complete()
 
     def clean(self, urls=None):
@@ -2024,14 +2037,14 @@  class Fetch(object):
         if not urls:
             urls = self.urls
 
-        for url in urls:
+        def clean(url):
             if url not in self.ud:
                 self.ud[url] = FetchData(url, self.d)
             ud = self.ud[url]
             ud.setup_localpath(self.d)
 
             if not ud.localfile and ud.localpath is None:
-                continue
+                return
 
             if ud.lockfile:
                 lf = bb.utils.lockfile(ud.lockfile)
@@ -2043,6 +2056,9 @@  class Fetch(object):
             if ud.lockfile:
                 bb.utils.unlockfile(lf)
 
+        for url in urls:
+            clean(url)
+
     def expanded_urldata(self, urls=None):
         """
         Get an expanded list of FetchData objects covering both the given
@@ -2054,10 +2070,13 @@  class Fetch(object):
             urls = self.urls
 
         urldata = []
-        for url in urls:
+        def expand_urldata(url):
             ud = self.ud[url]
             urldata.append(ud)
-            urldata += ud.method.implicit_urldata(ud, self.d)
+            urldata.extend(ud.method.implicit_urldata(ud, self.d))
+
+        for url in urls:
+            expand_urldata(url)
 
         return urldata