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:
parent
82d6ef6a7a
commit
ec17940f72
|
@ -525,43 +525,44 @@ python () {
|
||||||
raise bb.parse.SkipPackage("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % this_machine)
|
raise bb.parse.SkipPackage("incompatible with machine %s (not in COMPATIBLE_MACHINE)" % this_machine)
|
||||||
|
|
||||||
|
|
||||||
dont_want_license = d.getVar('INCOMPATIBLE_LICENSE', True)
|
bad_licenses = (d.getVar('INCOMPATIBLE_LICENSE', True) or "").split()
|
||||||
|
|
||||||
if dont_want_license and not pn.endswith("-native") and not pn.endswith("-cross") and not pn.endswith("-cross-initial") and not pn.endswith("-cross-intermediate") and not pn.endswith("-crosssdk-intermediate") and not pn.endswith("-crosssdk") and not pn.endswith("-crosssdk-initial") and not pn.endswith("-cross-canadian-%s" % d.getVar('TRANSLATED_TARGET_ARCH', True)) and not pn.startswith("nativesdk-"):
|
check_license = False if pn.startswith("nativesdk-") else True
|
||||||
# Internally, we'll use the license mapping. This way INCOMPATIBLE_LICENSE = "GPLv2" and
|
for t in ["-native", "-cross", "-cross-initial", "-cross-intermediate",
|
||||||
# INCOMPATIBLE_LICENSE = "GPLv2.0" will pick up all variations of GPL-2.0
|
"-crosssdk-intermediate", "-crosssdk", "-crosssdk-initial",
|
||||||
spdx_license = return_spdx(d, dont_want_license)
|
"-cross-canadian-" + d.getVar('TRANSLATED_TARGET_ARCH', True)]:
|
||||||
hosttools_whitelist = (d.getVar('HOSTTOOLS_WHITELIST_%s' % dont_want_license, True) or d.getVar('HOSTTOOLS_WHITELIST_%s' % spdx_license, True) or "").split()
|
if pn.endswith(t):
|
||||||
lgplv2_whitelist = (d.getVar('LGPLv2_WHITELIST_%s' % dont_want_license, True) or d.getVar('HOSTTOOLS_WHITELIST_%s' % spdx_license, True) or "").split()
|
check_license = False
|
||||||
dont_want_whitelist = (d.getVar('WHITELIST_%s' % dont_want_license, True) or d.getVar('HOSTTOOLS_WHITELIST_%s' % spdx_license, True) or "").split()
|
|
||||||
if pn not in hosttools_whitelist and pn not in lgplv2_whitelist and pn not in dont_want_whitelist:
|
if check_license and bad_licenses:
|
||||||
this_license = d.getVar('LICENSE', True)
|
whitelist = []
|
||||||
# At this point we know the recipe contains an INCOMPATIBLE_LICENSE, however it may contain packages that do not.
|
for lic in bad_licenses:
|
||||||
packages = d.getVar('PACKAGES', True).split()
|
for w in ["HOSTTOOLS_WHITELIST_", "LGPLv2_WHITELIST_", "WHITELIST_"]:
|
||||||
dont_skip_recipe = False
|
whitelist.extend((d.getVar(w + lic, True) or "").split())
|
||||||
skipped_packages = {}
|
spdx_license = return_spdx(d, lic)
|
||||||
unskipped_packages = []
|
if spdx_license:
|
||||||
for pkg in packages:
|
whitelist.extend((d.getVar('HOSTTOOLS_WHITELIST_%s' % spdx_license, True) or "").split())
|
||||||
if incompatible_license(d, dont_want_license, pkg):
|
if not pn in whitelist:
|
||||||
skipped_packages[pkg] = this_license
|
recipe_license = d.getVar('LICENSE', True)
|
||||||
dont_skip_recipe = True
|
pkgs = d.getVar('PACKAGES', True).split()
|
||||||
|
skipped_pkgs = []
|
||||||
|
unskipped_pkgs = []
|
||||||
|
for pkg in pkgs:
|
||||||
|
if incompatible_license(d, bad_licenses, pkg):
|
||||||
|
skipped_pkgs.append(pkg)
|
||||||
else:
|
else:
|
||||||
unskipped_packages.append(pkg)
|
unskipped_pkgs.append(pkg)
|
||||||
if not unskipped_packages:
|
some_skipped = skipped_pkgs and unskipped_pkgs
|
||||||
# if we hit here and have excluded all packages, then we can just exclude the recipe
|
all_skipped = skipped_pkgs and not unskipped_pkgs
|
||||||
dont_skip_recipe = False
|
if some_skipped:
|
||||||
elif skipped_packages and unskipped_packages:
|
for pkg in skipped_pkgs:
|
||||||
for pkg, license in skipped_packages.iteritems():
|
bb.note("SKIPPING the package " + pkg + " at do_rootfs because it's " + recipe_license)
|
||||||
bb.note("SKIPPING the package " + pkg + " at do_rootfs because it's " + this_license)
|
|
||||||
d.setVar('LICENSE_EXCLUSION-' + pkg, 1)
|
d.setVar('LICENSE_EXCLUSION-' + pkg, 1)
|
||||||
for index, pkg in enumerate(unskipped_packages):
|
for pkg in unskipped_pkgs:
|
||||||
bb.note("INCLUDING the package " + pkg)
|
bb.note("INCLUDING the package " + pkg)
|
||||||
|
elif all_skipped or incompatible_license(d, bad_licenses):
|
||||||
if dont_skip_recipe is False and incompatible_license(d, dont_want_license):
|
bb.note("SKIPPING recipe %s because it's %s" % (pn, recipe_license))
|
||||||
bb.note("SKIPPING recipe %s because it's %s" % (pn, this_license))
|
raise bb.parse.SkipPackage("incompatible with license %s" % recipe_license)
|
||||||
raise bb.parse.SkipPackage("incompatible with license %s" % this_license)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
srcuri = d.getVar('SRC_URI', True)
|
srcuri = d.getVar('SRC_URI', True)
|
||||||
# Svn packages should DEPEND on subversion-native
|
# Svn packages should DEPEND on subversion-native
|
||||||
|
|
|
@ -203,14 +203,11 @@ python do_populate_lic() {
|
||||||
|
|
||||||
def return_spdx(d, license):
|
def return_spdx(d, license):
|
||||||
"""
|
"""
|
||||||
This function returns the spdx mapping of a license.
|
This function returns the spdx mapping of a license if it exists.
|
||||||
"""
|
"""
|
||||||
if d.getVarFlag('SPDXLICENSEMAP', license) != None:
|
return d.getVarFlag('SPDXLICENSEMAP', license, True)
|
||||||
return license
|
|
||||||
else:
|
|
||||||
return d.getVarFlag('SPDXLICENSEMAP', license_type)
|
|
||||||
|
|
||||||
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'
|
This function checks if a recipe has only incompatible licenses. It also take into consideration 'or'
|
||||||
operand.
|
operand.
|
||||||
|
@ -219,45 +216,30 @@ def incompatible_license(d, dont_want_license, package=""):
|
||||||
import oe.license
|
import oe.license
|
||||||
from fnmatch import fnmatchcase as fnmatch
|
from fnmatch import fnmatchcase as fnmatch
|
||||||
pn = d.getVar('PN', True)
|
pn = d.getVar('PN', True)
|
||||||
dont_want_licenses = []
|
license = d.getVar("LICENSE_%s-%s" % (pn, package), True) if package else None
|
||||||
dont_want_licenses.append(d.getVar('INCOMPATIBLE_LICENSE', True))
|
if not license:
|
||||||
recipe_license = d.getVar('LICENSE', True)
|
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)
|
|
||||||
|
|
||||||
def include_license(license):
|
def license_ok(license):
|
||||||
if any(fnmatch(license, pattern) for pattern in dont_want_licenses):
|
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
|
return False
|
||||||
else:
|
return True
|
||||||
return True
|
|
||||||
|
|
||||||
def choose_licenses(a, b):
|
# Handles an "or" or two license sets provided by
|
||||||
if all(include_license(lic) for lic in a):
|
# flattened_licenses(), pick one that works if possible.
|
||||||
return a
|
def choose_lic_set(a, b):
|
||||||
else:
|
return a if all(license_ok(lic) for lic in a) else b
|
||||||
return b
|
|
||||||
|
|
||||||
"""
|
licenses=oe.license.flattened_licenses(license, choose_lic_set)
|
||||||
If you want to exlude license named generically 'X', we surely want to exlude 'X+' as well.
|
return any(not license_ok(l) for l in licenses)
|
||||||
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
|
|
||||||
|
|
||||||
def check_license_flags(d):
|
def check_license_flags(d):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue