1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-04 02:00:04 +00:00

license: Add support for handle INCOMPATIBLE_LICENSE in manifest creation

When INCOMPATIBLE_LICENSE's is specified it need to be removed from
license.manifest and also avoid copy to target image.

Add ManifestVisitor that walk the license string searching for
INCOMPATIBLE_LICENSE's if found remove it.

[YOCTO #6765]

(From OE-Core rev: d1278570041029d7c9fc6ce657e9a1701a421841)

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Aníbal Limón
2015-05-08 20:41:31 +00:00
committed by Richard Purdie
parent bb3469f9d3
commit b394cd4c7e
2 changed files with 103 additions and 3 deletions
+77
View File
@@ -138,3 +138,80 @@ def is_included(licensestr, whitelist=None, blacklist=None):
return False, excluded
else:
return True, included
class ManifestVisitor(LicenseVisitor):
"""Walk license tree (parsed from a string) removing the incompatible
licenses specified"""
def __init__(self, dont_want_licenses, canonical_license, d):
self._dont_want_licenses = dont_want_licenses
self._canonical_license = canonical_license
self._d = d
self._operators = []
self.licenses = []
self.licensestr = ''
LicenseVisitor.__init__(self)
def visit(self, node):
if isinstance(node, ast.Str):
lic = node.s
if license_ok(self._canonical_license(self._d, lic),
self._dont_want_licenses) == True:
if self._operators:
ops = []
for op in self._operators:
if op == '[':
ops.append(op)
elif op == ']':
ops.append(op)
else:
if not ops:
ops.append(op)
elif ops[-1] in ['[', ']']:
ops.append(op)
else:
ops[-1] = op
for op in ops:
if op == '[' or op == ']':
self.licensestr += op
elif self.licenses:
self.licensestr += ' ' + op + ' '
self._operators = []
self.licensestr += lic
self.licenses.append(lic)
elif isinstance(node, ast.BitAnd):
self._operators.append("&")
elif isinstance(node, ast.BitOr):
self._operators.append("|")
elif isinstance(node, ast.List):
self._operators.append("[")
elif isinstance(node, ast.Load):
self.licensestr += "]"
self.generic_visit(node)
def manifest_licenses(licensestr, dont_want_licenses, canonical_license, d):
"""Given a license string and dont_want_licenses list,
return license string filtered and a list of licenses"""
manifest = ManifestVisitor(dont_want_licenses, canonical_license, d)
try:
elements = manifest.get_elements(licensestr)
# Replace '()' to '[]' for handle in ast as List and Load types.
elements = ['[' if e == '(' else e for e in elements]
elements = [']' if e == ')' else e for e in elements]
manifest.visit_elements(elements)
except SyntaxError as exc:
raise LicenseSyntaxError(licensestr, exc)
# Replace '[]' to '()' for output correct license.
manifest.licensestr = manifest.licensestr.replace('[', '(').replace(']', ')')
return (manifest.licensestr, manifest.licenses)