create-spdx-3.0.bbclass 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #
  2. # Copyright OpenEmbedded Contributors
  3. #
  4. # SPDX-License-Identifier: GPL-2.0-only
  5. #
  6. inherit spdx-common
  7. SPDX_VERSION = "3.0.1"
  8. # The list of SPDX profiles generated documents will conform to
  9. SPDX_PROFILES ?= "core build software simpleLicensing security"
  10. SPDX_INCLUDE_BUILD_VARIABLES ??= "0"
  11. SPDX_INCLUDE_BUILD_VARIABLES[doc] = "If set to '1', the bitbake variables for a \
  12. recipe will be included in the Build object. This will most likely result \
  13. in non-reproducible SPDX output"
  14. SPDX_INCLUDE_BITBAKE_PARENT_BUILD ??= "0"
  15. SPDX_INCLUDE_BITBAKE_PARENT_BUILD[doc] = "Report the parent invocation of bitbake \
  16. for each Build object. This allows you to know who invoked bitbake to perform \
  17. a build, but will result in non-reproducible SPDX output."
  18. SPDX_PACKAGE_ADDITIONAL_PURPOSE ?= ""
  19. SPDX_PACKAGE_ADDITIONAL_PURPOSE[doc] = "The list of additional purposes to assign to \
  20. the generated packages for a recipe. The primary purpose is always `install`. \
  21. Packages overrides are allowed to override the additional purposes for \
  22. individual packages."
  23. SPDX_IMAGE_PURPOSE ?= "filesystemImage"
  24. SPDX_IMAGE_PURPOSE[doc] = "The list of purposes to assign to the generated images. \
  25. The first listed item will be the Primary Purpose and all additional items will \
  26. be added as additional purposes"
  27. SPDX_SDK_PURPOSE ?= "install"
  28. SPDX_SDK_PURPOSE[doc] = "The list of purposes to assign to the generate SDK installer. \
  29. The first listed item will be the Primary Purpose and all additional items will \
  30. be added as additional purposes"
  31. SPDX_INCLUDE_VEX ??= "current"
  32. SPDX_INCLUDE_VEX[doc] = "Controls what VEX information is in the output. Set to \
  33. 'none' to disable all VEX data. Set to 'current' to only include VEX data \
  34. for vulnerabilities not already fixed in the upstream source code \
  35. (recommended). Set to 'all' to get all known historical vulnerabilities, \
  36. including those already fixed upstream (warning: This can be large and \
  37. slow)."
  38. SPDX_INCLUDE_TIMESTAMPS ?= "0"
  39. SPDX_INCLUDE_TIMESTAMPS[doc] = "Include time stamps in SPDX output. This is \
  40. useful if you want to know when artifacts were produced and when builds \
  41. occurred, but will result in non-reproducible SPDX output"
  42. SPDX_IMPORTS ??= ""
  43. SPDX_IMPORTS[doc] = "SPDX_IMPORTS is the base variable that describes how to \
  44. reference external SPDX ids. Each import is defined as a key in this \
  45. variable with a suffix to describe to as a suffix to look up more \
  46. information about the import. Each key can have the following variables: \
  47. SPDX_IMPORTS_<key>_spdxid: The Fully qualified SPDX ID of the object \
  48. SPDX_IMPORTS_<key>_uri: The URI where the SPDX Document that contains \
  49. the external object can be found. Optional but recommended \
  50. SPDX_IMPORTS_<key>_hash_<hash>: The Checksum of the SPDX Document that \
  51. contains the External ID. <hash> must be one the valid SPDX hashing \
  52. algorithms, as described by the HashAlgorithm vocabulary in the\
  53. SPDX 3 spec. Optional but recommended"
  54. # Agents
  55. # Bitbake variables can be used to describe an SPDX Agent that may be used
  56. # during the build. An Agent is specified using a set of variables which all
  57. # start with some common base name:
  58. #
  59. # <BASE>_name: The name of the Agent (required)
  60. # <BASE>_type: The type of Agent. Must be one of "person", "organization",
  61. # "software", or "agent" (the default if not specified)
  62. # <BASE>_comment: The comment for the Agent (optional)
  63. # <BASE>_id_<ID>: And External Identifier for the Agent. <ID> must be a valid
  64. # ExternalIdentifierType from the SPDX 3 spec. Commonly, an E-mail address
  65. # can be specified with <BASE>_id_email
  66. #
  67. # Alternatively, an Agent can be an external reference by referencing a key
  68. # in SPDX_IMPORTS like so:
  69. #
  70. # <BASE>_import = "<key>"
  71. #
  72. # Finally, the same agent described by another set of agent variables can be
  73. # referenced by specifying the basename of the variable that should be
  74. # referenced:
  75. #
  76. # SPDX_PACKAGE_SUPPLIER_ref = "SPDX_AUTHORS_openembedded"
  77. SPDX_AUTHORS ??= "openembedded"
  78. SPDX_AUTHORS[doc] = "A space separated list of the document authors. Each item \
  79. is used to name a base variable like SPDX_AUTHORS_<AUTHOR> that \
  80. describes the author."
  81. SPDX_AUTHORS_openembedded_name = "OpenEmbedded"
  82. SPDX_AUTHORS_openembedded_type = "organization"
  83. SPDX_BUILD_HOST[doc] = "The base variable name to describe the build host on \
  84. which a build is running. Must be an SPDX_IMPORTS key. Requires \
  85. SPDX_INCLUDE_BITBAKE_PARENT_BUILD. NOTE: Setting this will result in \
  86. non-reproducible SPDX output"
  87. SPDX_INVOKED_BY[doc] = "The base variable name to describe the Agent that \
  88. invoked the build, which builds will link to if specified. Requires \
  89. SPDX_INCLUDE_BITBAKE_PARENT_BUILD. NOTE: Setting this will likely result in \
  90. non-reproducible SPDX output"
  91. SPDX_ON_BEHALF_OF[doc] = "The base variable name to describe the Agent on who's \
  92. behalf the invoking Agent (SPDX_INVOKED_BY) is running the build. Requires \
  93. SPDX_INCLUDE_BITBAKE_PARENT_BUILD. NOTE: Setting this will likely result in \
  94. non-reproducible SPDX output"
  95. SPDX_PACKAGE_SUPPLIER[doc] = "The base variable name to describe the Agent who \
  96. is supplying artifacts produced by the build"
  97. SPDX_PACKAGE_VERSION ??= "${PV}"
  98. SPDX_PACKAGE_VERSION[doc] = "The version of a package, software_packageVersion \
  99. in software_Package"
  100. SPDX_PACKAGE_URL ??= ""
  101. SPDX_PACKAGE_URL[doc] = "Provides a place for the SPDX data creator to record \
  102. the package URL string (in accordance with the Package URL specification) for \
  103. a software Package."
  104. IMAGE_CLASSES:append = " create-spdx-image-3.0"
  105. SDK_CLASSES += "create-spdx-sdk-3.0"
  106. oe.spdx30_tasks.set_timestamp_now[vardepsexclude] = "SPDX_INCLUDE_TIMESTAMPS"
  107. oe.spdx30_tasks.get_package_sources_from_debug[vardepsexclude] += "STAGING_KERNEL_DIR"
  108. oe.spdx30_tasks.collect_dep_objsets[vardepsexclude] = "SPDX_MULTILIB_SSTATE_ARCHS"
  109. # SPDX library code makes heavy use of classes, which bitbake cannot easily
  110. # parse out dependencies. As such, the library code files that make use of
  111. # classes are explicitly added as file checksum dependencies.
  112. SPDX3_LIB_DEP_FILES = "\
  113. ${COREBASE}/meta/lib/oe/sbom30.py:True \
  114. ${COREBASE}/meta/lib/oe/spdx30.py:True \
  115. "
  116. python do_create_spdx() {
  117. import oe.spdx30_tasks
  118. oe.spdx30_tasks.create_spdx(d)
  119. }
  120. do_create_spdx[vardeps] += "\
  121. SPDX_INCLUDE_BITBAKE_PARENT_BUILD \
  122. SPDX_PACKAGE_ADDITIONAL_PURPOSE \
  123. SPDX_PROFILES \
  124. SPDX_NAMESPACE_PREFIX \
  125. SPDX_UUID_NAMESPACE \
  126. "
  127. addtask do_create_spdx after \
  128. do_collect_spdx_deps \
  129. do_deploy_source_date_epoch \
  130. do_populate_sysroot do_package do_packagedata \
  131. before do_populate_sdk do_populate_sdk_ext do_build do_rm_work
  132. SSTATETASKS += "do_create_spdx"
  133. do_create_spdx[sstate-inputdirs] = "${SPDXDEPLOY}"
  134. do_create_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
  135. do_create_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
  136. python do_create_spdx_setscene () {
  137. sstate_setscene(d)
  138. }
  139. addtask do_create_spdx_setscene
  140. do_create_spdx[dirs] = "${SPDXWORK}"
  141. do_create_spdx[cleandirs] = "${SPDXDEPLOY} ${SPDXWORK}"
  142. do_create_spdx[depends] += " \
  143. ${PATCHDEPENDENCY} \
  144. ${@create_spdx_source_deps(d)} \
  145. "
  146. python do_create_package_spdx() {
  147. import oe.spdx30_tasks
  148. oe.spdx30_tasks.create_package_spdx(d)
  149. }
  150. oe.spdx30_tasks.create_package_spdx[vardepsexclude] = "OVERRIDES"
  151. addtask do_create_package_spdx after do_create_spdx before do_build do_rm_work
  152. SSTATETASKS += "do_create_package_spdx"
  153. do_create_package_spdx[sstate-inputdirs] = "${SPDXRUNTIMEDEPLOY}"
  154. do_create_package_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
  155. do_create_package_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
  156. python do_create_package_spdx_setscene () {
  157. sstate_setscene(d)
  158. }
  159. addtask do_create_package_spdx_setscene
  160. do_create_package_spdx[dirs] = "${SPDXRUNTIMEDEPLOY}"
  161. do_create_package_spdx[cleandirs] = "${SPDXRUNTIMEDEPLOY}"
  162. do_create_package_spdx[rdeptask] = "do_create_spdx"
  163. python spdx30_build_started_handler () {
  164. import oe.spdx30_tasks
  165. d = e.data.createCopy()
  166. oe.spdx30_tasks.write_bitbake_spdx(d)
  167. }
  168. addhandler spdx30_build_started_handler
  169. spdx30_build_started_handler[eventmask] = "bb.event.BuildStarted"