copyleft_filter.bbclass 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # Filter the license, the copyleft_should_include returns True for the
  5. # COPYLEFT_LICENSE_INCLUDE recipe, and False for the
  6. # COPYLEFT_LICENSE_EXCLUDE.
  7. #
  8. # By default, includes all GPL and LGPL, and excludes CLOSED and Proprietary.
  9. COPYLEFT_LICENSE_INCLUDE ?= 'GPL* LGPL* AGPL*'
  10. COPYLEFT_LICENSE_INCLUDE[type] = 'list'
  11. COPYLEFT_LICENSE_INCLUDE[doc] = 'Space separated list of globs which include licenses'
  12. COPYLEFT_LICENSE_EXCLUDE ?= 'CLOSED Proprietary'
  13. COPYLEFT_LICENSE_EXCLUDE[type] = 'list'
  14. COPYLEFT_LICENSE_EXCLUDE[doc] = 'Space separated list of globs which exclude licenses'
  15. COPYLEFT_RECIPE_TYPE ?= '${@copyleft_recipe_type(d)}'
  16. COPYLEFT_RECIPE_TYPE[doc] = 'The "type" of the current recipe (e.g. target, native, cross)'
  17. COPYLEFT_RECIPE_TYPES ?= 'target'
  18. COPYLEFT_RECIPE_TYPES[type] = 'list'
  19. COPYLEFT_RECIPE_TYPES[doc] = 'Space separated list of recipe types to include'
  20. COPYLEFT_AVAILABLE_RECIPE_TYPES = 'target native nativesdk cross crosssdk cross-canadian'
  21. COPYLEFT_AVAILABLE_RECIPE_TYPES[type] = 'list'
  22. COPYLEFT_AVAILABLE_RECIPE_TYPES[doc] = 'Space separated list of available recipe types'
  23. COPYLEFT_PN_INCLUDE ?= ''
  24. COPYLEFT_PN_INCLUDE[type] = 'list'
  25. COPYLEFT_PN_INCLUDE[doc] = 'Space separated list of recipe names to include'
  26. COPYLEFT_PN_EXCLUDE ?= ''
  27. COPYLEFT_PN_EXCLUDE[type] = 'list'
  28. COPYLEFT_PN_EXCLUDE[doc] = 'Space separated list of recipe names to exclude'
  29. def copyleft_recipe_type(d):
  30. for recipe_type in oe.data.typed_value('COPYLEFT_AVAILABLE_RECIPE_TYPES', d):
  31. if oe.utils.inherits(d, recipe_type):
  32. return recipe_type
  33. return 'target'
  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. recipe_type = d.getVar('COPYLEFT_RECIPE_TYPE')
  42. if recipe_type not in oe.data.typed_value('COPYLEFT_RECIPE_TYPES', d):
  43. included, motive = False, 'recipe type "%s" is excluded' % recipe_type
  44. else:
  45. included, motive = False, 'recipe did not match anything'
  46. include = oe.data.typed_value('COPYLEFT_LICENSE_INCLUDE', d)
  47. exclude = oe.data.typed_value('COPYLEFT_LICENSE_EXCLUDE', d)
  48. try:
  49. is_included, reason = oe.license.is_included(d.getVar('LICENSE'), include, exclude)
  50. except oe.license.LicenseError as exc:
  51. bb.fatal('%s: %s' % (d.getVar('PF'), exc))
  52. else:
  53. if is_included:
  54. if reason:
  55. included, motive = True, 'recipe has included licenses: %s' % ', '.join(reason)
  56. else:
  57. included, motive = False, 'recipe does not include a copyleft license'
  58. else:
  59. included, motive = False, 'recipe has excluded licenses: %s' % ', '.join(reason)
  60. if any(fnmatch(d.getVar('PN'), name) \
  61. for name in oe.data.typed_value('COPYLEFT_PN_INCLUDE', d)):
  62. included, motive = True, 'recipe included by name'
  63. if any(fnmatch(d.getVar('PN'), name) \
  64. for name in oe.data.typed_value('COPYLEFT_PN_EXCLUDE', d)):
  65. included, motive = False, 'recipe excluded by name'
  66. return included, motive