blob: 83cd90060d71972c3de9488a2a85929e405157e7 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007# 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 Williamsc124f4f2015-09-15 14:41:29 -050012
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013COPYLEFT_LICENSE_INCLUDE ?= 'GPL* LGPL* AGPL*'
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014COPYLEFT_LICENSE_INCLUDE[type] = 'list'
15COPYLEFT_LICENSE_INCLUDE[doc] = 'Space separated list of globs which include licenses'
16
17COPYLEFT_LICENSE_EXCLUDE ?= 'CLOSED Proprietary'
18COPYLEFT_LICENSE_EXCLUDE[type] = 'list'
19COPYLEFT_LICENSE_EXCLUDE[doc] = 'Space separated list of globs which exclude licenses'
20
21COPYLEFT_RECIPE_TYPE ?= '${@copyleft_recipe_type(d)}'
22COPYLEFT_RECIPE_TYPE[doc] = 'The "type" of the current recipe (e.g. target, native, cross)'
23
24COPYLEFT_RECIPE_TYPES ?= 'target'
25COPYLEFT_RECIPE_TYPES[type] = 'list'
26COPYLEFT_RECIPE_TYPES[doc] = 'Space separated list of recipe types to include'
27
28COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-canadian'
29COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list'
30COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types'
31
32COPYLEFT_PN_INCLUDE ?= ''
33COPYLEFT_PN_INCLUDE[type] = 'list'
34COPYLEFT_PN_INCLUDE[doc] = 'Space separated list of recipe names to include'
35
36COPYLEFT_PN_EXCLUDE ?= ''
37COPYLEFT_PN_EXCLUDE[type] = 'list'
38COPYLEFT_PN_EXCLUDE[doc] = 'Space separated list of recipe names to exclude'
39
40def 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
46def 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 Bishop6e60e8b2018-02-01 10:27:11 -050054 recipe_type = d.getVar('COPYLEFT_RECIPE_TYPE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050055 if recipe_type not in oe.data.typed_value('COPYLEFT_RECIPE_TYPES', d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 included, motive = False, 'recipe type "%s" is excluded' % recipe_type
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 included, motive = False, 'recipe did not match anything'
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 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 Williamsc124f4f2015-09-15 14:41:29 -050077 for name in oe.data.typed_value('COPYLEFT_PN_INCLUDE', d)):
78 included, motive = True, 'recipe included by name'
Brad Bishop6e60e8b2018-02-01 10:27:11 -050079 if any(fnmatch(d.getVar('PN'), name) \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050080 for name in oe.data.typed_value('COPYLEFT_PN_EXCLUDE', d)):
81 included, motive = False, 'recipe excluded by name'
82
83 return included, motive