summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorRoss Burton <ross@burtonini.com>2021-09-03 17:00:30 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-09-03 18:10:54 +0100
commit3405d9114ca9fe4ba820e0025c91670d1a5150b1 (patch)
tree671e7fc60db76a92c9525d2847950d0fa63e5970 /meta
parente4cb21609e3e95725b235de48458ab3c111ee9c1 (diff)
downloadopenembedded-core-contrib-3405d9114ca9fe4ba820e0025c91670d1a5150b1.tar.gz
create-spdx: transform license list into a dict for faster lookups
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> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/create-spdx.bbclass15
1 files changed, 8 insertions, 7 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index a590ab596a..73ccb3c990 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