common-license.bbclass 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Handle automatically pointing LIC_FILES_CHKSUM to a common license outside
  2. # the recipe's source tree, based on the value of LICENSE.
  3. LIC_FILES_CHKSUM ?= "${COMMON_LIC_CHKSUM}"
  4. COMMON_LIC_CHKSUM = ""
  5. COMMON_LIC_CHKSUM_CLOSED = ""
  6. COMMON_LIC_CHKSUM_GPL-2.0-only = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0-only;md5=801f80980d171dd6425610833a22dbe6"
  7. COMMON_LIC_CHKSUM_GPL-3.0-only = "file://${COREBASE}/meta/files/common-licenses/GPL-3.0-only;md5=c79ff39f19dfec6d293b95dea7b07891"
  8. COMMON_LIC_CHKSUM_GPL-3.0-with-GCC-exception = "file://${COREBASE}/meta/files/common-licenses/GPL-3.0-with-GCC-exception;md5=aef5f35c9272f508be848cd99e0151df"
  9. COMMON_LIC_CHKSUM_LGPL-2.1-only = "file://${COREBASE}/meta/files/common-licenses/LGPL-2.1-only;md5=1a6d268fd218675ffea8be556788b780"
  10. COMMON_LIC_CHKSUM_LGPL-2.1-or-later = "file://${COREBASE}/meta/files/common-licenses/LGPL-2.1-or-later;md5=2a4f4fd2128ea2f65047ee63fbca9f68"
  11. python () {
  12. import oe.license
  13. #; Set LIC_FILES_CHKSUM to a common license if it's unset and LICENSE is set
  14. licensestr = d.getVar('LICENSE', True)
  15. for pkg in d.getVar('PACKAGES', True).split():
  16. pkg_lic = d.getVar('LICENSE:%s' % pkg, True)
  17. if pkg_lic:
  18. licensestr += ' ' + pkg_lic
  19. licenses = oe.license.flattened_licenses(licensestr, lambda a, b: a + b)
  20. checksums = set()
  21. for license in licenses:
  22. if license != 'CLOSED' and d.getVar('LIC_FILES_CHKSUM', False) == '${COMMON_LIC_CHKSUM}':
  23. ext_chksum_var = 'COMMON_LIC_CHKSUM_{0}'.format(license)
  24. if d.getVar(ext_chksum_var, True):
  25. checksums.add('${%s}' % ext_chksum_var)
  26. else:
  27. lic_file_name = '${COREBASE}/meta/files/common-licenses/%s' % license
  28. lic_file = d.expand(lic_file_name)
  29. if os.path.exists(lic_file):
  30. md5 = bb.utils.md5_file(lic_file)
  31. chksum = 'file://{0};md5={1}'.format(lic_file_name, md5)
  32. bb.fatal('{0}: No available license checksum info for this license. Either set LIC_FILES_CHKSUM, or define:\n {1} = "{2}"'.format(d.getVar('PF', True), ext_chksum_var, chksum))
  33. d.setVar('COMMON_LIC_CHKSUM', ' '.join(checksums))
  34. }