diff options
Diffstat (limited to 'meta/classes/copyleft_filter.bbclass')
-rw-r--r-- | meta/classes/copyleft_filter.bbclass | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/meta/classes/copyleft_filter.bbclass b/meta/classes/copyleft_filter.bbclass new file mode 100644 index 0000000000..2c1d8f1c90 --- /dev/null +++ b/meta/classes/copyleft_filter.bbclass | |||
@@ -0,0 +1,62 @@ | |||
1 | # Filter the license, the copyleft_should_include returns True for the | ||
2 | # COPYLEFT_LICENSE_INCLUDE recipe, and False for the | ||
3 | # COPYLEFT_LICENSE_EXCLUDE. | ||
4 | # | ||
5 | # By default, includes all GPL and LGPL, and excludes CLOSED and Proprietary. | ||
6 | # | ||
7 | # vi:sts=4:sw=4:et | ||
8 | |||
9 | COPYLEFT_LICENSE_INCLUDE ?= 'GPL* LGPL*' | ||
10 | COPYLEFT_LICENSE_INCLUDE[type] = 'list' | ||
11 | COPYLEFT_LICENSE_INCLUDE[doc] = 'Space separated list of globs which include licenses' | ||
12 | |||
13 | COPYLEFT_LICENSE_EXCLUDE ?= 'CLOSED Proprietary' | ||
14 | COPYLEFT_LICENSE_EXCLUDE[type] = 'list' | ||
15 | COPYLEFT_LICENSE_EXCLUDE[doc] = 'Space separated list of globs which exclude licenses' | ||
16 | |||
17 | COPYLEFT_RECIPE_TYPE ?= '${@copyleft_recipe_type(d)}' | ||
18 | COPYLEFT_RECIPE_TYPE[doc] = 'The "type" of the current recipe (e.g. target, native, cross)' | ||
19 | |||
20 | COPYLEFT_RECIPE_TYPES ?= 'target' | ||
21 | COPYLEFT_RECIPE_TYPES[type] = 'list' | ||
22 | COPYLEFT_RECIPE_TYPES[doc] = 'Space separated list of recipe types to include' | ||
23 | |||
24 | COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-canadian' | ||
25 | COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list' | ||
26 | COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types' | ||
27 | |||
28 | def copyleft_recipe_type(d): | ||
29 | for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d): | ||
30 | if oe.utils.inherits(d, recipe_type): | ||
31 | return recipe_type | ||
32 | return 'target' | ||
33 | |||
34 | def copyleft_should_include(d): | ||
35 | """ | ||
36 | Determine if this recipe's sources should be deployed for compliance | ||
37 | """ | ||
38 | import ast | ||
39 | import oe.license | ||
40 | from fnmatch import fnmatchcase as fnmatch | ||
41 | |||
42 | recipe_type = d.getVar('COPYLEFT_RECIPE_TYPE', True) | ||
43 | if recipe_type not in oe.data.typed_value('COPYLEFT_RECIPE_TYPES', d): | ||
44 | return False, 'recipe type "%s" is excluded' % recipe_type | ||
45 | |||
46 | include = oe.data.typed_value('COPYLEFT_LICENSE_INCLUDE', d) | ||
47 | exclude = oe.data.typed_value('COPYLEFT_LICENSE_EXCLUDE', d) | ||
48 | |||
49 | try: | ||
50 | is_included, reason = oe.license.is_included(d.getVar('LICENSE', True), include, exclude) | ||
51 | except oe.license.LicenseError as exc: | ||
52 | bb.fatal('%s: %s' % (d.getVar('PF', True), exc)) | ||
53 | else: | ||
54 | if is_included: | ||
55 | if reason: | ||
56 | return True, 'recipe has included licenses: %s' % ', '.join(reason) | ||
57 | else: | ||
58 | return False, 'recipe does not include a copyleft license' | ||
59 | else: | ||
60 | return False, 'recipe has excluded licenses: %s' % ', '.join(reason) | ||
61 | |||
62 | |||