summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/license.py
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2015-05-08 20:41:31 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-05-09 22:28:14 +0100
commitb394cd4c7e1997f3df4a0c796446b48dd7fe2c07 (patch)
treed2a264a4c4ce5757e4f981153a7667caaa0089d1 /meta/lib/oe/license.py
parentbb3469f9d32ff18cf308a308869c0ae3500b5a15 (diff)
downloadpoky-b394cd4c7e1997f3df4a0c796446b48dd7fe2c07.tar.gz
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>
Diffstat (limited to 'meta/lib/oe/license.py')
-rw-r--r--meta/lib/oe/license.py77
1 files changed, 77 insertions, 0 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py
index 254279db53..f0f661c3ba 100644
--- a/meta/lib/oe/license.py
+++ b/meta/lib/oe/license.py
@@ -138,3 +138,80 @@ def is_included(licensestr, whitelist=None, blacklist=None):
138 return False, excluded 138 return False, excluded
139 else: 139 else:
140 return True, included 140 return True, included
141
142class ManifestVisitor(LicenseVisitor):
143 """Walk license tree (parsed from a string) removing the incompatible
144 licenses specified"""
145 def __init__(self, dont_want_licenses, canonical_license, d):
146 self._dont_want_licenses = dont_want_licenses
147 self._canonical_license = canonical_license
148 self._d = d
149 self._operators = []
150
151 self.licenses = []
152 self.licensestr = ''
153
154 LicenseVisitor.__init__(self)
155
156 def visit(self, node):
157 if isinstance(node, ast.Str):
158 lic = node.s
159
160 if license_ok(self._canonical_license(self._d, lic),
161 self._dont_want_licenses) == True:
162 if self._operators:
163 ops = []
164 for op in self._operators:
165 if op == '[':
166 ops.append(op)
167 elif op == ']':
168 ops.append(op)
169 else:
170 if not ops:
171 ops.append(op)
172 elif ops[-1] in ['[', ']']:
173 ops.append(op)
174 else:
175 ops[-1] = op
176
177 for op in ops:
178 if op == '[' or op == ']':
179 self.licensestr += op
180 elif self.licenses:
181 self.licensestr += ' ' + op + ' '
182
183 self._operators = []
184
185 self.licensestr += lic
186 self.licenses.append(lic)
187 elif isinstance(node, ast.BitAnd):
188 self._operators.append("&")
189 elif isinstance(node, ast.BitOr):
190 self._operators.append("|")
191 elif isinstance(node, ast.List):
192 self._operators.append("[")
193 elif isinstance(node, ast.Load):
194 self.licensestr += "]"
195
196 self.generic_visit(node)
197
198def manifest_licenses(licensestr, dont_want_licenses, canonical_license, d):
199 """Given a license string and dont_want_licenses list,
200 return license string filtered and a list of licenses"""
201 manifest = ManifestVisitor(dont_want_licenses, canonical_license, d)
202
203 try:
204 elements = manifest.get_elements(licensestr)
205
206 # Replace '()' to '[]' for handle in ast as List and Load types.
207 elements = ['[' if e == '(' else e for e in elements]
208 elements = [']' if e == ')' else e for e in elements]
209
210 manifest.visit_elements(elements)
211 except SyntaxError as exc:
212 raise LicenseSyntaxError(licensestr, exc)
213
214 # Replace '[]' to '()' for output correct license.
215 manifest.licensestr = manifest.licensestr.replace('[', '(').replace(']', ')')
216
217 return (manifest.licensestr, manifest.licenses)