diff options
Diffstat (limited to 'meta/lib/oe/license.py')
-rw-r--r-- | meta/lib/oe/license.py | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 665d32ecbb..d9c8d94da4 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py | |||
@@ -1,4 +1,6 @@ | |||
1 | # | 1 | # |
2 | # Copyright OpenEmbedded Contributors | ||
3 | # | ||
2 | # SPDX-License-Identifier: GPL-2.0-only | 4 | # SPDX-License-Identifier: GPL-2.0-only |
3 | # | 5 | # |
4 | """Code for parsing OpenEmbedded license strings""" | 6 | """Code for parsing OpenEmbedded license strings""" |
@@ -14,6 +16,16 @@ def license_ok(license, dont_want_licenses): | |||
14 | return False | 16 | return False |
15 | return True | 17 | return True |
16 | 18 | ||
19 | def obsolete_license_list(): | ||
20 | return ["AGPL-3", "AGPL-3+", "AGPLv3", "AGPLv3+", "AGPLv3.0", "AGPLv3.0+", "AGPL-3.0", "AGPL-3.0+", "BSD-0-Clause", | ||
21 | "GPL-1", "GPL-1+", "GPLv1", "GPLv1+", "GPLv1.0", "GPLv1.0+", "GPL-1.0", "GPL-1.0+", "GPL-2", "GPL-2+", "GPLv2", | ||
22 | "GPLv2+", "GPLv2.0", "GPLv2.0+", "GPL-2.0", "GPL-2.0+", "GPL-3", "GPL-3+", "GPLv3", "GPLv3+", "GPLv3.0", "GPLv3.0+", | ||
23 | "GPL-3.0", "GPL-3.0+", "LGPLv2", "LGPLv2+", "LGPLv2.0", "LGPLv2.0+", "LGPL-2.0", "LGPL-2.0+", "LGPL2.1", "LGPL2.1+", | ||
24 | "LGPLv2.1", "LGPLv2.1+", "LGPL-2.1", "LGPL-2.1+", "LGPLv3", "LGPLv3+", "LGPL-3.0", "LGPL-3.0+", "MPL-1", "MPLv1", | ||
25 | "MPLv1.1", "MPLv2", "MIT-X", "MIT-style", "openssl", "PSF", "PSFv2", "Python-2", "Apachev2", "Apache-2", "Artisticv1", | ||
26 | "Artistic-1", "AFL-2", "AFL-1", "AFLv2", "AFLv1", "CDDLv1", "CDDL-1", "EPLv1.0", "FreeType", "Nauman", | ||
27 | "tcl", "vim", "SGIv1"] | ||
28 | |||
17 | class LicenseError(Exception): | 29 | class LicenseError(Exception): |
18 | pass | 30 | pass |
19 | 31 | ||
@@ -74,6 +86,9 @@ class FlattenVisitor(LicenseVisitor): | |||
74 | def visit_Str(self, node): | 86 | def visit_Str(self, node): |
75 | self.licenses.append(node.s) | 87 | self.licenses.append(node.s) |
76 | 88 | ||
89 | def visit_Constant(self, node): | ||
90 | self.licenses.append(node.value) | ||
91 | |||
77 | def visit_BinOp(self, node): | 92 | def visit_BinOp(self, node): |
78 | if isinstance(node.op, ast.BitOr): | 93 | if isinstance(node.op, ast.BitOr): |
79 | left = FlattenVisitor(self.choose_licenses) | 94 | left = FlattenVisitor(self.choose_licenses) |
@@ -96,26 +111,26 @@ def flattened_licenses(licensestr, choose_licenses): | |||
96 | raise LicenseSyntaxError(licensestr, exc) | 111 | raise LicenseSyntaxError(licensestr, exc) |
97 | return flatten.licenses | 112 | return flatten.licenses |
98 | 113 | ||
99 | def is_included(licensestr, whitelist=None, blacklist=None): | 114 | def is_included(licensestr, include_licenses=None, exclude_licenses=None): |
100 | """Given a license string and whitelist and blacklist, determine if the | 115 | """Given a license string, a list of licenses to include and a list of |
101 | license string matches the whitelist and does not match the blacklist. | 116 | licenses to exclude, determine if the license string matches the include |
117 | list and does not match the exclude list. | ||
102 | 118 | ||
103 | Returns a tuple holding the boolean state and a list of the applicable | 119 | Returns a tuple holding the boolean state and a list of the applicable |
104 | licenses that were excluded if state is False, or the licenses that were | 120 | licenses that were excluded if state is False, or the licenses that were |
105 | included if the state is True. | 121 | included if the state is True.""" |
106 | """ | ||
107 | 122 | ||
108 | def include_license(license): | 123 | def include_license(license): |
109 | return any(fnmatch(license, pattern) for pattern in whitelist) | 124 | return any(fnmatch(license, pattern) for pattern in include_licenses) |
110 | 125 | ||
111 | def exclude_license(license): | 126 | def exclude_license(license): |
112 | return any(fnmatch(license, pattern) for pattern in blacklist) | 127 | return any(fnmatch(license, pattern) for pattern in exclude_licenses) |
113 | 128 | ||
114 | def choose_licenses(alpha, beta): | 129 | def choose_licenses(alpha, beta): |
115 | """Select the option in an OR which is the 'best' (has the most | 130 | """Select the option in an OR which is the 'best' (has the most |
116 | included licenses and no excluded licenses).""" | 131 | included licenses and no excluded licenses).""" |
117 | # The factor 1000 below is arbitrary, just expected to be much larger | 132 | # The factor 1000 below is arbitrary, just expected to be much larger |
118 | # that the number of licenses actually specified. That way the weight | 133 | # than the number of licenses actually specified. That way the weight |
119 | # will be negative if the list of licenses contains an excluded license, | 134 | # will be negative if the list of licenses contains an excluded license, |
120 | # but still gives a higher weight to the list with the most included | 135 | # but still gives a higher weight to the list with the most included |
121 | # licenses. | 136 | # licenses. |
@@ -128,11 +143,11 @@ def is_included(licensestr, whitelist=None, blacklist=None): | |||
128 | else: | 143 | else: |
129 | return beta | 144 | return beta |
130 | 145 | ||
131 | if not whitelist: | 146 | if not include_licenses: |
132 | whitelist = ['*'] | 147 | include_licenses = ['*'] |
133 | 148 | ||
134 | if not blacklist: | 149 | if not exclude_licenses: |
135 | blacklist = [] | 150 | exclude_licenses = [] |
136 | 151 | ||
137 | licenses = flattened_licenses(licensestr, choose_licenses) | 152 | licenses = flattened_licenses(licensestr, choose_licenses) |
138 | excluded = [lic for lic in licenses if exclude_license(lic)] | 153 | excluded = [lic for lic in licenses if exclude_license(lic)] |
@@ -227,6 +242,9 @@ class ListVisitor(LicenseVisitor): | |||
227 | def visit_Str(self, node): | 242 | def visit_Str(self, node): |
228 | self.licenses.add(node.s) | 243 | self.licenses.add(node.s) |
229 | 244 | ||
245 | def visit_Constant(self, node): | ||
246 | self.licenses.add(node.value) | ||
247 | |||
230 | def list_licenses(licensestr): | 248 | def list_licenses(licensestr): |
231 | """Simply get a list of all licenses mentioned in a license string. | 249 | """Simply get a list of all licenses mentioned in a license string. |
232 | Binary operators are not applied or taken into account in any way""" | 250 | Binary operators are not applied or taken into account in any way""" |
@@ -236,3 +254,8 @@ def list_licenses(licensestr): | |||
236 | except SyntaxError as exc: | 254 | except SyntaxError as exc: |
237 | raise LicenseSyntaxError(licensestr, exc) | 255 | raise LicenseSyntaxError(licensestr, exc) |
238 | return visitor.licenses | 256 | return visitor.licenses |
257 | |||
258 | def apply_pkg_license_exception(pkg, bad_licenses, exceptions): | ||
259 | """Return remaining bad licenses after removing any package exceptions""" | ||
260 | |||
261 | return [lic for lic in bad_licenses if pkg + ':' + lic not in exceptions] | ||