common-license.bbclass 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 = "file://${COREBASE}/meta/files/common-licenses/GPL-2.0;md5=801f80980d171dd6425610833a22dbe6"
  7. COMMON_LIC_CHKSUM_GPL-3.0 = "file://${COREBASE}/meta/files/common-licenses/GPL-3.0;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 = "file://${COREBASE}/meta/files/common-licenses/LGPL-2.1;md5=1a6d268fd218675ffea8be556788b780"
  10. python () {
  11. import oe.license
  12. #; Set LIC_FILES_CHKSUM to a common license if it's unset and LICENSE is set
  13. licensestr = d.getVar('LICENSE', True)
  14. for pkg in d.getVar('PACKAGES', True).split():
  15. pkg_lic = d.getVar('LICENSE_%s' % pkg, True)
  16. if pkg_lic:
  17. licensestr += ' ' + pkg_lic
  18. licenses = oe.license.flattened_licenses(licensestr, lambda a, b: a + b)
  19. checksums = set()
  20. for license in licenses:
  21. if license != 'CLOSED' and d.getVar('LIC_FILES_CHKSUM', False) == '${COMMON_LIC_CHKSUM}':
  22. license = mapped_license(license, d)
  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. }
  35. def mapped_license(license, d):
  36. if license.endswith('+'):
  37. license = license[:-1]
  38. mapped = d.getVarFlag('SPDXLICENSEMAP', license, False)
  39. if mapped:
  40. license = mapped
  41. return license