spdx-common.bbclass 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. SPDX_VERSION ??= ""
  7. DEPLOY_DIR_SPDX ??= "${DEPLOY_DIR}/spdx/${SPDX_VERSION}"
  8. # The product name that the CVE database uses. Defaults to BPN, but may need to
  9. # be overriden per recipe (for example tiff.bb sets CVE_PRODUCT=libtiff).
  10. CVE_PRODUCT ??= "${BPN}"
  11. CVE_VERSION ??= "${PV}"
  12. SPDXDIR ??= "${WORKDIR}/spdx/${SPDX_VERSION}"
  13. SPDXDEPLOY = "${SPDXDIR}/deploy"
  14. SPDXWORK = "${SPDXDIR}/work"
  15. SPDXIMAGEWORK = "${SPDXDIR}/image-work"
  16. SPDXSDKWORK = "${SPDXDIR}/sdk-work"
  17. SPDXSDKEXTWORK = "${SPDXDIR}/sdk-ext-work"
  18. SPDXDEPS = "${SPDXDIR}/deps.json"
  19. SPDX_TOOL_NAME ??= "oe-spdx-creator"
  20. SPDX_TOOL_VERSION ??= "1.0"
  21. SPDXRUNTIMEDEPLOY = "${SPDXDIR}/runtime-deploy"
  22. SPDX_INCLUDE_SOURCES ??= "0"
  23. SPDX_UUID_NAMESPACE ??= "sbom.openembedded.org"
  24. SPDX_NAMESPACE_PREFIX ??= "http://spdx.org/spdxdocs"
  25. SPDX_PRETTY ??= "0"
  26. SPDX_LICENSES ??= "${COREBASE}/meta/files/spdx-licenses.json"
  27. SPDX_CUSTOM_ANNOTATION_VARS ??= ""
  28. SPDX_MULTILIB_SSTATE_ARCHS ??= "${SSTATE_ARCHS}"
  29. def create_spdx_source_deps(d):
  30. import oe.spdx_common
  31. deps = []
  32. if d.getVar("SPDX_INCLUDE_SOURCES") == "1":
  33. pn = d.getVar('PN')
  34. # do_unpack is a hack for now; we only need it to get the
  35. # dependencies do_unpack already has so we can extract the source
  36. # ourselves
  37. if oe.spdx_common.has_task(d, "do_unpack"):
  38. deps.append("%s:do_unpack" % pn)
  39. if oe.spdx_common.is_work_shared_spdx(d) and \
  40. oe.spdx_common.process_sources(d):
  41. # For kernel source code
  42. if oe.spdx_common.has_task(d, "do_shared_workdir"):
  43. deps.append("%s:do_shared_workdir" % pn)
  44. elif d.getVar('S') == d.getVar('STAGING_KERNEL_DIR'):
  45. deps.append("virtual/kernel:do_shared_workdir")
  46. # For gcc-source-${PV} source code
  47. if oe.spdx_common.has_task(d, "do_preconfigure"):
  48. deps.append("%s:do_preconfigure" % pn)
  49. elif oe.spdx_common.has_task(d, "do_patch"):
  50. deps.append("%s:do_patch" % pn)
  51. # For gcc-cross-x86_64 source code
  52. elif oe.spdx_common.has_task(d, "do_configure"):
  53. deps.append("%s:do_configure" % pn)
  54. return " ".join(deps)
  55. python do_collect_spdx_deps() {
  56. # This task calculates the build time dependencies of the recipe, and is
  57. # required because while a task can deptask on itself, those dependencies
  58. # do not show up in BB_TASKDEPDATA. To work around that, this task does the
  59. # deptask on do_create_spdx and writes out the dependencies it finds, then
  60. # do_create_spdx reads in the found dependencies when writing the actual
  61. # SPDX document
  62. import json
  63. import oe.spdx_common
  64. from pathlib import Path
  65. spdx_deps_file = Path(d.getVar("SPDXDEPS"))
  66. deps = oe.spdx_common.collect_direct_deps(d, "do_create_spdx")
  67. with spdx_deps_file.open("w") as f:
  68. json.dump(deps, f)
  69. }
  70. # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source
  71. addtask do_collect_spdx_deps after do_unpack
  72. do_collect_spdx_deps[depends] += "${PATCHDEPENDENCY}"
  73. do_collect_spdx_deps[deptask] = "do_create_spdx"
  74. do_collect_spdx_deps[dirs] = "${SPDXDIR}"
  75. oe.spdx_common.collect_direct_deps[vardepsexclude] += "BB_TASKDEPDATA"
  76. oe.spdx_common.collect_direct_deps[vardeps] += "DEPENDS"
  77. oe.spdx_common.collect_package_providers[vardepsexclude] += "BB_TASKDEPDATA"
  78. oe.spdx_common.get_patched_src[vardepsexclude] += "STAGING_KERNEL_DIR"