[v3,2/2] INCOMPATIBLE_LICENSE: add has_pkg_license_exception()

Message ID 20220226013147.120437-2-saul.wold@windriver.com
State New
Headers show
Series None | expand

Commit Message

Saul Wold Feb. 26, 2022, 1:31 a.m. UTC
This adds in the new function to check for both package and
license are in the new INCOMPATIBLE_LICENSE_EXCEPTION list.

This has been tested by changing the skeleton/hello to MIT-X
and using that license to verify it will be skipped or not
installed.  oe-selftest was also used.

Signed-off-by: Saul Wold <saul.wold@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta/classes/base.bbclass          | 66 ++++++++++++------------------
 meta/classes/license_image.bbclass |  5 ++-
 meta/lib/oe/license.py             | 10 +++++
 3 files changed, 40 insertions(+), 41 deletions(-)

Patch

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index ddca87d4a8c..fccf3df17ff 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -597,46 +597,34 @@  python () {
 
             exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or "").split()
 
-            pkg_exceptions = {}
-            for exception in exceptions:
-                pkg_lic = exception.split(':')
-                pkg_exceptions[pkg_lic[0]] = pkg_lic[1]
-
-#            if any((pn in execption and incompatible_lic in exception) for execption in exceptions):
-            if any(execption.startswith(pn + ':') for execption in exceptions):
-                '''
-                We need to track which recipes are in the exception
-                list and why. If pn is incompatible we need to be
-                able to note that the image that is created may
-                infact contain incompatible licenses despite
-                INCOMPATIBLE_LICENSE being set.
-                '''
-                bb.note("Including %s as a buildable recipe despite it having an incompatible license because it was found in the exception list" % pn)
-            else:
-                pkgs = d.getVar('PACKAGES').split()
-                skipped_pkgs = {}
-                unskipped_pkgs = []
-                for pkg in pkgs:
-                    incompatible_lic = incompatible_license(d, bad_licenses, pkg)
-                    if incompatible_lic:
-                        skipped_pkgs[pkg] = incompatible_lic
-                    else:
-                        unskipped_pkgs.append(pkg)
-                if unskipped_pkgs:
-                    for pkg in skipped_pkgs:
-                        bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
-                        d.setVar('_exclude_incompatible-' + pkg, ' '.join(skipped_pkgs[pkg]))
-                    for pkg in unskipped_pkgs:
-                        bb.debug(1, "Including the package %s" % pkg)
+            pkgs = d.getVar('PACKAGES').split()
+            skipped_pkgs = {}
+            unskipped_pkgs = []
+            for pkg in pkgs:
+                pkg_exception = oe.license.has_pkg_license_exception(pkg, bad_licenses, exceptions)
+
+                incompatible_lic = incompatible_license(d, bad_licenses, pkg)
+                if incompatible_lic and not pkg_exception:
+                    skipped_pkgs[pkg] = incompatible_lic
                 else:
-                    incompatible_lic = incompatible_license(d, bad_licenses)
-                    for pkg in skipped_pkgs:
-                        incompatible_lic += skipped_pkgs[pkg]
-                    incompatible_lic = sorted(list(set(incompatible_lic)))
-
-                    if incompatible_lic:
-                        bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
-                        raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
+                    unskipped_pkgs.append(pkg)
+
+            if unskipped_pkgs:
+                for pkg in skipped_pkgs:
+                    bb.warn( "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
+                    bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
+                    d.setVar('_exclude_incompatible-' + pkg, ' '.join(skipped_pkgs[pkg]))
+                for pkg in unskipped_pkgs:
+                    bb.debug(1, "Including the package %s" % pkg)
+            else:
+                incompatible_lic = incompatible_license(d, bad_licenses)
+                for pkg in skipped_pkgs:
+                    incompatible_lic += skipped_pkgs[pkg]
+                incompatible_lic = sorted(list(set(incompatible_lic)))
+
+                if incompatible_lic:
+                    bb.warn( "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
+                    raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
 
     needsrcrev = False
     srcuri = d.getVar('SRC_URI')
diff --git a/meta/classes/license_image.bbclass b/meta/classes/license_image.bbclass
index c6f04d30733..cae094126db 100644
--- a/meta/classes/license_image.bbclass
+++ b/meta/classes/license_image.bbclass
@@ -57,11 +57,12 @@  def write_license_files(d, license_manifest, pkg_dic, rootfs=True):
     exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or "").split()
     with open(license_manifest, "w") as license_file:
         for pkg in sorted(pkg_dic):
-            if bad_licenses and not any((pkg + ":") in execption for execption in exceptions):
+            pkg_exception = oe.license.has_pkg_license_exception(pkg, bad_licenses, exceptions)
+            if bad_licenses and not pkg_exception:
                     licenses = incompatible_pkg_license(d, bad_licenses, pkg_dic[pkg]["LICENSE"])
                     if licenses:
                         bb.fatal("Package %s cannot be installed into the image because it has incompatible license(s): %s" %(pkg, ' '.join(licenses)))
-            elif any((pkg + ":") in execption for execption in exceptions):
+            elif pkg_exception:
                 oe.qa.handle_error('license-incompatible', "Including %s with an incompatible license %s into the image, because it has been allowed by exception list." %(pkg, pkg_dic[pkg]["LICENSE"]), d)
             try:
                 (pkg_dic[pkg]["LICENSE"], pkg_dic[pkg]["LICENSES"]) = \
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index 8955cbdeb24..2404bbecb18 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -242,3 +242,13 @@  def list_licenses(licensestr):
     except SyntaxError as exc:
         raise LicenseSyntaxError(licensestr, exc)
     return visitor.licenses
+
+def has_pkg_license_exception(pkg, dont_want_licenses, exceptions):
+    """Check the exception list for the package and return a boolean"""
+
+    pkg_exception = False
+    for bad_lic in dont_want_licenses:
+        if (pkg + ':' + bad_lic) in exceptions:
+            pkg_exception = True
+    return pkg_exception
+