From: "Ross Burton" <ross@burtonini.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH v2 1/4] create-spdx: transform license list into a dict for faster lookups
Date: Fri, 3 Sep 2021 17:00:30 +0100 [thread overview]
Message-ID: <20210903160033.3141022-1-ross.burton@arm.com> (raw)
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
next reply other threads:[~2021-09-03 16:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-03 16:00 Ross Burton [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210903160033.3141022-1-ross.burton@arm.com \
--to=ross@burtonini.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.