Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # Filter the license, the copyleft_should_include returns True for the |
| 8 | # COPYLEFT_LICENSE_INCLUDE recipe, and False for the |
| 9 | # COPYLEFT_LICENSE_EXCLUDE. |
| 10 | # |
| 11 | # By default, includes all GPL and LGPL, and excludes CLOSED and Proprietary. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | COPYLEFT_LICENSE_INCLUDE ?= 'GPL* LGPL* AGPL*' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 14 | COPYLEFT_LICENSE_INCLUDE[type] = 'list' |
| 15 | COPYLEFT_LICENSE_INCLUDE[doc] = 'Space separated list of globs which include licenses' |
| 16 | |
| 17 | COPYLEFT_LICENSE_EXCLUDE ?= 'CLOSED Proprietary' |
| 18 | COPYLEFT_LICENSE_EXCLUDE[type] = 'list' |
| 19 | COPYLEFT_LICENSE_EXCLUDE[doc] = 'Space separated list of globs which exclude licenses' |
| 20 | |
| 21 | COPYLEFT_RECIPE_TYPE ?= '${@copyleft_recipe_type(d)}' |
| 22 | COPYLEFT_RECIPE_TYPE[doc] = 'The "type" of the current recipe (e.g. target, native, cross)' |
| 23 | |
| 24 | COPYLEFT_RECIPE_TYPES ?= 'target' |
| 25 | COPYLEFT_RECIPE_TYPES[type] = 'list' |
| 26 | COPYLEFT_RECIPE_TYPES[doc] = 'Space separated list of recipe types to include' |
| 27 | |
| 28 | COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-canadian' |
| 29 | COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list' |
| 30 | COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types' |
| 31 | |
| 32 | COPYLEFT_PN_INCLUDE ?= '' |
| 33 | COPYLEFT_PN_INCLUDE[type] = 'list' |
| 34 | COPYLEFT_PN_INCLUDE[doc] = 'Space separated list of recipe names to include' |
| 35 | |
| 36 | COPYLEFT_PN_EXCLUDE ?= '' |
| 37 | COPYLEFT_PN_EXCLUDE[type] = 'list' |
| 38 | COPYLEFT_PN_EXCLUDE[doc] = 'Space separated list of recipe names to exclude' |
| 39 | |
| 40 | def copyleft_recipe_type(d): |
| 41 | for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d): |
| 42 | if oe.utils.inherits(d, recipe_type): |
| 43 | return recipe_type |
| 44 | return 'target' |
| 45 | |
| 46 | def copyleft_should_include(d): |
| 47 | """ |
| 48 | Determine if this recipe's sources should be deployed for compliance |
| 49 | """ |
| 50 | import ast |
| 51 | import oe.license |
| 52 | from fnmatch import fnmatchcase as fnmatch |
| 53 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | recipe_type = d.getVar('COPYLEFT_RECIPE_TYPE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | if recipe_type not in oe.data.typed_value('COPYLEFT_RECIPE_TYPES', d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | included, motive = False, 'recipe type "%s" is excluded' % recipe_type |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | included, motive = False, 'recipe did not match anything' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | include = oe.data.typed_value('COPYLEFT_LICENSE_INCLUDE', d) |
| 61 | exclude = oe.data.typed_value('COPYLEFT_LICENSE_EXCLUDE', d) |
| 62 | |
| 63 | try: |
| 64 | is_included, reason = oe.license.is_included(d.getVar('LICENSE'), include, exclude) |
| 65 | except oe.license.LicenseError as exc: |
| 66 | bb.fatal('%s: %s' % (d.getVar('PF'), exc)) |
| 67 | else: |
| 68 | if is_included: |
| 69 | if reason: |
| 70 | included, motive = True, 'recipe has included licenses: %s' % ', '.join(reason) |
| 71 | else: |
| 72 | included, motive = False, 'recipe does not include a copyleft license' |
| 73 | else: |
| 74 | included, motive = False, 'recipe has excluded licenses: %s' % ', '.join(reason) |
| 75 | |
| 76 | if any(fnmatch(d.getVar('PN'), name) \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | for name in oe.data.typed_value('COPYLEFT_PN_INCLUDE', d)): |
| 78 | included, motive = True, 'recipe included by name' |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 79 | if any(fnmatch(d.getVar('PN'), name) \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 80 | for name in oe.data.typed_value('COPYLEFT_PN_EXCLUDE', d)): |
| 81 | included, motive = False, 'recipe excluded by name' |
| 82 | |
| 83 | return included, motive |