mirror of
https://git.yoctoproject.org/poky
synced 2026-06-04 02:00:04 +00:00
base/license.bbclass: handle multiple INCOMPATIBLE_LICENSEs
Allow INCOMPATIBLE_LICENSE to be a whitespace-separated list of incompatible license strings and/or glob patterns. Also fix wildcarding: the string in INCOMPATIBLE_LICENSE was clearly intended to match with wildcards (e.g. "*GPLv3" to match both GPLv3 and LGPLv3), but this was broken because of a bug in return_spdx() which would die with a runtime error when there was no SPDXLICENSEMAP entry for the string. (From OE-Core rev: 8a8d00f4c9f7fe5f9f173b43b86cd18a6c75435c) Signed-off-by: Andy Ross <andy.ross@windriver.com> Signed-off-by: Elizabeth Flanagan <elizabeth.flanagan@intel.com> Signed-off-by: Saul Wold <sgw@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
82d6ef6a7a
commit
ec17940f72
@@ -203,14 +203,11 @@ python do_populate_lic() {
|
||||
|
||||
def return_spdx(d, license):
|
||||
"""
|
||||
This function returns the spdx mapping of a license.
|
||||
"""
|
||||
if d.getVarFlag('SPDXLICENSEMAP', license) != None:
|
||||
return license
|
||||
else:
|
||||
return d.getVarFlag('SPDXLICENSEMAP', license_type)
|
||||
This function returns the spdx mapping of a license if it exists.
|
||||
"""
|
||||
return d.getVarFlag('SPDXLICENSEMAP', license, True)
|
||||
|
||||
def incompatible_license(d, dont_want_license, package=""):
|
||||
def incompatible_license(d, dont_want_licenses, package=None):
|
||||
"""
|
||||
This function checks if a recipe has only incompatible licenses. It also take into consideration 'or'
|
||||
operand.
|
||||
@@ -219,45 +216,30 @@ def incompatible_license(d, dont_want_license, package=""):
|
||||
import oe.license
|
||||
from fnmatch import fnmatchcase as fnmatch
|
||||
pn = d.getVar('PN', True)
|
||||
dont_want_licenses = []
|
||||
dont_want_licenses.append(d.getVar('INCOMPATIBLE_LICENSE', True))
|
||||
recipe_license = d.getVar('LICENSE', True)
|
||||
if package != "":
|
||||
if d.getVar('LICENSE_' + pn + '-' + package, True):
|
||||
license = d.getVar('LICENSE_' + pn + '-' + package, True)
|
||||
else:
|
||||
license = recipe_license
|
||||
else:
|
||||
license = recipe_license
|
||||
spdx_license = return_spdx(d, dont_want_license)
|
||||
dont_want_licenses.append(spdx_license)
|
||||
license = d.getVar("LICENSE_%s-%s" % (pn, package), True) if package else None
|
||||
if not license:
|
||||
license = d.getVar('LICENSE', True)
|
||||
|
||||
def include_license(license):
|
||||
if any(fnmatch(license, pattern) for pattern in dont_want_licenses):
|
||||
def license_ok(license):
|
||||
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('\+$', dwl):
|
||||
lic = re.sub('\+', '', license)
|
||||
if fnmatch(lic, dwl):
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
return True
|
||||
|
||||
def choose_licenses(a, b):
|
||||
if all(include_license(lic) for lic in a):
|
||||
return a
|
||||
else:
|
||||
return b
|
||||
# Handles an "or" or two license sets provided by
|
||||
# flattened_licenses(), pick one that works if possible.
|
||||
def choose_lic_set(a, b):
|
||||
return a if all(license_ok(lic) for lic in a) else b
|
||||
|
||||
"""
|
||||
If you want to exlude license named generically 'X', we surely want to exlude 'X+' as well.
|
||||
In consequence, we will exclude the '+' character from LICENSE in case INCOMPATIBLE_LICENSE
|
||||
is not a 'X+' license.
|
||||
"""
|
||||
if not re.search(r'[+]',dont_want_license):
|
||||
licenses=oe.license.flattened_licenses(re.sub(r'[+]', '', license), choose_licenses)
|
||||
else:
|
||||
licenses=oe.license.flattened_licenses(license, choose_licenses)
|
||||
|
||||
for onelicense in licenses:
|
||||
if not include_license(onelicense):
|
||||
return True
|
||||
return False
|
||||
licenses=oe.license.flattened_licenses(license, choose_lic_set)
|
||||
return any(not license_ok(l) for l in licenses)
|
||||
|
||||
def check_license_flags(d):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user