diff options
-rw-r--r-- | meta/classes/license.bbclass | 29 | ||||
-rw-r--r-- | meta/lib/oe/license.py | 77 |
2 files changed, 103 insertions, 3 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass index 780b9d5863..54ab123840 100644 --- a/meta/classes/license.bbclass +++ b/meta/classes/license.bbclass | |||
@@ -29,6 +29,10 @@ python license_create_manifest() { | |||
29 | import re | 29 | import re |
30 | import oe.packagedata | 30 | import oe.packagedata |
31 | 31 | ||
32 | bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split() | ||
33 | bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses) | ||
34 | bad_licenses = expand_wildcard_licenses(d, bad_licenses) | ||
35 | |||
32 | build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True) | 36 | build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True) |
33 | if build_images_from_feeds == "1": | 37 | if build_images_from_feeds == "1": |
34 | return 0 | 38 | return 0 |
@@ -52,6 +56,18 @@ python license_create_manifest() { | |||
52 | d.getVar('IMAGE_NAME', True), 'license.manifest') | 56 | d.getVar('IMAGE_NAME', True), 'license.manifest') |
53 | with open(license_manifest, "w") as license_file: | 57 | with open(license_manifest, "w") as license_file: |
54 | for pkg in sorted(pkg_dic): | 58 | for pkg in sorted(pkg_dic): |
59 | if bad_licenses: | ||
60 | try: | ||
61 | (pkg_dic[pkg]["LICENSE"], pkg_dic[pkg]["LICENSES"]) = \ | ||
62 | oe.license.manifest_licenses(pkg_dic[pkg]["LICENSE"], | ||
63 | bad_licenses, canonical_license, d) | ||
64 | except oe.license.LicenseError as exc: | ||
65 | bb.fatal('%s: %s' % (d.getVar('P', True), exc)) | ||
66 | else: | ||
67 | pkg_dic[pkg]["LICENSES"] = re.sub('[|&()*]', '', pkg_dic[pkg]["LICENSE"]) | ||
68 | pkg_dic[pkg]["LICENSES"] = re.sub(' *', ' ', pkg_dic[pkg]["LICENSES"]) | ||
69 | pkg_dic[pkg]["LICENSES"] = pkg_dic[pkg]["LICENSES"].split() | ||
70 | |||
55 | license_file.write("PACKAGE NAME: %s\n" % pkg) | 71 | license_file.write("PACKAGE NAME: %s\n" % pkg) |
56 | license_file.write("PACKAGE VERSION: %s\n" % pkg_dic[pkg]["PV"]) | 72 | license_file.write("PACKAGE VERSION: %s\n" % pkg_dic[pkg]["PV"]) |
57 | license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"]) | 73 | license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"]) |
@@ -63,9 +79,7 @@ python license_create_manifest() { | |||
63 | if pkg_dic[pkg]["PKGSIZE_%s" % pkg] == "0": | 79 | if pkg_dic[pkg]["PKGSIZE_%s" % pkg] == "0": |
64 | continue | 80 | continue |
65 | 81 | ||
66 | licenses = re.sub('[|&()*]', '', pkg_dic[pkg]["LICENSE"]) | 82 | for lic in pkg_dic[pkg]["LICENSES"]: |
67 | licenses = re.sub(' *', ' ', licenses) | ||
68 | for lic in licenses.split(): | ||
69 | lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True), | 83 | lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True), |
70 | pkg_dic[pkg]["PN"], "generic_%s" % | 84 | pkg_dic[pkg]["PN"], "generic_%s" % |
71 | re.sub('\+', '', lic)) | 85 | re.sub('\+', '', lic)) |
@@ -101,11 +115,20 @@ python license_create_manifest() { | |||
101 | pkg_rootfs_license = os.path.join(pkg_rootfs_license_dir, lic) | 115 | pkg_rootfs_license = os.path.join(pkg_rootfs_license_dir, lic) |
102 | 116 | ||
103 | if re.match("^generic_.*$", lic): | 117 | if re.match("^generic_.*$", lic): |
118 | generic_lic = re.search("^generic_(.*)$", lic).group(1) | ||
119 | if oe.license.license_ok(canonical_license(d, | ||
120 | generic_lic), bad_licenses) == False: | ||
121 | continue | ||
122 | |||
104 | if not os.path.exists(rootfs_license): | 123 | if not os.path.exists(rootfs_license): |
105 | os.link(pkg_license, rootfs_license) | 124 | os.link(pkg_license, rootfs_license) |
106 | 125 | ||
107 | os.symlink(os.path.join('..', lic), pkg_rootfs_license) | 126 | os.symlink(os.path.join('..', lic), pkg_rootfs_license) |
108 | else: | 127 | else: |
128 | if oe.license.license_ok(canonical_license(d, | ||
129 | lic), bad_licenses) == False: | ||
130 | continue | ||
131 | |||
109 | os.link(pkg_license, pkg_rootfs_license) | 132 | os.link(pkg_license, pkg_rootfs_license) |
110 | } | 133 | } |
111 | 134 | ||
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 | |||
142 | class 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 | |||
198 | def 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) | ||