diff options
| author | Igor Opaniuk <igor.opaniuk@foundries.io> | 2025-01-15 14:07:02 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-01-29 15:52:58 +0000 |
| commit | f186e405c5b2c0d62c8fe21b460f0c31ec18c268 (patch) | |
| tree | 69acf48583cda196fd10f99336b2ecc399fed460 | |
| parent | 08680a5b549be98110aa71093c2e87e4d04ce364 (diff) | |
| download | poky-f186e405c5b2c0d62c8fe21b460f0c31ec18c268.tar.gz | |
lib/spdx30_tasks: support directories deployed by image recipes
create_image_spdx() implementation assumes that image is indeed a file.
If image recipe deploys a directory (for example, which contains an
hierarchy of flash artifacts, that is used by SoC vendor-specific
flashing tool) which follows ${IMAGE_NAME}.${IMAGE_TYPE} naming scheme,
create_image_spdx() function will fail after trying to hash a directory:
*** 0002:do_create_image_spdx(d)
0003:
File: '.../meta/classes-recipe/create-spdx-image-3.0.bbclass', lineno: 48, function: do_create_image_spdx
0044:addtask do_create_rootfs_spdx_setscene
0045:
0046:python do_create_image_spdx() {
0047: import oe.spdx30_tasks
*** 0048: oe.spdx30_tasks.create_image_spdx(d)
0049:}
0050:addtask do_create_image_spdx after do_image_complete do_create_rootfs_spdx before do_build
0051:SSTATETASKS += "do_create_image_spdx"
...
File: '.../bitbake/lib/bb/utils.py', lineno: 536, function: _hasher
0532:
0533:def _hasher(method, filename):
0534: import mmap
0535:
*** 0536: with open(filename, "rb") as f:
0537: try:
0538: with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ) as mm:
0539: for chunk in iter(lambda: mm.read(8192), b''):
0540: method.update(chunk)
Exception: IsADirectoryError: [Errno 21] Is a directory: '...'
(From OE-Core rev: a0d63082a4db375a55586c7864e280cd8f45ff7b)
Signed-off-by: Igor Opaniuk <igor.opaniuk@foundries.io>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oe/spdx30_tasks.py | 61 |
1 files changed, 42 insertions, 19 deletions
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py index c60c97896c..658e533d75 100644 --- a/meta/lib/oe/spdx30_tasks.py +++ b/meta/lib/oe/spdx30_tasks.py | |||
| @@ -135,7 +135,7 @@ def add_package_files( | |||
| 135 | topdir, | 135 | topdir, |
| 136 | get_spdxid, | 136 | get_spdxid, |
| 137 | get_purposes, | 137 | get_purposes, |
| 138 | license_data, | 138 | license_data=None, |
| 139 | *, | 139 | *, |
| 140 | archive=None, | 140 | archive=None, |
| 141 | ignore_dirs=[], | 141 | ignore_dirs=[], |
| @@ -169,7 +169,10 @@ def add_package_files( | |||
| 169 | ) | 169 | ) |
| 170 | spdx_files.add(spdx_file) | 170 | spdx_files.add(spdx_file) |
| 171 | 171 | ||
| 172 | if oe.spdx30.software_SoftwarePurpose.source in file_purposes: | 172 | if ( |
| 173 | oe.spdx30.software_SoftwarePurpose.source in file_purposes | ||
| 174 | and license_data is not None | ||
| 175 | ): | ||
| 173 | objset.scan_declared_licenses(spdx_file, filepath, license_data) | 176 | objset.scan_declared_licenses(spdx_file, filepath, license_data) |
| 174 | 177 | ||
| 175 | if archive is not None: | 178 | if archive is not None: |
| @@ -1072,25 +1075,45 @@ def create_image_spdx(d): | |||
| 1072 | for image in task["images"]: | 1075 | for image in task["images"]: |
| 1073 | image_filename = image["filename"] | 1076 | image_filename = image["filename"] |
| 1074 | image_path = image_deploy_dir / image_filename | 1077 | image_path = image_deploy_dir / image_filename |
| 1075 | a = objset.add_root( | 1078 | if os.path.isdir(image_path): |
| 1076 | oe.spdx30.software_File( | 1079 | a = add_package_files( |
| 1077 | _id=objset.new_spdxid("image", image_filename), | 1080 | d, |
| 1078 | creationInfo=objset.doc.creationInfo, | 1081 | objset, |
| 1079 | name=image_filename, | 1082 | image_path, |
| 1080 | verifiedUsing=[ | 1083 | lambda file_counter: objset.new_spdxid( |
| 1081 | oe.spdx30.Hash( | 1084 | "imagefile", str(file_counter) |
| 1082 | algorithm=oe.spdx30.HashAlgorithm.sha256, | 1085 | ), |
| 1083 | hashValue=bb.utils.sha256_file(image_path), | 1086 | lambda filepath: [], |
| 1084 | ) | 1087 | license_data=None, |
| 1085 | ], | 1088 | ignore_dirs=[], |
| 1089 | ignore_top_level_dirs=[], | ||
| 1090 | archive=None, | ||
| 1086 | ) | 1091 | ) |
| 1087 | ) | 1092 | artifacts.extend(a) |
| 1088 | set_purposes( | 1093 | else: |
| 1089 | d, a, "SPDX_IMAGE_PURPOSE:%s" % imagetype, "SPDX_IMAGE_PURPOSE" | 1094 | a = objset.add_root( |
| 1090 | ) | 1095 | oe.spdx30.software_File( |
| 1091 | set_timestamp_now(d, a, "builtTime") | 1096 | _id=objset.new_spdxid("image", image_filename), |
| 1097 | creationInfo=objset.doc.creationInfo, | ||
| 1098 | name=image_filename, | ||
| 1099 | verifiedUsing=[ | ||
| 1100 | oe.spdx30.Hash( | ||
| 1101 | algorithm=oe.spdx30.HashAlgorithm.sha256, | ||
| 1102 | hashValue=bb.utils.sha256_file(image_path), | ||
| 1103 | ) | ||
| 1104 | ], | ||
| 1105 | ) | ||
| 1106 | ) | ||
| 1107 | |||
| 1108 | artifacts.append(a) | ||
| 1109 | |||
| 1110 | for a in artifacts: | ||
| 1111 | set_purposes( | ||
| 1112 | d, a, "SPDX_IMAGE_PURPOSE:%s" % imagetype, "SPDX_IMAGE_PURPOSE" | ||
| 1113 | ) | ||
| 1114 | |||
| 1115 | set_timestamp_now(d, a, "builtTime") | ||
| 1092 | 1116 | ||
| 1093 | artifacts.append(a) | ||
| 1094 | 1117 | ||
| 1095 | if artifacts: | 1118 | if artifacts: |
| 1096 | objset.new_scoped_relationship( | 1119 | objset.new_scoped_relationship( |
