Skip to contentSkip to conversation

licenses: Fix canonical license for 'or-later' handling

PATCH New Richard Purdie 1 participant 2 messages Feb 19, 2021

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 licenses: Fix canonical license for 'or-later' handling

GPLv2 and GPLv2+ are two difference licenses with different meanings and we can't just pretend they're the same thing. Change the code to treat them separately.

---
 meta/classes/license.bbclass | 11 ++---------
 meta/lib/oe/license.py       |  9 +--------
 2 files changed, 3 insertions(+), 17 deletions(-)
meta/classes/license.bbclass +2 -9
index dc91118340d..358c716a801 100644
@@ -252,16 +252,9 @@ def return_spdx(d, license):
 def canonical_license(d, license):
     """
     Return the canonical (SPDX) form of the license if available (so GPLv3
-    becomes GPL-3.0), for the license named 'X+', return canonical form of
-    'X' if available and the tailing '+' (so GPLv3+ becomes GPL-3.0+),
-    or the passed license if there is no canonical form.
+    becomes GPL-3.0) or the passed license if there is no canonical form.
     """
-    lic = d.getVarFlag('SPDXLICENSEMAP', license) or ""
-    if not lic and license.endswith('+'):
-        lic = d.getVarFlag('SPDXLICENSEMAP', license.rstrip('+'))
-        if lic:
-            lic += '+'
-    return lic or license
+    return d.getVarFlag('SPDXLICENSEMAP', license) or license
 
 def available_licenses(d):
     """
meta/lib/oe/license.py +1 -8
index c1274a61dec..665d32ecbb1 100644
@@ -10,14 +10,7 @@ from fnmatch import fnmatchcase as fnmatch
 def license_ok(license, dont_want_licenses):
     """ Return False if License exist in dont_want_licenses else True """
     for dwl in dont_want_licenses:
-        # If you want to exclude license named generically 'X', we
-        # surely want to exclude 'X+' as well.  In consequence, we
-        # will exclude a trailing '+' character from LICENSE in
-        # case INCOMPATIBLE_LICENSE is not a 'X+' license.
-        lic = license
-        if not re.search(r'\+$', dwl):
-            lic = re.sub(r'\+', '', license)
-        if fnmatch(lic, dwl):
+        if fnmatch(license, dwl):
             return False
     return True
 
Signature · 1 line
2.27.0
#1 lore raw

PATCH v2 2/2 licenses: Update INCOMPATIBLE_LICENSE for 'or-later' handling

Where a user adds "GPLv3" to INCOMPATIBLE_LICENSE they almost certainly mean both GPLv3-only and GPLv3-or-later. Update the code to handle this correctly.

---
 meta/classes/license.bbclass | 6 ++++++
 1 file changed, 6 insertions(+)
meta/classes/license.bbclass +6 -0
index 358c716a801..bcea0b3cb53 100644
@@ -281,6 +281,12 @@ def expand_wildcard_licenses(d, wildcard_licenses):
     wildcards from SPDXLICENSEMAP flags and AVAILABLE_LICENSES.
     """
     import fnmatch
+
+    # Assume if we're passed "GPLv3" or "*GPLv3" it means -or-later as well
+    for lic in wildcard_licenses[:]:
+        if not lic.endswith(("-or-later", "-only", "*")):
+            wildcard_licenses.append(lic + "+")
+
     licenses = wildcard_licenses[:]
     spdxmapkeys = d.getVarFlags('SPDXLICENSEMAP').keys()
     for wld_lic in wildcard_licenses:
Signature · 1 line
2.27.0