summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2024-08-02 10:26:28 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-08-07 15:47:15 +0100
commita211f058cc3a5673d8e686b9e6e8fcf1e7cd972b (patch)
treea4f9de9e79332521a477df5fc56e8cbc15a1a6b7 /meta/lib
parent7355465f9ead0c4969adbfc167d7f29d0ca1fc11 (diff)
downloadpoky-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/lib')
-rw-r--r--meta/lib/oe/sbom30.py8
-rw-r--r--meta/lib/oe/spdx30_tasks.py17
-rw-r--r--meta/lib/oe/spdx_common.py5
3 files changed, 17 insertions, 13 deletions
diff --git a/meta/lib/oe/sbom30.py b/meta/lib/oe/sbom30.py
index 27ed74f810..2cea56ac3e 100644
--- a/meta/lib/oe/sbom30.py
+++ b/meta/lib/oe/sbom30.py
@@ -558,8 +558,8 @@ class ObjectSet(oe.spdx30.SHACLObjectSet):
558 scope=scope, 558 scope=scope,
559 ) 559 )
560 560
561 def new_license_expression(self, license_expression, license_text_map={}): 561 def new_license_expression(self, license_expression, license_data, license_text_map={}):
562 license_list_version = self.d.getVar("SPDX_LICENSE_DATA")["licenseListVersion"] 562 license_list_version = license_data["licenseListVersion"]
563 # SPDX 3 requires that the license list version be a semver 563 # SPDX 3 requires that the license list version be a semver
564 # MAJOR.MINOR.MICRO, but the actual license version might be 564 # MAJOR.MINOR.MICRO, but the actual license version might be
565 # MAJOR.MINOR on some older versions. As such, manually append a .0 565 # MAJOR.MINOR on some older versions. As such, manually append a .0
@@ -607,14 +607,14 @@ class ObjectSet(oe.spdx30.SHACLObjectSet):
607 607
608 return lic 608 return lic
609 609
610 def scan_declared_licenses(self, spdx_file, filepath): 610 def scan_declared_licenses(self, spdx_file, filepath, license_data):
611 for e in spdx_file.extension: 611 for e in spdx_file.extension:
612 if isinstance(e, OELicenseScannedExtension): 612 if isinstance(e, OELicenseScannedExtension):
613 return 613 return
614 614
615 file_licenses = set() 615 file_licenses = set()
616 for extracted_lic in oe.spdx_common.extract_licenses(filepath): 616 for extracted_lic in oe.spdx_common.extract_licenses(filepath):
617 file_licenses.add(self.new_license_expression(extracted_lic)) 617 file_licenses.add(self.new_license_expression(extracted_lic, license_data))
618 618
619 self.new_relationship( 619 self.new_relationship(
620 [spdx_file], 620 [spdx_file],
diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index 9d5bbadc0f..03dc47db02 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -28,8 +28,7 @@ def set_timestamp_now(d, o, prop):
28 delattr(o, prop) 28 delattr(o, prop)
29 29
30 30
31def add_license_expression(d, objset, license_expression): 31def add_license_expression(d, objset, license_expression, license_data):
32 license_data = d.getVar("SPDX_LICENSE_DATA")
33 simple_license_text = {} 32 simple_license_text = {}
34 license_text_map = {} 33 license_text_map = {}
35 license_ref_idx = 0 34 license_ref_idx = 0
@@ -120,7 +119,7 @@ def add_license_expression(d, objset, license_expression):
120 ) 119 )
121 spdx_license_expression = " ".join(convert(l) for l in lic_split) 120 spdx_license_expression = " ".join(convert(l) for l in lic_split)
122 121
123 return objset.new_license_expression(spdx_license_expression, license_text_map) 122 return objset.new_license_expression(spdx_license_expression, license_data, license_text_map)
124 123
125 124
126def add_package_files( 125def add_package_files(
@@ -129,6 +128,7 @@ def add_package_files(
129 topdir, 128 topdir,
130 get_spdxid, 129 get_spdxid,
131 get_purposes, 130 get_purposes,
131 license_data,
132 *, 132 *,
133 archive=None, 133 archive=None,
134 ignore_dirs=[], 134 ignore_dirs=[],
@@ -165,7 +165,7 @@ def add_package_files(
165 spdx_files.add(spdx_file) 165 spdx_files.add(spdx_file)
166 166
167 if oe.spdx30.software_SoftwarePurpose.source in file_purposes: 167 if oe.spdx30.software_SoftwarePurpose.source in file_purposes:
168 objset.scan_declared_licenses(spdx_file, filepath) 168 objset.scan_declared_licenses(spdx_file, filepath, license_data)
169 169
170 if archive is not None: 170 if archive is not None:
171 with filepath.open("rb") as f: 171 with filepath.open("rb") as f:
@@ -452,6 +452,8 @@ def create_spdx(d):
452 if val: 452 if val:
453 setattr(obj, name, val) 453 setattr(obj, name, val)
454 454
455 license_data = oe.spdx_common.load_spdx_license_data(d)
456
455 deploydir = Path(d.getVar("SPDXDEPLOY")) 457 deploydir = Path(d.getVar("SPDXDEPLOY"))
456 deploy_dir_spdx = Path(d.getVar("DEPLOY_DIR_SPDX")) 458 deploy_dir_spdx = Path(d.getVar("DEPLOY_DIR_SPDX"))
457 spdx_workdir = Path(d.getVar("SPDXWORK")) 459 spdx_workdir = Path(d.getVar("SPDXWORK"))
@@ -508,7 +510,7 @@ def create_spdx(d):
508 source_files = add_download_files(d, build_objset) 510 source_files = add_download_files(d, build_objset)
509 build_inputs |= source_files 511 build_inputs |= source_files
510 512
511 recipe_spdx_license = add_license_expression(d, build_objset, d.getVar("LICENSE")) 513 recipe_spdx_license = add_license_expression(d, build_objset, d.getVar("LICENSE"), license_data)
512 build_objset.new_relationship( 514 build_objset.new_relationship(
513 source_files, 515 source_files,
514 oe.spdx30.RelationshipType.hasConcludedLicense, 516 oe.spdx30.RelationshipType.hasConcludedLicense,
@@ -527,6 +529,7 @@ def create_spdx(d):
527 "sourcefile", str(file_counter) 529 "sourcefile", str(file_counter)
528 ), 530 ),
529 lambda filepath: [oe.spdx30.software_SoftwarePurpose.source], 531 lambda filepath: [oe.spdx30.software_SoftwarePurpose.source],
532 license_data,
530 ignore_dirs=[".git"], 533 ignore_dirs=[".git"],
531 ignore_top_level_dirs=["temp"], 534 ignore_top_level_dirs=["temp"],
532 archive=None, 535 archive=None,
@@ -636,7 +639,7 @@ def create_spdx(d):
636 package_license = d.getVar("LICENSE:%s" % package) 639 package_license = d.getVar("LICENSE:%s" % package)
637 if package_license and package_license != d.getVar("LICENSE"): 640 if package_license and package_license != d.getVar("LICENSE"):
638 package_spdx_license = add_license_expression( 641 package_spdx_license = add_license_expression(
639 d, build_objset, package_license 642 d, build_objset, package_license, license_data
640 ) 643 )
641 else: 644 else:
642 package_spdx_license = recipe_spdx_license 645 package_spdx_license = recipe_spdx_license
@@ -708,6 +711,7 @@ def create_spdx(d):
708 ), 711 ),
709 # TODO: Can we know the purpose here? 712 # TODO: Can we know the purpose here?
710 lambda filepath: [], 713 lambda filepath: [],
714 license_data,
711 ignore_top_level_dirs=["CONTROL", "DEBIAN"], 715 ignore_top_level_dirs=["CONTROL", "DEBIAN"],
712 archive=None, 716 archive=None,
713 ) 717 )
@@ -739,6 +743,7 @@ def create_spdx(d):
739 d.expand("${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}"), 743 d.expand("${COMPONENTS_DIR}/${PACKAGE_ARCH}/${PN}"),
740 lambda file_counter: build_objset.new_spdxid("sysroot", str(file_counter)), 744 lambda file_counter: build_objset.new_spdxid("sysroot", str(file_counter)),
741 lambda filepath: [], 745 lambda filepath: [],
746 license_data,
742 archive=None, 747 archive=None,
743 ) 748 )
744 749
diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index f23100fe03..dfe90f96cf 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -42,14 +42,13 @@ def is_work_shared_spdx(d):
42 42
43 43
44def load_spdx_license_data(d): 44def load_spdx_license_data(d):
45 if d.getVar("SPDX_LICENSE_DATA"):
46 return
47 45
48 with open(d.getVar("SPDX_LICENSES"), "r") as f: 46 with open(d.getVar("SPDX_LICENSES"), "r") as f:
49 data = json.load(f) 47 data = json.load(f)
50 # Transform the license array to a dictionary 48 # Transform the license array to a dictionary
51 data["licenses"] = {l["licenseId"]: l for l in data["licenses"]} 49 data["licenses"] = {l["licenseId"]: l for l in data["licenses"]}
52 d.setVar("SPDX_LICENSE_DATA", data) 50
51 return data
53 52
54 53
55def process_sources(d): 54def process_sources(d):