summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSaul Wold <Saul.Wold@windriver.com>2022-02-23 17:26:59 -0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-02 18:43:25 +0000
commitd6449581c998a24145e527c571b3baf90a9f2518 (patch)
treef20a0fd2e91dd9fb294e5243f28b1533fc8ec21c
parent9ead8e762e977d41b0107553b4827f9a7edc252f (diff)
downloadpoky-d6449581c998a24145e527c571b3baf90a9f2518.tar.gz
base/license: Rework INCOMPATIBLE_LICENSE variable handling
This re-writes the INCOMPATIBLE_LICENSE checking code to replace the WHITELIST_<lic> with INCOMPATIBLE_LICENSE_EXCEPTIONS = '<pkg>:<lic> <pkg>:<lic> ...' This initial change leaves most of the code structure in place, but the code in base.bbclass needs to be re-written to make the check more consistent around packages (PKGS) and not recipe names (PN). This also is taking into account the changes for SPDX licenses. The aim is to provide a mode consistent variable where the variable name is known and can easily be queried. (From OE-Core rev: 0d19c45ba6cf43518f380ca5afe9753a2eda0691) Signed-off-by: Saul Wold <saul.wold@windriver.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/base.bbclass67
-rw-r--r--meta/classes/license_image.bbclass33
-rw-r--r--meta/classes/multilib.bbclass6
-rw-r--r--meta/conf/bitbake.conf11
-rw-r--r--meta/lib/oe/license.py5
-rw-r--r--meta/lib/oeqa/selftest/cases/incompatible_lic.py4
6 files changed, 63 insertions, 63 deletions
diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index 55f654d37d..1d5db96afb 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -595,46 +595,35 @@ python () {
595 if check_license and bad_licenses: 595 if check_license and bad_licenses:
596 bad_licenses = expand_wildcard_licenses(d, bad_licenses) 596 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
597 597
598 whitelist = [] 598 exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or "").split()
599 for lic in bad_licenses: 599
600 spdx_license = return_spdx(d, lic) 600 pkgs = d.getVar('PACKAGES').split()
601 whitelist.extend((d.getVar("WHITELIST_" + lic) or "").split()) 601 skipped_pkgs = {}
602 if spdx_license: 602 unskipped_pkgs = []
603 whitelist.extend((d.getVar("WHITELIST_" + spdx_license) or "").split()) 603 for pkg in pkgs:
604 604 remaining_bad_licenses = oe.license.apply_pkg_license_exception(pkg, bad_licenses, exceptions)
605 if pn in whitelist: 605
606 ''' 606 incompatible_lic = incompatible_license(d, remaining_bad_licenses, pkg)
607 We need to track what we are whitelisting and why. If pn is 607 if incompatible_lic:
608 incompatible we need to be able to note that the image that 608 skipped_pkgs[pkg] = incompatible_lic
609 is created may infact contain incompatible licenses despite
610 INCOMPATIBLE_LICENSE being set.
611 '''
612 bb.note("Including %s as buildable despite it having an incompatible license because it has been whitelisted" % pn)
613 else:
614 pkgs = d.getVar('PACKAGES').split()
615 skipped_pkgs = {}
616 unskipped_pkgs = []
617 for pkg in pkgs:
618 incompatible_lic = incompatible_license(d, bad_licenses, pkg)
619 if incompatible_lic:
620 skipped_pkgs[pkg] = incompatible_lic
621 else:
622 unskipped_pkgs.append(pkg)
623 if unskipped_pkgs:
624 for pkg in skipped_pkgs:
625 bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
626 d.setVar('_exclude_incompatible-' + pkg, ' '.join(skipped_pkgs[pkg]))
627 for pkg in unskipped_pkgs:
628 bb.debug(1, "Including the package %s" % pkg)
629 else: 609 else:
630 incompatible_lic = incompatible_license(d, bad_licenses) 610 unskipped_pkgs.append(pkg)
631 for pkg in skipped_pkgs: 611
632 incompatible_lic += skipped_pkgs[pkg] 612 if unskipped_pkgs:
633 incompatible_lic = sorted(list(set(incompatible_lic))) 613 for pkg in skipped_pkgs:
634 614 bb.debug(1, "Skipping the package %s at do_rootfs because of incompatible license(s): %s" % (pkg, ' '.join(skipped_pkgs[pkg])))
635 if incompatible_lic: 615 d.setVar('_exclude_incompatible-' + pkg, ' '.join(skipped_pkgs[pkg]))
636 bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic))) 616 for pkg in unskipped_pkgs:
637 raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic)) 617 bb.debug(1, "Including the package %s" % pkg)
618 else:
619 incompatible_lic = incompatible_license(d, bad_licenses)
620 for pkg in skipped_pkgs:
621 incompatible_lic += skipped_pkgs[pkg]
622 incompatible_lic = sorted(list(set(incompatible_lic)))
623
624 if incompatible_lic:
625 bb.debug(1, "Skipping recipe %s because of incompatible license(s): %s" % (pn, ' '.join(incompatible_lic)))
626 raise bb.parse.SkipRecipe("it has incompatible license(s): %s" % ' '.join(incompatible_lic))
638 627
639 needsrcrev = False 628 needsrcrev = False
640 srcuri = d.getVar('SRC_URI') 629 srcuri = d.getVar('SRC_URI')
diff --git a/meta/classes/license_image.bbclass b/meta/classes/license_image.bbclass
index bf70bee99b..0a5ea0a2fb 100644
--- a/meta/classes/license_image.bbclass
+++ b/meta/classes/license_image.bbclass
@@ -54,28 +54,23 @@ def write_license_files(d, license_manifest, pkg_dic, rootfs=True):
54 bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE") or "").split() 54 bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE") or "").split()
55 bad_licenses = expand_wildcard_licenses(d, bad_licenses) 55 bad_licenses = expand_wildcard_licenses(d, bad_licenses)
56 56
57 whitelist = [] 57 exceptions = (d.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS") or "").split()
58 for lic in bad_licenses:
59 whitelist.extend((d.getVar("WHITELIST_" + lic) or "").split())
60
61 with open(license_manifest, "w") as license_file: 58 with open(license_manifest, "w") as license_file:
62 for pkg in sorted(pkg_dic): 59 for pkg in sorted(pkg_dic):
63 if bad_licenses and pkg not in whitelist: 60 remaining_bad_licenses = oe.license.apply_pkg_license_exception(pkg, bad_licenses, exceptions)
64 try: 61 incompatible_licenses = incompatible_pkg_license(d, remaining_bad_licenses, pkg_dic[pkg]["LICENSE"])
65 licenses = incompatible_pkg_license(d, bad_licenses, pkg_dic[pkg]["LICENSE"]) 62 if incompatible_licenses:
66 if licenses: 63 bb.fatal("Package %s cannot be installed into the image because it has incompatible license(s): %s" %(pkg, ' '.join(incompatible_licenses)))
67 bb.fatal("Package %s cannot be installed into the image because it has incompatible license(s): %s" %(pkg, ' '.join(licenses)))
68 (pkg_dic[pkg]["LICENSE"], pkg_dic[pkg]["LICENSES"]) = \
69 oe.license.manifest_licenses(pkg_dic[pkg]["LICENSE"],
70 bad_licenses, canonical_license, d)
71 except oe.license.LicenseError as exc:
72 bb.fatal('%s: %s' % (d.getVar('P'), exc))
73 else: 64 else:
74 pkg_dic[pkg]["LICENSES"] = re.sub(r'[|&()*]', ' ', pkg_dic[pkg]["LICENSE"]) 65 incompatible_licenses = incompatible_pkg_license(d, bad_licenses, pkg_dic[pkg]["LICENSE"])
75 pkg_dic[pkg]["LICENSES"] = re.sub(r' *', ' ', pkg_dic[pkg]["LICENSES"]) 66 if incompatible_licenses:
76 pkg_dic[pkg]["LICENSES"] = pkg_dic[pkg]["LICENSES"].split() 67 oe.qa.handle_error('license-incompatible', "Including %s with incompatible license(s) %s into the image, because it has been allowed by exception list." %(pkg, ' '.join(incompatible_licenses)), d)
77 if pkg in whitelist: 68 try:
78 oe.qa.handle_error('license-incompatible', "Including %s with an incompatible license %s into the image, because it has been whitelisted." %(pkg, pkg_dic[pkg]["LICENSE"]), d) 69 (pkg_dic[pkg]["LICENSE"], pkg_dic[pkg]["LICENSES"]) = \
70 oe.license.manifest_licenses(pkg_dic[pkg]["LICENSE"],
71 remaining_bad_licenses, canonical_license, d)
72 except oe.license.LicenseError as exc:
73 bb.fatal('%s: %s' % (d.getVar('P'), exc))
79 74
80 if not "IMAGE_MANIFEST" in pkg_dic[pkg]: 75 if not "IMAGE_MANIFEST" in pkg_dic[pkg]:
81 # Rootfs manifest 76 # Rootfs manifest
diff --git a/meta/classes/multilib.bbclass b/meta/classes/multilib.bbclass
index 1ad654f546..5859ca8d21 100644
--- a/meta/classes/multilib.bbclass
+++ b/meta/classes/multilib.bbclass
@@ -75,12 +75,12 @@ python multilib_virtclass_handler () {
75 e.data.setVar("PN", variant + "-" + e.data.getVar("PN", False)) 75 e.data.setVar("PN", variant + "-" + e.data.getVar("PN", False))
76 e.data.setVar("OVERRIDES", e.data.getVar("OVERRIDES", False) + override) 76 e.data.setVar("OVERRIDES", e.data.getVar("OVERRIDES", False) + override)
77 77
78 # Expand WHITELIST_GPL-3.0 with multilib prefix 78 # Expand INCOMPATIBLE_LICENSE_EXCEPTIONS with multilib prefix
79 pkgs = e.data.getVar("WHITELIST_GPL-3.0") 79 pkgs = e.data.getVar("INCOMPATIBLE_LICENSE_EXCEPTIONS")
80 if pkgs: 80 if pkgs:
81 for pkg in pkgs.split(): 81 for pkg in pkgs.split():
82 pkgs += " " + variant + "-" + pkg 82 pkgs += " " + variant + "-" + pkg
83 e.data.setVar("WHITELIST_GPL-3.0", pkgs) 83 e.data.setVar("INCOMPATIBLE_LICENSE_EXCEPTIONS", pkgs)
84 84
85 # DEFAULTTUNE can change TARGET_ARCH override so expand this now before update_data 85 # DEFAULTTUNE can change TARGET_ARCH override so expand this now before update_data
86 newtune = e.data.getVar("DEFAULTTUNE:" + "virtclass-multilib-" + variant, False) 86 newtune = e.data.getVar("DEFAULTTUNE:" + "virtclass-multilib-" + variant, False)
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 6fb7bfeb23..7705415a4f 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -110,6 +110,17 @@ BB_RENAMED_VARIABLES[INHERIT_BLACKLIST] = "is a deprecated variable and no longe
110BB_RENAMED_VARIABLES[TUNEABI_WHITELIST] = "is a deprecated variable and support has been removed" 110BB_RENAMED_VARIABLES[TUNEABI_WHITELIST] = "is a deprecated variable and support has been removed"
111BB_RENAMED_VARIABLES[LICENSE_FLAGS_WHITELIST] = "LICENSE_FLAGS_ACCEPTED" 111BB_RENAMED_VARIABLES[LICENSE_FLAGS_WHITELIST] = "LICENSE_FLAGS_ACCEPTED"
112 112
113BB_RENAMED_VARIABLES[WHITELIST_GPL-3.0-only] = "INCOMPATIBLE_LICENSE_EXCEPTIONS"
114BB_RENAMED_VARIABLES[WHITELIST_GPL-3.0-or-later] = "INCOMPATIBLE_LICENSE_EXCEPTIONS"
115BB_RENAMED_VARIABLES[WHITELIST_LGPL-3.0-only] = "INCOMPATIBLE_LICENSE_EXCEPTIONS"
116BB_RENAMED_VARIABLES[WHITELIST_LGPL-3.0-or-later] = "INCOMPATIBLE_LICENSE_EXCEPTIONS"
117
118# These are deprecated version and should be updated to approved names
119BB_RENAMED_VARIABLES[WHITELIST_GPL-3.0] = "is deprecated, convert to INCOMPATIBLE_LICENSE_EXCEPTIONS = '<pkg>:GPL-3.0-only'"
120BB_RENAMED_VARIABLES[WHITELIST_GPL-3.0+] = "is deprecated, convert to INCOMPATIBLE_LICENSE_EXCEPTIONS = '<pkg>:GPL-3.0-or-later'"
121BB_RENAMED_VARIABLES[WHITELIST_LGPL-3.0] = "is deprecated, convert to INCOMPATIBLE_LICENSE_EXCEPTIONS = '<pkg>:LGPL-3.0-only'"
122BB_RENAMED_VARIABLES[WHITELIST_LGPL-3.0+] = "is deprecated, convert to INCOMPATIBLE_LICENSE_EXCEPTIONS = '<pkg>:LGPL-3.0-or-later'"
123
113################################################################## 124##################################################################
114# Architecture-dependent build variables. 125# Architecture-dependent build variables.
115################################################################## 126##################################################################
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index 8955cbdeb2..29412dfe46 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -242,3 +242,8 @@ def list_licenses(licensestr):
242 except SyntaxError as exc: 242 except SyntaxError as exc:
243 raise LicenseSyntaxError(licensestr, exc) 243 raise LicenseSyntaxError(licensestr, exc)
244 return visitor.licenses 244 return visitor.licenses
245
246def apply_pkg_license_exception(pkg, bad_licenses, exceptions):
247 """Return remaining bad licenses after removing any package exceptions"""
248
249 return [lic for lic in bad_licenses if pkg + ':' + lic not in exceptions]
diff --git a/meta/lib/oeqa/selftest/cases/incompatible_lic.py b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
index fd3b3f409e..c68f920555 100644
--- a/meta/lib/oeqa/selftest/cases/incompatible_lic.py
+++ b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
@@ -110,8 +110,8 @@ INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0 LGPL-3.0"
110 110
111 bitbake('core-image-minimal') 111 bitbake('core-image-minimal')
112 112
113 def test_bash_whitelist(self): 113 def test_bash_license_exceptions(self):
114 self.write_config(self.default_config() + '\nWHITELIST_GPL-3.0:pn-core-image-minimal = "bash"') 114 self.write_config(self.default_config() + '\nINCOMPATIBLE_LICENSE_EXCEPTIONS:pn-core-image-minimal = "bash:GPL-3.0-or-later"')
115 115
116 bitbake('core-image-minimal') 116 bitbake('core-image-minimal')
117 117