@@ -30,6 +30,16 @@ python do_cyclonedx_component() {
30
30
"components" : []
31
31
}
32
32
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 )
33
43
sbom ["components" ]. append (comp )
34
44
35
45
path = d . getVar ("CYCLONEDX_EXPORT_TMP" )
@@ -103,16 +113,8 @@ python do_cyclonedx_image() {
103
113
if filename . endswith (".json" ):
104
114
filepath = os . path . join (filesdir , filename )
105
115
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 )
110
116
111
117
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
-
116
118
if not bb . utils . to_boolean (d . getVar ('CYCLONEDX_WITH_NATIVE' )) and not "isNative" in comp ["tags" ]:
117
119
sbom ["components" ]. append (comp )
118
120
@@ -122,30 +124,12 @@ python do_cyclonedx_image() {
122
124
link = imgdeploydir / (image_link_name + suffix )
123
125
if link != sbom_export_file :
124
126
link . symlink_to (os . path . relpath (sbom_export_file , link . parent ))
125
-
126
127
}
127
128
do_rootfs [recrdeptask ] += "do_cyclonedx_component"
128
129
129
130
ROOTFS_POSTUNINSTALL_COMMAND = + "do_cyclonedx_image"
130
131
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 ):
149
133
cve_products_names = d . getVar ("CVE_PRODUCT" )
150
134
for product in cve_products_names . split ():
151
135
# CVE_PRODUCT in recipes may include vendor information for CPE identifiers. If not,
@@ -155,34 +139,23 @@ python do_cyclonedx_buildinfos () {
155
139
else :
156
140
vendor = ""
157
141
158
- pkg = {
159
- "properties" : []
160
- }
161
142
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
-
169
143
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
+ ]
174
156
}
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
186
159
187
160
def generate_packages_list (d ):
188
161
"""
@@ -325,11 +298,9 @@ python() {
325
298
kernel_pn = d . getVar ('PREFERRED_PROVIDER_virtual/kernel' ) or ''
326
299
327
300
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 )
330
302
331
303
boot_pn = d . getVar ('PREFERRED_PROVIDER_virtual/bootloader' ) or ''
332
304
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 )
335
306
}
0 commit comments