diff mbox series

cooker: Clean up collect_bbfiles handling

Message ID 20260826162530.2483331-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series cooker: Clean up collect_bbfiles handling | expand

Commit Message

Richard Purdie Aug. 26, 2026, 4:25 p.m. UTC
Calling collect_bbfiles from within matchFiles is horrible. Most code paths
already have a parsed configuration, except the command API call. Change that
to require a configuration and then call collect_bbfiles earlier during
parseConfiguration so the data is always available.

Also, rather than have half object entries and half return values, store all
the output of collect_bbfiles in the object to improve consistency.

This fixes consistency issues where self.collections may have done something
different to the main code paths, e.g. when listing bbappends with -b usage.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/command.py |  2 +-
 lib/bb/cooker.py  | 24 +++++++++++++-----------
 2 files changed, 14 insertions(+), 12 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/command.py b/lib/bb/command.py
index 1b16884fa77..9c421aa9a8c 100644
--- a/lib/bb/command.py
+++ b/lib/bb/command.py
@@ -257,7 +257,7 @@  class CommandsSync:
         except IndexError:
             mc = ''
         return command.cooker.matchFile(fMatch, mc)
-    matchFile.needconfig = False
+    matchFile.needconfig = True
 
     def getUIHandlerNum(self, command, params):
         return bb.event.get_uihandler()
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index bd4ee164abc..00a6bac555f 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -445,6 +445,7 @@  You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
         self.collections = {}
         for mc in self.multiconfigs:
             self.collections[mc] = CookerCollectFiles(self.bbfile_config_priorities, mc)
+            self.collections[mc].collect_bbfiles(self.databuilder.mcdata[mc], self.databuilder.mcdata[mc])
 
         self._parsecache_set(False)
 
@@ -1322,8 +1323,8 @@  You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
         if bf.startswith("/") or bf.startswith("../"):
             bf = os.path.abspath(bf)
 
-        collections = {mc: CookerCollectFiles(self.bbfile_config_priorities, mc)}
-        filelist, masked, searchdirs = collections[mc].collect_bbfiles(self.databuilder.mcdata[mc], self.databuilder.mcdata[mc])
+        filelist = self.collections[mc].bbfiles
+
         try:
             os.stat(bf)
             bf = os.path.abspath(bf)
@@ -1668,11 +1669,9 @@  You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
             total_masked = 0
             searchdirs = set()
             for mc in self.multiconfigs:
-                (filelist, masked, search) = self.collections[mc].collect_bbfiles(self.databuilder.mcdata[mc], self.databuilder.mcdata[mc])
-
-                mcfilelist[mc] = filelist
-                total_masked += masked
-                searchdirs |= set(search)
+                mcfilelist[mc] = self.collections[mc].bbfiles
+                total_masked += self.collections[mc].maskedcount
+                searchdirs |= set(self.collections[mc].searchdirs)
 
             # Add mtimes for directories searched for bb/bbappend files
             for dirent in searchdirs:
@@ -1813,6 +1812,7 @@  class CookerCollectFiles(object):
     def __init__(self, priorities, mc=''):
         self.mc = mc
         self.bbappends = []
+        self.overlayed = None
         # Priorities is a list of tuples, with the second element as the pattern.
         # We need to sort the list with the longest pattern first, and so on to
         # the shortest.  This allows nested layers to be properly evaluated.
@@ -1847,7 +1847,10 @@  class CookerCollectFiles(object):
 
     def collect_bbfiles(self, config, eventdata):
         """Collect all available .bb build files"""
+        bbfiles = []
+        bbappend = []
         masked = 0
+        searchdirs = []
 
         collectlog.debug("collecting .bb files")
 
@@ -1870,7 +1873,6 @@  class CookerCollectFiles(object):
         origlistdir = os.listdir
         if hasattr(os, 'scandir'):
             origscandir = os.scandir
-        searchdirs = []
 
         def ourlistdir(d):
             searchdirs.append(d)
@@ -1932,8 +1934,6 @@  class CookerCollectFiles(object):
                 collectlog.critical("BBMASK is not a valid regular expression, ignoring: %s" % bbmask)
                 bbmask = None
 
-        bbfiles = []
-        bbappend = []
         for f in newfiles:
             if bbmask and bbmask_compiled.search(f):
                 collectlog.debug("skipping masked file %s", f)
@@ -1963,7 +1963,9 @@  class CookerCollectFiles(object):
                 topfile = bbfile_seen[base]
                 self.overlayed[topfile].append(f)
 
-        return (bbfiles, masked, searchdirs)
+        self.searchdirs = searchdirs
+        self.maskedcount = masked
+        self.bbfiles = bbfiles
 
     def get_file_appends(self, fn):
         """