diff options
| author | Joshua Watt <JPEWhacker@gmail.com> | 2024-10-07 10:24:15 -0600 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-10-15 11:47:24 +0100 |
| commit | 19aa2c0a99b02dfa157f38d8975ea73e95647861 (patch) | |
| tree | 71ba9519e7d535c79e6ec54f2e67919512c738a8 /meta/lib | |
| parent | ca5472cd2ce30061dc8bd18efe9e85c8f76b8444 (diff) | |
| download | poky-19aa2c0a99b02dfa157f38d8975ea73e95647861.tar.gz | |
spdx30: Link license and build by alias
The license information and Build created by do_create_spdx are changed
to be referenced by their link alias instead of the actual SPDX ID. This
fixes a case where do_create_package_spdx would pull these from
mismatching sstate, and then the SPDX IDs would be unresolved when
assembling the final document
(From OE-Core rev: c0fcdc72a7c8fca86a874d1b04298fe9e500c796)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
| -rw-r--r-- | meta/lib/oe/sbom30.py | 43 | ||||
| -rw-r--r-- | meta/lib/oe/spdx30_tasks.py | 10 |
2 files changed, 31 insertions, 22 deletions
diff --git a/meta/lib/oe/sbom30.py b/meta/lib/oe/sbom30.py index 7b4f78cc71..27ab5e45ac 100644 --- a/meta/lib/oe/sbom30.py +++ b/meta/lib/oe/sbom30.py | |||
| @@ -305,24 +305,7 @@ class ObjectSet(oe.spdx30.SHACLObjectSet): | |||
| 305 | 305 | ||
| 306 | def add_aliases(self): | 306 | def add_aliases(self): |
| 307 | for o in self.foreach_type(oe.spdx30.Element): | 307 | for o in self.foreach_type(oe.spdx30.Element): |
| 308 | if not o._id or o._id.startswith("_:"): | 308 | self.set_element_alias(o) |
| 309 | continue | ||
| 310 | |||
| 311 | alias_ext = get_alias(o) | ||
| 312 | if alias_ext is None: | ||
| 313 | unihash = self.d.getVar("BB_UNIHASH") | ||
| 314 | namespace = self.get_namespace() | ||
| 315 | if unihash not in o._id: | ||
| 316 | bb.warn(f"Unihash {unihash} not found in {o._id}") | ||
| 317 | elif namespace not in o._id: | ||
| 318 | bb.warn(f"Namespace {namespace} not found in {o._id}") | ||
| 319 | else: | ||
| 320 | alias_ext = set_alias( | ||
| 321 | o, | ||
| 322 | o._id.replace(unihash, "UNIHASH").replace( | ||
| 323 | namespace, self.d.getVar("PN") | ||
| 324 | ), | ||
| 325 | ) | ||
| 326 | 309 | ||
| 327 | def remove_internal_extensions(self): | 310 | def remove_internal_extensions(self): |
| 328 | def remove(o): | 311 | def remove(o): |
| @@ -345,6 +328,26 @@ class ObjectSet(oe.spdx30.SHACLObjectSet): | |||
| 345 | str(uuid.uuid5(namespace_uuid, pn)), | 328 | str(uuid.uuid5(namespace_uuid, pn)), |
| 346 | ) | 329 | ) |
| 347 | 330 | ||
| 331 | def set_element_alias(self, e): | ||
| 332 | if not e._id or e._id.startswith("_:"): | ||
| 333 | return | ||
| 334 | |||
| 335 | alias_ext = get_alias(e) | ||
| 336 | if alias_ext is None: | ||
| 337 | unihash = self.d.getVar("BB_UNIHASH") | ||
| 338 | namespace = self.get_namespace() | ||
| 339 | if unihash not in e._id: | ||
| 340 | bb.warn(f"Unihash {unihash} not found in {e._id}") | ||
| 341 | elif namespace not in e._id: | ||
| 342 | bb.warn(f"Namespace {namespace} not found in {e._id}") | ||
| 343 | else: | ||
| 344 | alias_ext = set_alias( | ||
| 345 | e, | ||
| 346 | e._id.replace(unihash, "UNIHASH").replace( | ||
| 347 | namespace, self.d.getVar("PN") | ||
| 348 | ), | ||
| 349 | ) | ||
| 350 | |||
| 348 | def new_spdxid(self, *suffix, include_unihash=True): | 351 | def new_spdxid(self, *suffix, include_unihash=True): |
| 349 | items = [self.get_namespace()] | 352 | items = [self.get_namespace()] |
| 350 | if include_unihash: | 353 | if include_unihash: |
| @@ -557,7 +560,9 @@ class ObjectSet(oe.spdx30.SHACLObjectSet): | |||
| 557 | scope=scope, | 560 | scope=scope, |
| 558 | ) | 561 | ) |
| 559 | 562 | ||
| 560 | def new_license_expression(self, license_expression, license_data, license_text_map={}): | 563 | def new_license_expression( |
| 564 | self, license_expression, license_data, license_text_map={} | ||
| 565 | ): | ||
| 561 | license_list_version = license_data["licenseListVersion"] | 566 | license_list_version = license_data["licenseListVersion"] |
| 562 | # SPDX 3 requires that the license list version be a semver | 567 | # SPDX 3 requires that the license list version be a semver |
| 563 | # MAJOR.MINOR.MICRO, but the actual license version might be | 568 | # MAJOR.MINOR.MICRO, but the actual license version might be |
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py index d0dd40877e..e0b656d81f 100644 --- a/meta/lib/oe/spdx30_tasks.py +++ b/meta/lib/oe/spdx30_tasks.py | |||
| @@ -119,9 +119,11 @@ def add_license_expression(d, objset, license_expression, license_data): | |||
| 119 | ) | 119 | ) |
| 120 | spdx_license_expression = " ".join(convert(l) for l in lic_split) | 120 | spdx_license_expression = " ".join(convert(l) for l in lic_split) |
| 121 | 121 | ||
| 122 | return objset.new_license_expression( | 122 | o = objset.new_license_expression( |
| 123 | spdx_license_expression, license_data, license_text_map | 123 | spdx_license_expression, license_data, license_text_map |
| 124 | ) | 124 | ) |
| 125 | objset.set_element_alias(o) | ||
| 126 | return o | ||
| 125 | 127 | ||
| 126 | 128 | ||
| 127 | def add_package_files( | 129 | def add_package_files( |
| @@ -462,6 +464,8 @@ def create_spdx(d): | |||
| 462 | build_objset = oe.sbom30.ObjectSet.new_objset(d, d.getVar("PN")) | 464 | build_objset = oe.sbom30.ObjectSet.new_objset(d, d.getVar("PN")) |
| 463 | 465 | ||
| 464 | build = build_objset.new_task_build("recipe", "recipe") | 466 | build = build_objset.new_task_build("recipe", "recipe") |
| 467 | build_objset.set_element_alias(build) | ||
| 468 | |||
| 465 | build_objset.doc.rootElement.append(build) | 469 | build_objset.doc.rootElement.append(build) |
| 466 | 470 | ||
| 467 | build_objset.set_is_native(is_native) | 471 | build_objset.set_is_native(is_native) |
| @@ -603,7 +607,7 @@ def create_spdx(d): | |||
| 603 | set_var_field("DESCRIPTION", spdx_package, "description", package=package) | 607 | set_var_field("DESCRIPTION", spdx_package, "description", package=package) |
| 604 | 608 | ||
| 605 | pkg_objset.new_scoped_relationship( | 609 | pkg_objset.new_scoped_relationship( |
| 606 | [build._id], | 610 | [oe.sbom30.get_element_link_id(build)], |
| 607 | oe.spdx30.RelationshipType.hasOutput, | 611 | oe.spdx30.RelationshipType.hasOutput, |
| 608 | oe.spdx30.LifecycleScopeType.build, | 612 | oe.spdx30.LifecycleScopeType.build, |
| 609 | [spdx_package], | 613 | [spdx_package], |
| @@ -650,7 +654,7 @@ def create_spdx(d): | |||
| 650 | pkg_objset.new_relationship( | 654 | pkg_objset.new_relationship( |
| 651 | [spdx_package], | 655 | [spdx_package], |
| 652 | oe.spdx30.RelationshipType.hasConcludedLicense, | 656 | oe.spdx30.RelationshipType.hasConcludedLicense, |
| 653 | [package_spdx_license._id], | 657 | [oe.sbom30.get_element_link_id(package_spdx_license)], |
| 654 | ) | 658 | ) |
| 655 | 659 | ||
| 656 | # NOTE: CVE Elements live in the recipe collection | 660 | # NOTE: CVE Elements live in the recipe collection |
