All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] create-spdx: transform license list into a dict for faster lookups
@ 2021-09-03 16:00 Ross Burton
  2021-09-03 16:00 ` [PATCH v2 2/4] create-spdx: remove redundant test Ross Burton
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ross Burton @ 2021-09-03 16:00 UTC (permalink / raw)
  To: openembedded-core

spdx-licenses.json contains an array of licenses objects. As we'll be
searching it often, convert that to a dictionary when we parse it.

Signed-off-by: Ross Burton <ross.burton@arm.com>
---
 meta/classes/create-spdx.bbclass | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index a590ab596ac..73ccb3c990f 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -44,7 +44,10 @@ python() {
         return
 
     with open(d.getVar("SPDX_LICENSES"), "r") as f:
-        d.setVar("SPDX_LICENSE_DATA", json.load(f))
+        data = json.load(f)
+        # Transform the license array to a dictionary
+        data["licenses"] = {l["licenseId"]: l for l in data["licenses"]}
+        d.setVar("SPDX_LICENSE_DATA", data)
 }
 
 def convert_license_to_spdx(lic, document, d):
@@ -55,9 +58,8 @@ def convert_license_to_spdx(lic, document, d):
     def add_extracted_license(ident, name, text):
         nonlocal document
 
-        for lic_data in license_data["licenses"]:
-            if lic_data["licenseId"] == ident:
-                return False
+        if ident in license_data["licenses"]:
+            return False
 
         spdx_lic = oe.spdx.SPDXExtractedLicensingInfo()
         spdx_lic.name = name
@@ -79,9 +81,8 @@ def convert_license_to_spdx(lic, document, d):
             return "OR"
 
         spdx_license = d.getVarFlag("SPDXLICENSEMAP", l) or l
-        for lic_data in license_data["licenses"]:
-            if lic_data["licenseId"] == spdx_license:
-                return spdx_license
+        if spdx_license in license_data["licenses"]:
+            return spdx_license
 
         spdx_license = "LicenseRef-" + l
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-03 22:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-03 16:00 [PATCH v2 1/4] create-spdx: transform license list into a dict for faster lookups Ross Burton
2021-09-03 16:00 ` [PATCH v2 2/4] create-spdx: remove redundant test Ross Burton
2021-09-03 16:00 ` [PATCH v2 3/4] create-spdx: embed unknown license texts Ross Burton
2021-09-03 16:00 ` [PATCH v2 4/4] create-spex: don't duplicate license texts in each package Ross Burton
2021-09-03 22:14   ` [OE-core] " Peter Kjellerstedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.