copyleft_compliance.bbclass 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: MIT
  5. #
  6. # Deploy sources for recipes for compliance with copyleft-style licenses
  7. # Defaults to using symlinks, as it's a quick operation, and one can easily
  8. # follow the links when making use of the files (e.g. tar with the -h arg).
  9. #
  10. # vi:sts=4:sw=4:et
  11. inherit copyleft_filter
  12. COPYLEFT_SOURCES_DIR ?= '${DEPLOY_DIR}/copyleft_sources'
  13. python do_prepare_copyleft_sources () {
  14. """Populate a tree of the recipe sources and emit patch series files"""
  15. import os.path
  16. import shutil
  17. p = d.getVar('P')
  18. included, reason = copyleft_should_include(d)
  19. if not included:
  20. bb.debug(1, 'copyleft: %s is excluded: %s' % (p, reason))
  21. return
  22. else:
  23. bb.debug(1, 'copyleft: %s is included: %s' % (p, reason))
  24. sources_dir = d.getVar('COPYLEFT_SOURCES_DIR')
  25. dl_dir = d.getVar('DL_DIR')
  26. src_uri = d.getVar('SRC_URI').split()
  27. fetch = bb.fetch2.Fetch(src_uri, d)
  28. ud = fetch.ud
  29. pf = d.getVar('PF')
  30. dest = os.path.join(sources_dir, pf)
  31. shutil.rmtree(dest, ignore_errors=True)
  32. bb.utils.mkdirhier(dest)
  33. for u in ud.values():
  34. local = os.path.normpath(fetch.localpath(u.url))
  35. if local.endswith('.bb'):
  36. continue
  37. elif local.endswith('/'):
  38. local = local[:-1]
  39. if u.mirrortarball:
  40. tarball_path = os.path.join(dl_dir, u.mirrortarball)
  41. if os.path.exists(tarball_path):
  42. local = tarball_path
  43. oe.path.symlink(local, os.path.join(dest, os.path.basename(local)), force=True)
  44. patches = src_patches(d)
  45. for patch in patches:
  46. _, _, local, _, _, parm = bb.fetch.decodeurl(patch)
  47. patchdir = parm.get('patchdir')
  48. if patchdir:
  49. series = os.path.join(dest, 'series.subdir.%s' % patchdir.replace('/', '_'))
  50. else:
  51. series = os.path.join(dest, 'series')
  52. with open(series, 'a') as s:
  53. s.write('%s -p%s\n' % (os.path.basename(local), parm['striplevel']))
  54. }
  55. addtask prepare_copyleft_sources after do_fetch before do_build
  56. do_prepare_copyleft_sources[dirs] = "${WORKDIR}"
  57. do_build[recrdeptask] += 'do_prepare_copyleft_sources'