summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2022-02-28 15:40:32 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-02 18:43:25 +0000
commit82f24d21978456476f631812e73033d23a7eac64 (patch)
treecb6ba9dee8ac5606664e70c15cc49f6ac5fb7df2
parent321cf8962ea2f3ce6b3942fe02ec2ce8d258cce3 (diff)
downloadpoky-82f24d21978456476f631812e73033d23a7eac64.tar.gz
license: Rework INCOMPATIBLE_LICENSE wildcard handling
The current wildcard handling is badly documented and inconsistently used and understood. Forcing users to have to use "GPL-3.0-only GPL-3.0-or-later" whilst explict is not very user friendly. Equally, using the current wildcards is ambigious. This supports pre-defined expansions only and at least makes it clear what GPL-3.0* means (it doesn't include the exception licenses). This is hopefully an acceptable compromise between literal meaning and having something usable. Non-SPDX forms of license in this field have been dropped and errors are shown for unsupported expansions and unsupported old style license terms. Users need to carefully consider how to migrate to the new syntax but the meaning should be well defined and clear from here forward. (From OE-Core rev: 724fc8047cae6ed6197d7deca887b1594871c90e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/classes/license.bbclass41
-rw-r--r--meta/lib/oeqa/selftest/cases/incompatible_lic.py86
2 files changed, 70 insertions, 57 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 68c022248c..cb1f46983a 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -277,28 +277,27 @@ AVAILABLE_LICENSES := "${@' '.join(available_licenses(d))}"
277 277
278def expand_wildcard_licenses(d, wildcard_licenses): 278def expand_wildcard_licenses(d, wildcard_licenses):
279 """ 279 """
280 Return actual spdx format license names if wildcards are used. We expand 280 There are some common wildcard values users may want to use. Support them
281 wildcards from SPDXLICENSEMAP flags and AVAILABLE_LICENSES. 281 here.
282 """ 282 """
283 import fnmatch 283 licenses = set(wildcard_licenses)
284 284 mapping = {
285 licenses = wildcard_licenses[:] 285 "GPL-3.0*" : ["GPL-3.0-only", "GPL-3.0-or-later"],
286 spdxmapkeys = d.getVarFlags('SPDXLICENSEMAP').keys() 286 "LGPL-3.0*" : ["LGPL-3.0-only", "LGPL-3.0-or-later"],
287 for wld_lic in wildcard_licenses: 287 }
288 spdxflags = fnmatch.filter(spdxmapkeys, wld_lic) 288 for k in mapping:
289 licenses += [d.getVarFlag('SPDXLICENSEMAP', flag) for flag in spdxflags] 289 if k in wildcard_licenses:
290 # Assume that if we are passed "GPL-3.0" or "*GPL-3.0", then it means 290 licenses.remove(k)
291 # "-or-later" as well. 291 for item in mapping[k]:
292 if not wld_lic.endswith(("-or-later", "-only", "*", "+")): 292 licenses.add(item)
293 spdxflags = fnmatch.filter(spdxmapkeys, wld_lic + "+") 293
294 licenses += [d.getVarFlag('SPDXLICENSEMAP', flag) for flag in spdxflags] 294 for l in licenses:
295 295 if l in oe.license.obsolete_license_list():
296 spdx_lics = d.getVar('AVAILABLE_LICENSES').split() 296 bb.fatal("Error, %s is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE" % l)
297 for wld_lic in wildcard_licenses: 297 if "*" in l:
298 licenses += fnmatch.filter(spdx_lics, wld_lic) 298 bb.fatal("Error, %s is an invalid license wildcard entry" % l)
299 299
300 licenses = list(set(licenses)) 300 return list(licenses)
301 return licenses
302 301
303def incompatible_license_contains(license, truevalue, falsevalue, d): 302def incompatible_license_contains(license, truevalue, falsevalue, d):
304 license = canonical_license(d, license) 303 license = canonical_license(d, license)
diff --git a/meta/lib/oeqa/selftest/cases/incompatible_lic.py b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
index c68f920555..0794d46e6d 100644
--- a/meta/lib/oeqa/selftest/cases/incompatible_lic.py
+++ b/meta/lib/oeqa/selftest/cases/incompatible_lic.py
@@ -1,10 +1,11 @@
1from oeqa.selftest.case import OESelftestTestCase 1from oeqa.selftest.case import OESelftestTestCase
2from oeqa.utils.commands import bitbake 2from oeqa.utils.commands import bitbake
3 3
4class IncompatibleLicenseTests(OESelftestTestCase): 4class IncompatibleLicenseTestObsolete(OESelftestTestCase):
5 5
6 def lic_test(self, pn, pn_lic, lic): 6 def lic_test(self, pn, pn_lic, lic, error_msg=None):
7 error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic) 7 if not error_msg:
8 error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
8 9
9 self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic)) 10 self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
10 11
@@ -13,68 +14,81 @@ class IncompatibleLicenseTests(OESelftestTestCase):
13 raise AssertionError(result.output) 14 raise AssertionError(result.output)
14 15
15 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) 16 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
16 # cannot be built when INCOMPATIBLE_LICENSE contains this SPDX license
17 def test_incompatible_spdx_license(self):
18 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0-only')
19
20 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
21 # cannot be built when INCOMPATIBLE_LICENSE contains an alias (in 17 # cannot be built when INCOMPATIBLE_LICENSE contains an alias (in
22 # SPDXLICENSEMAP) of this SPDX license 18 # SPDXLICENSEMAP) of this SPDX license
23 def test_incompatible_alias_spdx_license(self): 19 def test_incompatible_alias_spdx_license(self):
24 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPLv3') 20 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
25
26 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
27 # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded license
28 # matching this SPDX license
29 def test_incompatible_spdx_license_wildcard(self):
30 self.lic_test('incompatible-license', 'GPL-3.0-only', '*GPL-3.0-only')
31 21
32 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES) 22 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
33 # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded alias 23 # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded alias
34 # license matching this SPDX license 24 # license matching this SPDX license
35 def test_incompatible_alias_spdx_license_wildcard(self): 25 def test_incompatible_alias_spdx_license_wildcard(self):
36 self.lic_test('incompatible-license', 'GPL-3.0-only', '*GPLv3') 26 self.lic_test('incompatible-license', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
37
38 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
39 # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
40 # license
41 def test_incompatible_spdx_license_alias(self):
42 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPL-3.0-only')
43 27
44 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX 28 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
45 # license cannot be built when INCOMPATIBLE_LICENSE contains this alias 29 # license cannot be built when INCOMPATIBLE_LICENSE contains this alias
46 def test_incompatible_alias_spdx_license_alias(self): 30 def test_incompatible_alias_spdx_license_alias(self):
47 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPLv3') 31 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPLv3', "is an obsolete license, please use an SPDX reference in INCOMPATIBLE_LICENSE")
48 32
49 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX 33 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
50 # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded 34 # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
51 # license matching this SPDX license 35 # license matching this SPDX license
52 def test_incompatible_spdx_license_alias_wildcard(self): 36 def test_incompatible_spdx_license_alias_wildcard(self):
53 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPL-3.0') 37 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPL-3.0', "*GPL-3.0 is an invalid license wildcard entry")
54 38
55 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX 39 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
56 # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded 40 # license cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded
57 # alias license matching the SPDX license 41 # alias license matching the SPDX license
58 def test_incompatible_alias_spdx_license_alias_wildcard(self): 42 def test_incompatible_alias_spdx_license_alias_wildcard(self):
59 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPLv3') 43 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', '*GPLv3', "*GPLv3 is an invalid license wildcard entry")
60 44
61 # Verify that a package with multiple SPDX licenses (from
62 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains
63 # some of them
64 def test_incompatible_spdx_licenses(self):
65 self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', 'GPL-3.0-only LGPL-3.0-only')
66 45
67 # Verify that a package with multiple SPDX licenses (from 46 # Verify that a package with multiple SPDX licenses (from
68 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a 47 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a
69 # wildcard to some of them 48 # wildcard to some of them
70 def test_incompatible_spdx_licenses_wildcard(self): 49 def test_incompatible_spdx_licenses_wildcard(self):
71 self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', '*GPL-3.0-only') 50 self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', '*GPL-3.0-only', "*GPL-3.0-only is an invalid license wildcard entry")
51
72 52
73 # Verify that a package with multiple SPDX licenses (from 53 # Verify that a package with multiple SPDX licenses (from
74 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a 54 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains a
75 # wildcard matching all licenses 55 # wildcard matching all licenses
76 def test_incompatible_all_licenses_wildcard(self): 56 def test_incompatible_all_licenses_wildcard(self):
77 self.lic_test('incompatible-licenses', 'GPL-2.0-only GPL-3.0-only LGPL-3.0-only', '*') 57 self.lic_test('incompatible-licenses', 'GPL-2.0-only GPL-3.0-only LGPL-3.0-only', '*', "* is an invalid license wildcard entry")
58
59class IncompatibleLicenseTests(OESelftestTestCase):
60
61 def lic_test(self, pn, pn_lic, lic):
62 error_msg = 'ERROR: Nothing PROVIDES \'%s\'\n%s was skipped: it has incompatible license(s): %s' % (pn, pn, pn_lic)
63
64 self.write_config("INCOMPATIBLE_LICENSE += \"%s\"" % (lic))
65
66 result = bitbake('%s --dry-run' % (pn), ignore_status=True)
67 if error_msg not in result.output:
68 raise AssertionError(result.output)
69
70 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
71 # cannot be built when INCOMPATIBLE_LICENSE contains this SPDX license
72 def test_incompatible_spdx_license(self):
73 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0-only')
74
75 # Verify that a package with an SPDX license (from AVAILABLE_LICENSES)
76 # cannot be built when INCOMPATIBLE_LICENSE contains a wildcarded license
77 # matching this SPDX license
78 def test_incompatible_spdx_license_wildcard(self):
79 self.lic_test('incompatible-license', 'GPL-3.0-only', 'GPL-3.0*')
80
81 # Verify that a package with an alias (from SPDXLICENSEMAP) to an SPDX
82 # license cannot be built when INCOMPATIBLE_LICENSE contains this SPDX
83 # license
84 def test_incompatible_spdx_license_alias(self):
85 self.lic_test('incompatible-license-alias', 'GPL-3.0-only', 'GPL-3.0-only')
86
87 # Verify that a package with multiple SPDX licenses (from
88 # AVAILABLE_LICENSES) cannot be built when INCOMPATIBLE_LICENSE contains
89 # some of them
90 def test_incompatible_spdx_licenses(self):
91 self.lic_test('incompatible-licenses', 'GPL-3.0-only LGPL-3.0-only', 'GPL-3.0-only LGPL-3.0-only')
78 92
79 # Verify that a package with a non-SPDX license (neither in 93 # Verify that a package with a non-SPDX license (neither in
80 # AVAILABLE_LICENSES nor in SPDXLICENSEMAP) cannot be built when 94 # AVAILABLE_LICENSES nor in SPDXLICENSEMAP) cannot be built when
@@ -86,7 +100,7 @@ class IncompatibleLicensePerImageTests(OESelftestTestCase):
86 def default_config(self): 100 def default_config(self):
87 return """ 101 return """
88IMAGE_INSTALL:append = " bash" 102IMAGE_INSTALL:append = " bash"
89INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0 LGPL-3.0" 103INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
90""" 104"""
91 105
92 def test_bash_default(self): 106 def test_bash_default(self):
@@ -118,15 +132,15 @@ INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0 LGPL-3.0"
118class NoGPL3InImagesTests(OESelftestTestCase): 132class NoGPL3InImagesTests(OESelftestTestCase):
119 def test_core_image_minimal(self): 133 def test_core_image_minimal(self):
120 self.write_config(""" 134 self.write_config("""
121INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0 LGPL-3.0" 135INCOMPATIBLE_LICENSE:pn-core-image-minimal = "GPL-3.0* LGPL-3.0*"
122""") 136""")
123 bitbake('core-image-minimal') 137 bitbake('core-image-minimal')
124 138
125 def test_core_image_full_cmdline_weston(self): 139 def test_core_image_full_cmdline_weston(self):
126 self.write_config(""" 140 self.write_config("""
127INHERIT += "testimage" 141INHERIT += "testimage"
128INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0 LGPL-3.0" 142INCOMPATIBLE_LICENSE:pn-core-image-full-cmdline = "GPL-3.0* LGPL-3.0*"
129INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0 LGPL-3.0" 143INCOMPATIBLE_LICENSE:pn-core-image-weston = "GPL-3.0* LGPL-3.0*"
130# Settings for full-cmdline 144# Settings for full-cmdline
131RDEPENDS:packagegroup-core-full-cmdline-utils:remove = "bash bc coreutils cpio ed findutils gawk grep mc mc-fish mc-helpers mc-helpers-perl sed tar time" 145RDEPENDS:packagegroup-core-full-cmdline-utils:remove = "bash bc coreutils cpio ed findutils gawk grep mc mc-fish mc-helpers mc-helpers-perl sed tar time"
132RDEPENDS:packagegroup-core-full-cmdline-dev-utils:remove = "diffutils m4 make patch" 146RDEPENDS:packagegroup-core-full-cmdline-dev-utils:remove = "diffutils m4 make patch"