spdx-common.bbclass 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. python () {
  30. from oe.cve_check import extend_cve_status
  31. extend_cve_status(d)
  32. }
  33. def create_spdx_source_deps(d):
  34. import oe.spdx_common
  35. deps = []
  36. if d.getVar("SPDX_INCLUDE_SOURCES") == "1":
  37. pn = d.getVar('PN')
  38. # do_unpack is a hack for now; we only need it to get the
  39. # dependencies do_unpack already has so we can extract the source
  40. # ourselves
  41. if oe.spdx_common.has_task(d, "do_unpack"):
  42. deps.append("%s:do_unpack" % pn)
  43. if oe.spdx_common.is_work_shared_spdx(d) and \
  44. oe.spdx_common.process_sources(d):
  45. # For kernel source code
  46. if oe.spdx_common.has_task(d, "do_shared_workdir"):
  47. deps.append("%s:do_shared_workdir" % pn)
  48. elif d.getVar('S') == d.getVar('STAGING_KERNEL_DIR'):
  49. deps.append("virtual/kernel:do_shared_workdir")
  50. # For gcc-source-${PV} source code
  51. if oe.spdx_common.has_task(d, "do_preconfigure"):
  52. deps.append("%s:do_preconfigure" % pn)
  53. elif oe.spdx_common.has_task(d, "do_patch"):
  54. deps.append("%s:do_patch" % pn)
  55. # For gcc-cross-x86_64 source code
  56. elif oe.spdx_common.has_task(d, "do_configure"):
  57. deps.append("%s:do_configure" % pn)
  58. return " ".join(deps)
  59. python do_collect_spdx_deps() {
  60. # This task calculates the build time dependencies of the recipe, and is
  61. # required because while a task can deptask on itself, those dependencies
  62. # do not show up in BB_TASKDEPDATA. To work around that, this task does the
  63. # deptask on do_create_spdx and writes out the dependencies it finds, then
  64. # do_create_spdx reads in the found dependencies when writing the actual
  65. # SPDX document
  66. import json
  67. import oe.spdx_common
  68. from pathlib import Path
  69. spdx_deps_file = Path(d.getVar("SPDXDEPS"))
  70. deps = oe.spdx_common.collect_direct_deps(d, "do_create_spdx")
  71. with spdx_deps_file.open("w") as f:
  72. json.dump(deps, f)
  73. }
  74. # NOTE: depending on do_unpack is a hack that is necessary to get it's dependencies for archive the source
  75. addtask do_collect_spdx_deps after do_unpack
  76. do_collect_spdx_deps[depends] += "${PATCHDEPENDENCY}"
  77. do_collect_spdx_deps[deptask] = "do_create_spdx"
  78. do_collect_spdx_deps[dirs] = "${SPDXDIR}"
  79. oe.spdx_common.collect_direct_deps[vardepsexclude] += "BB_TASKDEPDATA"
  80. oe.spdx_common.collect_direct_deps[vardeps] += "DEPENDS"
  81. oe.spdx_common.collect_package_providers[vardepsexclude] += "BB_TASKDEPDATA"
  82. oe.spdx_common.get_patched_src[vardepsexclude] += "STAGING_KERNEL_DIR"