copyleft_filter.bbclass 3.2 KB

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