The logic to obtain filelics is moved from package.bbclass to license.py as a 
standalone function.
Also, the check in package.bbclass after obtaining filelics ensures licenses 
with * WITH Linux-syscall-note" are ignored, as long as they're only in header 
files.

Signed-off-by: Ida Delphine <[email protected]>
---
 meta/classes/package.bbclass | 35 ++++++++++++-----------------------
 meta/lib/oe/license.py       | 29 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 23 deletions(-)

diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 8cd7f3ad21..a2144ec08e 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -1715,28 +1715,19 @@ fi
             with open(data_file + ".srclist", 'w') as f:
                 f.write(json.dumps(sources, sort_keys=True))
 
+            flics = oe.license.get_filelics([d.getVar('PKGD'), 
d.getVar('STAGING_DIR_TARGET')])
             filelics = {}
-            for dirent in [d.getVar('PKGD'), d.getVar('STAGING_DIR_TARGET')]:
-                p = subprocess.Popen(["grep", 'SPDX-License-Identifier:', 
'-R', '-I'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=dirent)
-                out, err = p.communicate()
-                if p.returncode == 0:
-                    for l in out.decode("utf-8").split("\n"):
-                        l = l.strip()
-                        if not l:
-                            continue
-                        l = l.split(":")
-                        if len(l) < 3:
-                            bb.warn(str(l))
-                            continue
-                        fn = "/" + l[0]
-                        lic = l[2].strip()
-                        if lic.endswith("*/"):
-                            lic = lic[:-2]
-                        lic = lic.strip()
-                        filelics[fn] = lic
+            header_list = [".h", ".hh", ".hpp"]
+            for k, v in flics.items():
+                # This check ignores "*WITH Linux-syscall-note" licenses in 
header files since the headers aren't part of the original sources and come 
from dependencies the software links to.
+                #C/C++ headers because most of the ones being match are from 
the Linux kernel.
+                if k.endswith(tuple(header_list)) and v.endswith("WITH 
Linux-syscall-note"):
+                    continue
+                else:
+                    filelics[k] = v
             with open(data_file + ".filelics", 'w') as f:
                 f.write(json.dumps(filelics, sort_keys=True))
-
+  
             computedlics = {}
             computedpkglics = {}
             for r in sourceresult:
@@ -1745,8 +1736,7 @@ fi
                         if r[0] not in computedlics:
                             computedlics[r[0]] = set()
                         computedlics[r[0]].add(filelics[subf])
-            #if computedlics:
-            #    bb.warn(str(computedlics))
+            
             dvar = d.getVar('PKGD')
             for f in computedlics:
                 shortf = f.replace(dvar, "")
@@ -1759,8 +1749,7 @@ fi
                         computedpkglics[pkg].update(computedlics[f])
                 if not found:
                     bb.warn("%s not in %s" % (f, str(filemap)))
-            #if computedpkglics:
-            #    bb.warn(str(computedpkglics))
+            
             for pkg in computedpkglics:
                 lic = d.getVar('LICENSE_%s' % (pkg))
                 if not lic:
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index dc1bc6682c..45f90ff151 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -6,6 +6,8 @@
 import ast
 import re
 from fnmatch import fnmatchcase as fnmatch
+import subprocess
+import bb
 
 def license_ok(license, dont_want_licenses):
     """ Return False if License exist in dont_want_licenses else True """
@@ -262,3 +264,30 @@ def split_spdx_lic(licensestr,d):
     split_lic = list_licenses(licensestr)
     spdx_lic = set([canonical_license(l, d) for l in split_lic])
     return spdx_lic
+
+def get_filelics(dirs):
+    """"
+    This function returns a dictionary of file paths (keys) and their 
corresponding SPDX header identifiers (values).
+    """
+    filelics = {}
+    for dirent in dirs:
+        p = subprocess.Popen(["grep", 'SPDX-License-Identifier:', '-R','-I'], 
stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=dirent)
+        out, err = p.communicate()
+        if p.returncode == 0:
+            for l in out.decode("utf-8").split("\n"):
+                l = l.strip()
+                if not l:
+                    continue
+                l = l.split(":")
+                if len(l) < 3:
+                    bb.warn(str(l))
+                    continue
+                fn = "/" + l[0]
+                lic = l[2].strip()
+                if lic.endswith("*/"):
+                    lic = lic[:-2]
+                lic = lic.strip()
+                filelics[fn] = lic
+    return filelics
+    
+
-- 
2.25.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#149559): 
https://lists.openembedded.org/g/openembedded-core/message/149559
Mute This Topic: https://lists.openembedded.org/mt/81371634/21656
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to