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