diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-08-02 10:26:28 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-08-07 15:47:15 +0100 |
commit | a211f058cc3a5673d8e686b9e6e8fcf1e7cd972b (patch) | |
tree | a4f9de9e79332521a477df5fc56e8cbc15a1a6b7 /meta/classes | |
parent | 7355465f9ead0c4969adbfc167d7f29d0ca1fc11 (diff) | |
download | poky-a211f058cc3a5673d8e686b9e6e8fcf1e7cd972b.tar.gz |
sdpx: Avoid loading of SPDX_LICENSE_DATA into global config
Loading a load of json files into a memory structure and stashing in a bitbake
variable is relatively anti-social making bitbake -e output hard to read for
example as well as other potential performance issues.
Defer loading of that data until it is actually needed/used in a funciton
where it is now passed as a parameter.
(From OE-Core rev: 6f21cc9598178288784ff451ab3c40b174c0ef3e)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/create-spdx-2.2.bbclass | 25 | ||||
-rw-r--r-- | meta/classes/spdx-common.bbclass | 6 |
2 files changed, 15 insertions, 16 deletions
diff --git a/meta/classes/create-spdx-2.2.bbclass b/meta/classes/create-spdx-2.2.bbclass index 509d3b58b6..795ba1a882 100644 --- a/meta/classes/create-spdx-2.2.bbclass +++ b/meta/classes/create-spdx-2.2.bbclass | |||
@@ -44,11 +44,10 @@ def get_json_indent(d): | |||
44 | return None | 44 | return None |
45 | 45 | ||
46 | 46 | ||
47 | def convert_license_to_spdx(lic, document, d, existing={}): | 47 | def convert_license_to_spdx(lic, license_data, document, d, existing={}): |
48 | from pathlib import Path | 48 | from pathlib import Path |
49 | import oe.spdx | 49 | import oe.spdx |
50 | 50 | ||
51 | license_data = d.getVar("SPDX_LICENSE_DATA") | ||
52 | extracted = {} | 51 | extracted = {} |
53 | 52 | ||
54 | def add_extracted_license(ident, name): | 53 | def add_extracted_license(ident, name): |
@@ -385,10 +384,10 @@ def add_download_packages(d, doc, recipe): | |||
385 | # but this should be sufficient for now | 384 | # but this should be sufficient for now |
386 | doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe) | 385 | doc.add_relationship(package, "BUILD_DEPENDENCY_OF", recipe) |
387 | 386 | ||
388 | def get_license_list_version(d): | 387 | def get_license_list_version(license_data, d): |
389 | # Newer versions of the SPDX license list are SemVer ("MAJOR.MINOR.MICRO"), | 388 | # Newer versions of the SPDX license list are SemVer ("MAJOR.MINOR.MICRO"), |
390 | # but SPDX 2 only uses "MAJOR.MINOR". | 389 | # but SPDX 2 only uses "MAJOR.MINOR". |
391 | return ".".join(d.getVar("SPDX_LICENSE_DATA")["licenseListVersion"].split(".")[:2]) | 390 | return ".".join(license_data["licenseListVersion"].split(".")[:2]) |
392 | 391 | ||
393 | 392 | ||
394 | python do_create_spdx() { | 393 | python do_create_spdx() { |
@@ -401,6 +400,8 @@ python do_create_spdx() { | |||
401 | from contextlib import contextmanager | 400 | from contextlib import contextmanager |
402 | import oe.cve_check | 401 | import oe.cve_check |
403 | 402 | ||
403 | license_data = oe.spdx_common.load_spdx_license_data(d) | ||
404 | |||
404 | @contextmanager | 405 | @contextmanager |
405 | def optional_tarfile(name, guard, mode="w"): | 406 | def optional_tarfile(name, guard, mode="w"): |
406 | import tarfile | 407 | import tarfile |
@@ -432,7 +433,7 @@ python do_create_spdx() { | |||
432 | doc.documentNamespace = get_namespace(d, doc.name) | 433 | doc.documentNamespace = get_namespace(d, doc.name) |
433 | doc.creationInfo.created = creation_time | 434 | doc.creationInfo.created = creation_time |
434 | doc.creationInfo.comment = "This document was created by analyzing recipe files during the build." | 435 | doc.creationInfo.comment = "This document was created by analyzing recipe files during the build." |
435 | doc.creationInfo.licenseListVersion = get_license_list_version(d) | 436 | doc.creationInfo.licenseListVersion = get_license_list_version(license_data, d) |
436 | doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") | 437 | doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") |
437 | doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) | 438 | doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) |
438 | doc.creationInfo.creators.append("Person: N/A ()") | 439 | doc.creationInfo.creators.append("Person: N/A ()") |
@@ -451,7 +452,7 @@ python do_create_spdx() { | |||
451 | 452 | ||
452 | license = d.getVar("LICENSE") | 453 | license = d.getVar("LICENSE") |
453 | if license: | 454 | if license: |
454 | recipe.licenseDeclared = convert_license_to_spdx(license, doc, d) | 455 | recipe.licenseDeclared = convert_license_to_spdx(license, license_data, doc, d) |
455 | 456 | ||
456 | summary = d.getVar("SUMMARY") | 457 | summary = d.getVar("SUMMARY") |
457 | if summary: | 458 | if summary: |
@@ -536,7 +537,7 @@ python do_create_spdx() { | |||
536 | package_doc.documentNamespace = get_namespace(d, package_doc.name) | 537 | package_doc.documentNamespace = get_namespace(d, package_doc.name) |
537 | package_doc.creationInfo.created = creation_time | 538 | package_doc.creationInfo.created = creation_time |
538 | package_doc.creationInfo.comment = "This document was created by analyzing packages created during the build." | 539 | package_doc.creationInfo.comment = "This document was created by analyzing packages created during the build." |
539 | package_doc.creationInfo.licenseListVersion = get_license_list_version(d) | 540 | package_doc.creationInfo.licenseListVersion = get_license_list_version(license_data, d) |
540 | package_doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") | 541 | package_doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") |
541 | package_doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) | 542 | package_doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) |
542 | package_doc.creationInfo.creators.append("Person: N/A ()") | 543 | package_doc.creationInfo.creators.append("Person: N/A ()") |
@@ -549,7 +550,7 @@ python do_create_spdx() { | |||
549 | spdx_package.SPDXID = oe.sbom.get_package_spdxid(pkg_name) | 550 | spdx_package.SPDXID = oe.sbom.get_package_spdxid(pkg_name) |
550 | spdx_package.name = pkg_name | 551 | spdx_package.name = pkg_name |
551 | spdx_package.versionInfo = d.getVar("PV") | 552 | spdx_package.versionInfo = d.getVar("PV") |
552 | spdx_package.licenseDeclared = convert_license_to_spdx(package_license, package_doc, d, found_licenses) | 553 | spdx_package.licenseDeclared = convert_license_to_spdx(package_license, license_data, package_doc, d, found_licenses) |
553 | spdx_package.supplier = d.getVar("SPDX_SUPPLIER") | 554 | spdx_package.supplier = d.getVar("SPDX_SUPPLIER") |
554 | 555 | ||
555 | package_doc.packages.append(spdx_package) | 556 | package_doc.packages.append(spdx_package) |
@@ -608,6 +609,8 @@ python do_create_runtime_spdx() { | |||
608 | 609 | ||
609 | creation_time = datetime.now(tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") | 610 | creation_time = datetime.now(tz=timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ") |
610 | 611 | ||
612 | license_data = oe.spdx_common.load_spdx_license_data(d) | ||
613 | |||
611 | providers = oe.spdx_common.collect_package_providers(d) | 614 | providers = oe.spdx_common.collect_package_providers(d) |
612 | pkg_arch = d.getVar("SSTATE_PKGARCH") | 615 | pkg_arch = d.getVar("SSTATE_PKGARCH") |
613 | package_archs = d.getVar("SPDX_MULTILIB_SSTATE_ARCHS").split() | 616 | package_archs = d.getVar("SPDX_MULTILIB_SSTATE_ARCHS").split() |
@@ -644,7 +647,7 @@ python do_create_runtime_spdx() { | |||
644 | runtime_doc.documentNamespace = get_namespace(localdata, runtime_doc.name) | 647 | runtime_doc.documentNamespace = get_namespace(localdata, runtime_doc.name) |
645 | runtime_doc.creationInfo.created = creation_time | 648 | runtime_doc.creationInfo.created = creation_time |
646 | runtime_doc.creationInfo.comment = "This document was created by analyzing package runtime dependencies." | 649 | runtime_doc.creationInfo.comment = "This document was created by analyzing package runtime dependencies." |
647 | runtime_doc.creationInfo.licenseListVersion = get_license_list_version(d) | 650 | runtime_doc.creationInfo.licenseListVersion = get_license_list_version(license_data, d) |
648 | runtime_doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") | 651 | runtime_doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") |
649 | runtime_doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) | 652 | runtime_doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) |
650 | runtime_doc.creationInfo.creators.append("Person: N/A ()") | 653 | runtime_doc.creationInfo.creators.append("Person: N/A ()") |
@@ -797,6 +800,8 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages, spdx | |||
797 | import tarfile | 800 | import tarfile |
798 | import bb.compress.zstd | 801 | import bb.compress.zstd |
799 | 802 | ||
803 | license_data = oe.spdx_common.load_spdx_license_data(d) | ||
804 | |||
800 | providers = oe.spdx_common.collect_package_providers(d) | 805 | providers = oe.spdx_common.collect_package_providers(d) |
801 | package_archs = d.getVar("SPDX_MULTILIB_SSTATE_ARCHS").split() | 806 | package_archs = d.getVar("SPDX_MULTILIB_SSTATE_ARCHS").split() |
802 | package_archs.reverse() | 807 | package_archs.reverse() |
@@ -810,7 +815,7 @@ def combine_spdx(d, rootfs_name, rootfs_deploydir, rootfs_spdxid, packages, spdx | |||
810 | doc.documentNamespace = get_namespace(d, doc.name) | 815 | doc.documentNamespace = get_namespace(d, doc.name) |
811 | doc.creationInfo.created = creation_time | 816 | doc.creationInfo.created = creation_time |
812 | doc.creationInfo.comment = "This document was created by analyzing the source of the Yocto recipe during the build." | 817 | doc.creationInfo.comment = "This document was created by analyzing the source of the Yocto recipe during the build." |
813 | doc.creationInfo.licenseListVersion = get_license_list_version(d) | 818 | doc.creationInfo.licenseListVersion = get_license_list_version(license_data, d) |
814 | doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") | 819 | doc.creationInfo.creators.append("Tool: OpenEmbedded Core create-spdx.bbclass") |
815 | doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) | 820 | doc.creationInfo.creators.append("Organization: %s" % d.getVar("SPDX_ORG")) |
816 | doc.creationInfo.creators.append("Person: N/A ()") | 821 | doc.creationInfo.creators.append("Person: N/A ()") |
diff --git a/meta/classes/spdx-common.bbclass b/meta/classes/spdx-common.bbclass index e1528b6d0b..cd9cc0db98 100644 --- a/meta/classes/spdx-common.bbclass +++ b/meta/classes/spdx-common.bbclass | |||
@@ -39,12 +39,6 @@ SPDX_CUSTOM_ANNOTATION_VARS ??= "" | |||
39 | 39 | ||
40 | SPDX_MULTILIB_SSTATE_ARCHS ??= "${SSTATE_ARCHS}" | 40 | SPDX_MULTILIB_SSTATE_ARCHS ??= "${SSTATE_ARCHS}" |
41 | 41 | ||
42 | python() { | ||
43 | import oe.spdx_common | ||
44 | oe.spdx_common.load_spdx_license_data(d) | ||
45 | } | ||
46 | |||
47 | |||
48 | python do_collect_spdx_deps() { | 42 | python do_collect_spdx_deps() { |
49 | # This task calculates the build time dependencies of the recipe, and is | 43 | # This task calculates the build time dependencies of the recipe, and is |
50 | # required because while a task can deptask on itself, those dependencies | 44 | # required because while a task can deptask on itself, those dependencies |