diff mbox series

[1/2] cooker: Fix corner cases where BBFILES globbed directories were not expanded

Message ID 20261112142755.3343305-1-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/2] cooker: Fix corner cases where BBFILES globbed directories were not expanded | expand

Commit Message

Richard Purdie Nov. 12, 2026, 2:27 p.m. UTC
If the BBFILES glob expands into directories instead of files, the directories
are not traversed and the files are not added. This is in contrast to
the behaviour if a directory is explictly listed and I believe an oversight
in the implementation.

Rearrange the code so that directories resolved by globs are traversed.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cooker.py | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 8a422e50621..af53135353e 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -1890,19 +1890,20 @@  class CookerCollectFiles(object):
             # Can't use set here as order is important
             newfiles = []
             for f in files:
-                if os.path.isdir(f):
-                    dirfiles = self.find_bbfiles(f)
-                    for g in dirfiles:
-                        if g not in newfiles:
-                            newfiles.append(g)
+                globbed = []
+                if os.path.exists(f):
+                    globbed = [f]
                 else:
-                    globbed = glob.glob(f)
-                    if not globbed and os.path.exists(f):
-                        globbed = [f]
                     # glob gives files in order on disk. Sort to be deterministic.
-                    for g in sorted(globbed):
-                        if g not in newfiles:
-                            newfiles.append(g)
+                    globbed = sorted(glob.glob(f))
+                for g in globbed:
+                    if os.path.isdir(g):
+                        dirfiles = self.find_bbfiles(g)
+                        for g in dirfiles:
+                            if g not in newfiles:
+                                newfiles.append(g)
+                    elif g not in newfiles:
+                        newfiles.append(g)
         finally:
             os.listdir = origlistdir
             if hasattr(os, 'scandir'):