diff mbox series

[1/7] license_finder: keep all license files of the nearest directory

Message ID 20261201034910.25521-2-tim.orling@konsulko.com
State New
Headers show
Series go-mod-update-modules: identify licenses with licensecheck | expand

Commit Message

Tim Orling Dec. 1, 2026, 3:49 a.m. UTC
find_license_files() with first_only returned only the first license
file, in name order, of the nearest directory.
github.com/klauspost/pgzip has LICENSE (MIT) and GO_LICENSE
(BSD-3-Clause), so go-mod-update-modules left out MIT.

Return every license file of that directory. The top-down search that
recipetool uses is unchanged.

AI-Generated: Claude Opus 5.5
Signed-off-by: Tim Orling <tim.orling@konsulko.com>
---
 meta/lib/oe/license_finder.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py
index 9c217cf891..d08d4af5d2 100644
--- a/meta/lib/oe/license_finder.py
+++ b/meta/lib/oe/license_finder.py
@@ -127,7 +127,10 @@  def _crunch_license(licfile):
 def find_license_files(srctree, first_only=False, bottom=""):
     """
     Search srctree for files that look like they could be licenses.
-    If first_only is True, only return the first file found.
+    If first_only is True, only return the first file found. When searching
+    upwards from bottom, return all files from the first directory that has
+    any instead, because a directory can hold several licenses, for example
+    LICENSE for the project and GO_LICENSE for code copied from Go.
     If bottom is not empty, start at bottom and continue upwards to the top.
     """
     licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10']
@@ -144,11 +147,10 @@  def find_license_files(srctree, first_only=False, bottom=""):
             for name in sorted(files):
                 if name.endswith(skip_extensions):
                     continue
-                for spec in licspecs:
-                    if fnmatch.fnmatch(name, spec):
-                        licfiles.append(os.path.join(srcdir, name))
-                        if first_only:
-                            return licfiles
+                if any(fnmatch.fnmatch(name, spec) for spec in licspecs):
+                    licfiles.append(os.path.join(srcdir, name))
+            if first_only and licfiles:
+                return licfiles
             srcdir = os.path.dirname(srcdir)
         return licfiles