Skip to content

Commit d9c1a38

Browse files
motto-phytecsmk-embedded
authored andcommitted
classes: sbom-cyclonedx.bbclass: Integrate buildinfos task in do_cyclonedx_component task
The buildinfos task is only for the bootloader and the kernel, which has creates cyclonedx node with the config and build files information in a separate file for the package. Integration of the buildinfos functions to the do_cyclonedx_component task for using the sstates and to reduce the task amount. Signed-off-by: Maik Otto <[email protected]> Signed-off-by: Stefan Müller-Klieser <[email protected]>
1 parent f22c42b commit d9c1a38

File tree

1 file changed

+27
-56
lines changed

1 file changed

+27
-56
lines changed

classes/sbom-cyclonedx.bbclass

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ python do_cyclonedx_component() {
3030
"components": []
3131
}
3232
for comp in generate_packages_list(d):
33+
if bb.utils.to_boolean(d.getVar('CYCLONEDX_WITH_BUILDINFOS')):
34+
pn = d.getVar('PN')
35+
36+
kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel') or ''
37+
boot_pn = d.getVar('PREFERRED_PROVIDER_virtual/bootloader') or ''
38+
if pn == boot_pn or pn == kernel_pn:
39+
prop_buildinfo = do_cyclonedx_buildinfos(d)
40+
if prop_buildinfo is not None:
41+
for prop in prop_buildinfo["properties"]:
42+
comp["properties"].append(prop)
3343
sbom["components"].append(comp)
3444

3545
path = d.getVar("CYCLONEDX_EXPORT_TMP")
@@ -103,16 +113,8 @@ python do_cyclonedx_image() {
103113
if filename.endswith(".json"):
104114
filepath = os.path.join(filesdir, filename)
105115
component = read_json(filepath)
106-
prop_path = os.path.join(filesdir, "buildinfos", filename)
107-
prop_buildinfo = None
108-
if os.path.exists(prop_path):
109-
prop_buildinfo = read_json(prop_path)
110116

111117
for comp in component["components"]:
112-
if prop_buildinfo is not None:
113-
for prop in prop_buildinfo["properties"]:
114-
comp["properties"].append(prop)
115-
116118
if not bb.utils.to_boolean(d.getVar('CYCLONEDX_WITH_NATIVE')) and not "isNative" in comp["tags"]:
117119
sbom["components"].append(comp)
118120

@@ -122,30 +124,12 @@ python do_cyclonedx_image() {
122124
link = imgdeploydir / (image_link_name + suffix)
123125
if link != sbom_export_file:
124126
link.symlink_to(os.path.relpath(sbom_export_file, link.parent))
125-
126127
}
127128
do_rootfs[recrdeptask] += "do_cyclonedx_component"
128129

129130
ROOTFS_POSTUNINSTALL_COMMAND =+ "do_cyclonedx_image"
130131

131-
def cyclonedx_image_depends(d):
132-
deps = list()
133-
134-
if bb.utils.to_boolean(d.getVar('CYCLONEDX_WITH_BUILDINFOS')):
135-
if bb.data.inherits_class('image', d):
136-
boot_pn = d.getVar('PREFERRED_PROVIDER_virtual/bootloader') or ''
137-
if boot_pn:
138-
deps.append('%s:do_cyclonedx_buildinfos' % boot_pn)
139-
140-
kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel') or ''
141-
if kernel_pn:
142-
deps.append('%s:do_cyclonedx_buildinfos' % kernel_pn)
143-
144-
return ' '.join(deps)
145-
146-
do_cyclonedx_image[depends] += " ${@cyclonedx_image_depends(d)} "
147-
148-
python do_cyclonedx_buildinfos () {
132+
def do_cyclonedx_buildinfos (d):
149133
cve_products_names = d.getVar("CVE_PRODUCT")
150134
for product in cve_products_names.split():
151135
# CVE_PRODUCT in recipes may include vendor information for CPE identifiers. If not,
@@ -155,34 +139,23 @@ python do_cyclonedx_buildinfos () {
155139
else:
156140
vendor = ""
157141

158-
pkg = {
159-
"properties": []
160-
}
161142
build_files = do_generate_package_activefiles(product,d)
162-
if len(build_files) >0:
163-
prop_tfl = {
164-
"name" : "build_file_list",
165-
"value" : "{}".format(build_files)
166-
}
167-
pkg["properties"].append(prop_tfl)
168-
169143
build_config = get_config(product,d)
170-
if len(build_config) >0:
171-
prop_bc = {
172-
"name" : "build_config_list",
173-
"value" : "{}".format(build_config)
144+
if len(build_files) >0 and len(build_config) >0:
145+
pkg = {
146+
"properties": [
147+
{
148+
"name" : "build_file_list",
149+
"value" : "{}".format(build_files)
150+
},
151+
{
152+
"name" : "build_config_list",
153+
"value" : "{}".format(build_config)
154+
}
155+
]
174156
}
175-
pkg["properties"].append(prop_bc)
176-
177-
path = os.path.join(d.getVar("CYCLONEDX_EXPORT_TMP"), "buildinfos")
178-
if not os.path.exists(path):
179-
bb.utils.mkdirhier(path)
180-
181-
sbom_file = os.path.join(path, d.getVar("CYCLONEDX_EXPORT_COMPONENT_FILE"))
182-
183-
write_json(sbom_file, pkg)
184-
}
185-
do_cyclonedx_buildinfos[nostamp] = "1"
157+
return pkg
158+
return None
186159

187160
def generate_packages_list(d):
188161
"""
@@ -325,11 +298,9 @@ python() {
325298
kernel_pn = d.getVar('PREFERRED_PROVIDER_virtual/kernel') or ''
326299

327300
if pn == kernel_pn:
328-
bb.build.addtask('do_cyclonedx_buildinfos', 'do_rm_work', 'do_compile', d)
329-
d.appendVarFlag('do_cyclonedx_buildinfos', 'depends', ' %s:do_compile' % pn)
301+
d.appendVarFlag('do_cyclonedx_component', 'depends', ' %s:do_compile' % pn)
330302

331303
boot_pn = d.getVar('PREFERRED_PROVIDER_virtual/bootloader') or ''
332304
if pn == boot_pn:
333-
bb.build.addtask('do_cyclonedx_buildinfos', 'do_rm_work', 'do_compile', d)
334-
d.appendVarFlag('do_cyclonedx_buildinfos', 'depends', ' %s:do_compile' % pn)
305+
d.appendVarFlag('do_cyclonedx_component', 'depends', ' %s:do_compile' % pn)
335306
}

0 commit comments

Comments
 (0)