summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2025-03-18 22:40:54 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2025-03-20 13:50:40 +0000
commit110b2c124bcc464325fc5cf987cdf95a19b22bd3 (patch)
treea49b1ded4238368829362a161e3ca60dc34e28c8 /meta/lib
parentbdd2b0fee18c43597efc3493b9ac9ace9ccf7959 (diff)
downloadpoky-110b2c124bcc464325fc5cf987cdf95a19b22bd3.tar.gz
spdx: Update for bitbake changes
Bitbake is dropping the need for fetcher name iteration and multiple revisions per url. Update the code to match (removal of the for loop). (From OE-Core rev: 4859cdf97fd9a260036e148e25f0b78eb393df1e) Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/spdx30_tasks.py125
-rw-r--r--meta/lib/oe/spdx_common.py2
2 files changed, 63 insertions, 64 deletions
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index 0618f2f139..1841b0de4a 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -356,78 +356,77 @@ def add_download_files(d, objset):
356 for download_idx, src_uri in enumerate(urls): 356 for download_idx, src_uri in enumerate(urls):
357 fd = fetch.ud[src_uri] 357 fd = fetch.ud[src_uri]
358 358
359 for name in fd.names: 359 file_name = os.path.basename(fetch.localpath(src_uri))
360 file_name = os.path.basename(fetch.localpath(src_uri)) 360 if oe.patch.patch_path(src_uri, fetch, "", expand=False):
361 if oe.patch.patch_path(src_uri, fetch, "", expand=False): 361 primary_purpose = oe.spdx30.software_SoftwarePurpose.patch
362 primary_purpose = oe.spdx30.software_SoftwarePurpose.patch 362 else:
363 else: 363 primary_purpose = oe.spdx30.software_SoftwarePurpose.source
364 primary_purpose = oe.spdx30.software_SoftwarePurpose.source 364
365 365 if fd.type == "file":
366 if fd.type == "file": 366 if os.path.isdir(fd.localpath):
367 if os.path.isdir(fd.localpath): 367 walk_idx = 1
368 walk_idx = 1 368 for root, dirs, files in os.walk(fd.localpath, onerror=walk_error):
369 for root, dirs, files in os.walk(fd.localpath, onerror=walk_error): 369 dirs.sort()
370 dirs.sort() 370 files.sort()
371 files.sort() 371 for f in files:
372 for f in files: 372 f_path = os.path.join(root, f)
373 f_path = os.path.join(root, f) 373 if os.path.islink(f_path):
374 if os.path.islink(f_path): 374 # TODO: SPDX doesn't support symlinks yet
375 # TODO: SPDX doesn't support symlinks yet 375 continue
376 continue
377
378 file = objset.new_file(
379 objset.new_spdxid(
380 "source", str(download_idx + 1), str(walk_idx)
381 ),
382 os.path.join(
383 file_name, os.path.relpath(f_path, fd.localpath)
384 ),
385 f_path,
386 purposes=[primary_purpose],
387 )
388 376
389 inputs.add(file) 377 file = objset.new_file(
390 walk_idx += 1 378 objset.new_spdxid(
379 "source", str(download_idx + 1), str(walk_idx)
380 ),
381 os.path.join(
382 file_name, os.path.relpath(f_path, fd.localpath)
383 ),
384 f_path,
385 purposes=[primary_purpose],
386 )
391 387
392 else: 388 inputs.add(file)
393 file = objset.new_file( 389 walk_idx += 1
394 objset.new_spdxid("source", str(download_idx + 1)),
395 file_name,
396 fd.localpath,
397 purposes=[primary_purpose],
398 )
399 inputs.add(file)
400 390
401 else: 391 else:
402 dl = objset.add( 392 file = objset.new_file(
403 oe.spdx30.software_Package( 393 objset.new_spdxid("source", str(download_idx + 1)),
404 _id=objset.new_spdxid("source", str(download_idx + 1)), 394 file_name,
405 creationInfo=objset.doc.creationInfo, 395 fd.localpath,
406 name=file_name, 396 purposes=[primary_purpose],
407 software_primaryPurpose=primary_purpose,
408 software_downloadLocation=oe.spdx_common.fetch_data_to_uri(
409 fd, name
410 ),
411 )
412 ) 397 )
398 inputs.add(file)
413 399
414 if fd.method.supports_checksum(fd): 400 else:
415 # TODO Need something better than hard coding this 401 dl = objset.add(
416 for checksum_id in ["sha256", "sha1"]: 402 oe.spdx30.software_Package(
417 expected_checksum = getattr( 403 _id=objset.new_spdxid("source", str(download_idx + 1)),
418 fd, "%s_expected" % checksum_id, None 404 creationInfo=objset.doc.creationInfo,
419 ) 405 name=file_name,
420 if expected_checksum is None: 406 software_primaryPurpose=primary_purpose,
421 continue 407 software_downloadLocation=oe.spdx_common.fetch_data_to_uri(
408 fd, fd.name
409 ),
410 )
411 )
422 412
423 dl.verifiedUsing.append( 413 if fd.method.supports_checksum(fd):
424 oe.spdx30.Hash( 414 # TODO Need something better than hard coding this
425 algorithm=getattr(oe.spdx30.HashAlgorithm, checksum_id), 415 for checksum_id in ["sha256", "sha1"]:
426 hashValue=expected_checksum, 416 expected_checksum = getattr(
427 ) 417 fd, "%s_expected" % checksum_id, None
418 )
419 if expected_checksum is None:
420 continue
421
422 dl.verifiedUsing.append(
423 oe.spdx30.Hash(
424 algorithm=getattr(oe.spdx30.HashAlgorithm, checksum_id),
425 hashValue=expected_checksum,
428 ) 426 )
427 )
429 428
430 inputs.add(dl) 429 inputs.add(dl)
431 430
432 return inputs 431 return inputs
433 432
diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index e1b26edaaf..4caefc7673 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -239,6 +239,6 @@ def fetch_data_to_uri(fd, name):
239 uri = uri + "://" + fd.host + fd.path 239 uri = uri + "://" + fd.host + fd.path
240 240
241 if fd.method.supports_srcrev(): 241 if fd.method.supports_srcrev():
242 uri = uri + "@" + fd.revisions[name] 242 uri = uri + "@" + fd.revision
243 243
244 return uri 244 return uri