public inbox for openembedded-core@lists.openembedded.org
 help / color / mirror / Atom feed
From: "Meh Mbeh Ida Delphine" <idadelm@gmail.com>
To: openembedded-core@lists.openembedded.org
Subject: [poky-contrib][RFC PATCH 5/5] package.bbclass: Remove false positive license warnings
Date: Wed, 17 Feb 2021 05:00:33 +0100	[thread overview]
Message-ID: <20210217040033.21541-6-idadelm@gmail.com> (raw)
In-Reply-To: <20210217040033.21541-1-idadelm@gmail.com>

- Splits license strings and canonicalise using split_spdx_lic() from license.bbclass. This is so that they can be easily compared with the computedpkglics. The computedpkglics are passed into rem_false_lics() in order so that more warnings can be filtered during comparism with the source licenses.
- After the comparism between computedpkglics and recipe lics, the warnings are displayed if and only if there are licenses in the recipes not found in the sources.
- package_qa_handle_error() from insane.bbclass handles display of warnings by allowing the user decide whether they want the issues treated as warnings, errors or hidden completely. This is done by setting a variable "license_source_spdx"

Signed-off-by: Ida Delphine <idadelm@gmail.com>
---
 meta/classes/package.bbclass | 145 ++++++++++++++++-------------------
 1 file changed, 68 insertions(+), 77 deletions(-)

diff --git a/meta/classes/package.bbclass b/meta/classes/package.bbclass
index 782d9d00b3..08e8fa1694 100644
--- a/meta/classes/package.bbclass
+++ b/meta/classes/package.bbclass
@@ -1546,6 +1546,7 @@ PKGDATA_VARS = "PN PE PV PR PKGE PKGV PKGR LICENSE DESCRIPTION SUMMARY RDEPENDS
 
 python emit_pkgdata() {
     import oe.license
+    import bb.utils
     from glob import glob
     import json
     import subprocess
@@ -1706,83 +1707,73 @@ fi
         write_extra_runtime_pkgs(global_variants, packages, pkgdatadir)
 
     sourceresult = d.getVar('TEMPDBGSRCMAPPING', False)
-    sources = {}
-    if sourceresult:
-        for r in sourceresult:
-            sources[r[0]] = r[1]
-        with open(data_file + ".srclist", 'w') as f:
-            f.write(json.dumps(sources, sort_keys=True))
-
-        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
-        with open(data_file + ".filelics", 'w') as f:
-            f.write(json.dumps(filelics, sort_keys=True))
-
-        computedlics = {}
-        computedpkglics = {}
-        for r in sourceresult:
-            for subf in r[1]:
-                if subf in filelics:
-                    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, "")
-            found = False
-            for pkg in filemap:
-                if shortf in filemap[pkg]:
-                    found = True
-                    if pkg not in computedpkglics:
-                        computedpkglics[pkg] = set()
-                    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:
-                lic = d.getVar('LICENSE')
-
-            # Splits the LICENSE values and canonicalise each license
-            # in the set of split license(s)    
-            split_lic = oe.license.list_licenses(lic)
-            spdx_lic = set([canonical_license(d, l) for l in split_lic])
-            if computedpkglics[pkg]:
-                computedpkglicsperpkg = set([])
-                for l in computedpkglics[pkg]:
-                    if l.endswith('-or-later'):
-                        lic_ = l.replace('-or-later', '+')
-                        computedpkglicsperpkg.add(lic_)
-                    elif l.endswith(' WITH Linux-syscall-note'):
-                        if d.getVar("IGNOREWITHLINUXSYSCALLNOTE") == "1":
-                            lic_ = l.replace(' WITH Linux-syscall-note', '')
-                            computedpkglicsperpkg.add(lic_)
-                    else:
-                        computedpkglicsperpkg.add(l)
-            # Displays warnings for licenses found in the recipes and not sources
-            if spdx_lic - computedpkglicsperpkg:
-                bb.warn("License for package %s is %s (source SPDX headers) vs %s (LICENSE)" % (pkg, computedpkglicsperpkg, spdx_lic))
+    if bb.utils.contains("license_source_spdx", "1", True, False, d):
+        sources = {}
+        if sourceresult:
+            for r in sourceresult:
+                sources[r[0]] = r[1]
+            with open(data_file + ".srclist", 'w') as f:
+                f.write(json.dumps(sources, sort_keys=True))
+
+            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
+            with open(data_file + ".filelics", 'w') as f:
+                f.write(json.dumps(filelics, sort_keys=True))
+
+            computedlics = {}
+            computedpkglics = {}
+            for r in sourceresult:
+                for subf in r[1]:
+                    if subf in filelics:
+                        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, "")
+                found = False
+                for pkg in filemap:
+                    if shortf in filemap[pkg]:
+                        found = True
+                        if pkg not in computedpkglics:
+                            computedpkglics[pkg] = set()
+                        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:
+                    lic = d.getVar('LICENSE')
+
+                # Splits the LICENSE values and canonicalise each license
+                # in the set of split license(s)
+                spdx_lic = split_spdx_lic(d, lic)
+                computedpkglicsperpkg = rem_false_lics(d, computedpkglics[pkg])    
+               
+                # Displays warnings for licenses found in the recipes and not sources
+                if spdx_lic - computedpkglicsperpkg:
+                    package_qa_handle_error("license_source_spdx", f'License for package {pkg} is {computedpkglicsperpkg} (source SPDX headers) vs {spdx_lic} (LICENSE)', d)
 }
 emit_pkgdata[dirs] = "${PKGDESTWORK}/runtime ${PKGDESTWORK}/runtime-reverse ${PKGDESTWORK}/runtime-rprovides"
 
-- 
2.25.1


  parent reply	other threads:[~2021-02-17  4:01 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-17  4:00 [poky-contrib][RFC PATCH 0/5] Suggestions for improvements? Meh Mbeh Ida Delphine
2021-02-17  4:00 ` [poky-contrib][RFC PATCH 1/5] package: Remove false positive lic warnings Meh Mbeh Ida Delphine
2021-02-17 10:42   ` [OE-core] " Richard Purdie
2021-02-17  4:00 ` [poky-contrib][RFC PATCH 2/5] " Meh Mbeh Ida Delphine
2021-02-17 10:39   ` [OE-core] " Richard Purdie
2021-02-17 14:55     ` Peter Kjellerstedt
2021-02-17 15:04       ` Richard Purdie
2021-02-17  4:00 ` [poky-contrib][RFC PATCH 3/5] " Meh Mbeh Ida Delphine
2021-02-17  4:00 ` [poky-contrib][RFC PATCH 4/5] license.bbclass: Add functions to split and canonicalise license strings Meh Mbeh Ida Delphine
2021-02-17 10:45   ` [OE-core] " Richard Purdie
2021-02-17 15:04   ` Peter Kjellerstedt
2021-02-17 16:36     ` Richard Purdie
2021-02-17 16:55       ` Meh Mbeh Ida Delphine
2021-02-17 20:51         ` Richard Purdie
2021-02-21  3:04           ` Meh Mbeh Ida Delphine
2021-02-21 11:21             ` Richard Purdie
2021-02-17  4:00 ` Meh Mbeh Ida Delphine [this message]
2021-02-17 15:50 ` [OE-core] [poky-contrib][RFC PATCH 0/5] Suggestions for improvements? Peter Kjellerstedt
2021-02-17 16:58   ` Meh Mbeh Ida Delphine
2021-02-18 11:17     ` Peter Kjellerstedt
2021-02-18 12:21       ` Meh Mbeh Ida Delphine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210217040033.21541-6-idadelm@gmail.com \
    --to=idadelm@gmail.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox