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 9COPYLEFT_LICENSE_INCLUDE ?= 'GPL* LGPL* AGPL*' 10COPYLEFT_LICENSE_INCLUDE[type] = 'list' 11COPYLEFT_LICENSE_INCLUDE[doc] = 'Space separated list of globs which include licenses' 12 13COPYLEFT_LICENSE_EXCLUDE ?= 'CLOSED Proprietary' 14COPYLEFT_LICENSE_EXCLUDE[type] = 'list' 15COPYLEFT_LICENSE_EXCLUDE[doc] = 'Space separated list of globs which exclude licenses' 16 17COPYLEFT_RECIPE_TYPE ?= '${@copyleft_recipe_type(d)}' 18COPYLEFT_RECIPE_TYPE[doc] = 'The "type" of the current recipe (e.g. target, native, cross)' 19 20COPYLEFT_RECIPE_TYPES ?= 'target' 21COPYLEFT_RECIPE_TYPES[type] = 'list' 22COPYLEFT_RECIPE_TYPES[doc] = 'Space separated list of recipe types to include' 23 24COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-canadian' 25COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list' 26COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types' 27 28COPYLEFT_PN_INCLUDE ?= '' 29COPYLEFT_PN_INCLUDE[type] = 'list' 30COPYLEFT_PN_INCLUDE[doc] = 'Space separated list of recipe names to include' 31 32COPYLEFT_PN_EXCLUDE ?= '' 33COPYLEFT_PN_EXCLUDE[type] = 'list' 34COPYLEFT_PN_EXCLUDE[doc] = 'Space separated list of recipe names to exclude' 35 36def copyleft_recipe_type(d): 37 for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d): 38 if oe.utils.inherits(d, recipe_type): 39 return recipe_type 40 return 'target' 41 42def copyleft_should_include(d): 43 """ 44 Determine if this recipe's sources should be deployed for compliance 45 """ 46 import ast 47 import oe.license 48 from fnmatch import fnmatchcase as fnmatch 49 50 recipe_type = d.getVar('COPYLEFT_RECIPE_TYPE') 51 if recipe_type not in oe.data.typed_value('COPYLEFT_RECIPE_TYPES', d): 52 included, motive = False, 'recipe type "%s" is excluded' % recipe_type 53 else: 54 included, motive = False, 'recipe did not match anything' 55 56 include = oe.data.typed_value('COPYLEFT_LICENSE_INCLUDE', d) 57 exclude = oe.data.typed_value('COPYLEFT_LICENSE_EXCLUDE', d) 58 59 try: 60 is_included, reason = oe.license.is_included(d.getVar('LICENSE'), include, exclude) 61 except oe.license.LicenseError as exc: 62 bb.fatal('%s: %s' % (d.getVar('PF'), exc)) 63 else: 64 if is_included: 65 if reason: 66 included, motive = True, 'recipe has included licenses: %s' % ', '.join(reason) 67 else: 68 included, motive = False, 'recipe does not include a copyleft license' 69 else: 70 included, motive = False, 'recipe has excluded licenses: %s' % ', '.join(reason) 71 72 if any(fnmatch(d.getVar('PN'), name) \ 73 for name in oe.data.typed_value('COPYLEFT_PN_INCLUDE', d)): 74 included, motive = True, 'recipe included by name' 75 if any(fnmatch(d.getVar('PN'), name) \ 76 for name in oe.data.typed_value('COPYLEFT_PN_EXCLUDE', d)): 77 included, motive = False, 'recipe excluded by name' 78 79 return included, motive 80