summaryrefslogtreecommitdiffstats
path: root/meta/classes/create-spdx-3.0.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/create-spdx-3.0.bbclass')
-rw-r--r--meta/classes/create-spdx-3.0.bbclass205
1 files changed, 205 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..c0a5436ad6
--- /dev/null
+++ b/meta/classes/create-spdx-3.0.bbclass
@@ -0,0 +1,205 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: GPL-2.0-only
5#
6
7inherit spdx-common
8
9SPDX_VERSION = "3.0.1"
10
11# The list of SPDX profiles generated documents will conform to
12SPDX_PROFILES ?= "core build software simpleLicensing security"
13
14SPDX_INCLUDE_BUILD_VARIABLES ??= "0"
15SPDX_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
19SPDX_INCLUDE_BITBAKE_PARENT_BUILD ??= "0"
20SPDX_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
24SPDX_PACKAGE_ADDITIONAL_PURPOSE ?= ""
25SPDX_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
30SPDX_IMAGE_PURPOSE ?= "filesystemImage"
31SPDX_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
35SPDX_SDK_PURPOSE ?= "install"
36SPDX_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
40SPDX_INCLUDE_VEX ??= "current"
41SPDX_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
48SPDX_INCLUDE_TIMESTAMPS ?= "0"
49SPDX_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
53SPDX_IMPORTS ??= ""
54SPDX_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
90SPDX_AUTHORS ??= "openembedded"
91SPDX_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
95SPDX_AUTHORS_openembedded_name = "OpenEmbedded"
96SPDX_AUTHORS_openembedded_type = "organization"
97
98SPDX_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
103SPDX_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
108SPDX_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
113SPDX_PACKAGE_SUPPLIER[doc] = "The base variable name to describe the Agent who \
114 is supplying artifacts produced by the build"
115
116SPDX_PACKAGE_VERSION ??= "${PV}"
117SPDX_PACKAGE_VERSION[doc] = "The version of a package, software_packageVersion \
118 in software_Package"
119
120SPDX_PACKAGE_URL ??= ""
121SPDX_PACKAGE_URL[doc] = "Provides a place for the SPDX data creator to record \
122the package URL string (in accordance with the Package URL specification) for \
123a software Package."
124
125IMAGE_CLASSES:append = " create-spdx-image-3.0"
126SDK_CLASSES += "create-spdx-sdk-3.0"
127
128oe.spdx30_tasks.set_timestamp_now[vardepsexclude] = "SPDX_INCLUDE_TIMESTAMPS"
129oe.spdx30_tasks.get_package_sources_from_debug[vardepsexclude] += "STAGING_KERNEL_DIR"
130oe.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.
136SPDX3_LIB_DEP_FILES = "\
137 ${COREBASE}/meta/lib/oe/sbom30.py:True \
138 ${COREBASE}/meta/lib/oe/spdx30.py:True \
139 "
140
141python do_create_spdx() {
142 import oe.spdx30_tasks
143 oe.spdx30_tasks.create_spdx(d)
144}
145do_create_spdx[vardeps] += "\
146 SPDX_INCLUDE_BITBAKE_PARENT_BUILD \
147 SPDX_PACKAGE_ADDITIONAL_PURPOSE \
148 SPDX_PROFILES \
149 SPDX_NAMESPACE_PREFIX \
150 SPDX_UUID_NAMESPACE \
151 "
152
153addtask do_create_spdx after \
154 do_collect_spdx_deps \
155 do_deploy_source_date_epoch \
156 do_populate_sysroot do_package do_packagedata \
157 before do_populate_sdk do_populate_sdk_ext do_build do_rm_work
158
159SSTATETASKS += "do_create_spdx"
160do_create_spdx[sstate-inputdirs] = "${SPDXDEPLOY}"
161do_create_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
162do_create_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
163
164python do_create_spdx_setscene () {
165 sstate_setscene(d)
166}
167addtask do_create_spdx_setscene
168
169do_create_spdx[dirs] = "${SPDXWORK}"
170do_create_spdx[cleandirs] = "${SPDXDEPLOY} ${SPDXWORK}"
171do_create_spdx[depends] += " \
172 ${PATCHDEPENDENCY} \
173 ${@create_spdx_source_deps(d)} \
174"
175
176python do_create_package_spdx() {
177 import oe.spdx30_tasks
178 oe.spdx30_tasks.create_package_spdx(d)
179}
180oe.spdx30_tasks.create_package_spdx[vardepsexclude] = "OVERRIDES"
181
182addtask do_create_package_spdx after do_create_spdx before do_build do_rm_work
183SSTATETASKS += "do_create_package_spdx"
184do_create_package_spdx[sstate-inputdirs] = "${SPDXRUNTIMEDEPLOY}"
185do_create_package_spdx[sstate-outputdirs] = "${DEPLOY_DIR_SPDX}"
186do_create_package_spdx[file-checksums] += "${SPDX3_LIB_DEP_FILES}"
187
188python do_create_package_spdx_setscene () {
189 sstate_setscene(d)
190}
191addtask do_create_package_spdx_setscene
192
193do_create_package_spdx[dirs] = "${SPDXRUNTIMEDEPLOY}"
194do_create_package_spdx[cleandirs] = "${SPDXRUNTIMEDEPLOY}"
195do_create_package_spdx[rdeptask] = "do_create_spdx"
196
197python spdx30_build_started_handler () {
198 import oe.spdx30_tasks
199 d = e.data.createCopy()
200 oe.spdx30_tasks.write_bitbake_spdx(d)
201}
202
203addhandler spdx30_build_started_handler
204spdx30_build_started_handler[eventmask] = "bb.event.BuildStarted"
205