diff options
| -rw-r--r-- | meta/classes/license.bbclass | 21 | ||||
| -rw-r--r-- | meta/lib/oe/license.py | 14 |
2 files changed, 18 insertions, 17 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass index 975867d241..780b9d5863 100644 --- a/meta/classes/license.bbclass +++ b/meta/classes/license.bbclass | |||
| @@ -341,36 +341,23 @@ def incompatible_license(d, dont_want_licenses, package=None): | |||
| 341 | take into consideration 'or' operand. dont_want_licenses should be passed | 341 | take into consideration 'or' operand. dont_want_licenses should be passed |
| 342 | as canonical (SPDX) names. | 342 | as canonical (SPDX) names. |
| 343 | """ | 343 | """ |
| 344 | import re | ||
| 345 | import oe.license | 344 | import oe.license |
| 346 | from fnmatch import fnmatchcase as fnmatch | ||
| 347 | license = d.getVar("LICENSE_%s" % package, True) if package else None | 345 | license = d.getVar("LICENSE_%s" % package, True) if package else None |
| 348 | if not license: | 346 | if not license: |
| 349 | license = d.getVar('LICENSE', True) | 347 | license = d.getVar('LICENSE', True) |
| 350 | 348 | ||
| 351 | def license_ok(license): | ||
| 352 | for dwl in dont_want_licenses: | ||
| 353 | # If you want to exclude license named generically 'X', we | ||
| 354 | # surely want to exclude 'X+' as well. In consequence, we | ||
| 355 | # will exclude a trailing '+' character from LICENSE in | ||
| 356 | # case INCOMPATIBLE_LICENSE is not a 'X+' license. | ||
| 357 | lic = license | ||
| 358 | if not re.search('\+$', dwl): | ||
| 359 | lic = re.sub('\+', '', license) | ||
| 360 | if fnmatch(lic, dwl): | ||
| 361 | return False | ||
| 362 | return True | ||
| 363 | |||
| 364 | # Handles an "or" or two license sets provided by | 349 | # Handles an "or" or two license sets provided by |
| 365 | # flattened_licenses(), pick one that works if possible. | 350 | # flattened_licenses(), pick one that works if possible. |
| 366 | def choose_lic_set(a, b): | 351 | def choose_lic_set(a, b): |
| 367 | return a if all(license_ok(lic) for lic in a) else b | 352 | return a if all(oe.license.license_ok(lic, dont_want_licenses) \ |
| 353 | for lic in a) else b | ||
| 368 | 354 | ||
| 369 | try: | 355 | try: |
| 370 | licenses = oe.license.flattened_licenses(license, choose_lic_set) | 356 | licenses = oe.license.flattened_licenses(license, choose_lic_set) |
| 371 | except oe.license.LicenseError as exc: | 357 | except oe.license.LicenseError as exc: |
| 372 | bb.fatal('%s: %s' % (d.getVar('P', True), exc)) | 358 | bb.fatal('%s: %s' % (d.getVar('P', True), exc)) |
| 373 | return any(not license_ok(canonical_license(d, l)) for l in licenses) | 359 | return any(not oe.license.license_ok(canonical_license(d, l), \ |
| 360 | dont_want_licenses) for l in licenses) | ||
| 374 | 361 | ||
| 375 | def check_license_flags(d): | 362 | def check_license_flags(d): |
| 376 | """ | 363 | """ |
diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 31ca15b574..bc146a28c4 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py | |||
| @@ -5,6 +5,20 @@ import ast | |||
| 5 | import re | 5 | import re |
| 6 | from fnmatch import fnmatchcase as fnmatch | 6 | from fnmatch import fnmatchcase as fnmatch |
| 7 | 7 | ||
| 8 | def license_ok(license, dont_want_licenses): | ||
| 9 | """ Return False if License exist in dont_want_licenses else True """ | ||
| 10 | for dwl in dont_want_licenses: | ||
| 11 | # If you want to exclude license named generically 'X', we | ||
| 12 | # surely want to exclude 'X+' as well. In consequence, we | ||
| 13 | # will exclude a trailing '+' character from LICENSE in | ||
| 14 | # case INCOMPATIBLE_LICENSE is not a 'X+' license. | ||
| 15 | lic = license | ||
| 16 | if not re.search('\+$', dwl): | ||
| 17 | lic = re.sub('\+', '', license) | ||
| 18 | if fnmatch(lic, dwl): | ||
| 19 | return False | ||
| 20 | return True | ||
| 21 | |||
| 8 | class LicenseError(Exception): | 22 | class LicenseError(Exception): |
| 9 | pass | 23 | pass |
| 10 | 24 | ||
