diff options
author | Ross Burton <ross@burtonini.com> | 2021-09-03 17:00:30 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-09-04 08:44:11 +0100 |
commit | 3c9102f3b63a1191b6d01b017b2da1067cbda037 (patch) | |
tree | 6f773953a1fe043e5779d83c5ebff12071b8531b | |
parent | 2cca28cfdee9ccca1046a4aaa937d38f8f115d05 (diff) | |
download | poky-3c9102f3b63a1191b6d01b017b2da1067cbda037.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.
(From OE-Core rev: 3405d9114ca9fe4ba820e0025c91670d1a5150b1)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r-- | meta/classes/create-spdx.bbclass | 15 |
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() { | |||
44 | return | 44 | return |
45 | 45 | ||
46 | with open(d.getVar("SPDX_LICENSES"), "r") as f: | 46 | with open(d.getVar("SPDX_LICENSES"), "r") as f: |
47 | d.setVar("SPDX_LICENSE_DATA", json.load(f)) | 47 | data = json.load(f) |
48 | # Transform the license array to a dictionary | ||
49 | data["licenses"] = {l["licenseId"]: l for l in data["licenses"]} | ||
50 | d.setVar("SPDX_LICENSE_DATA", data) | ||
48 | } | 51 | } |
49 | 52 | ||
50 | def convert_license_to_spdx(lic, document, d): | 53 | def convert_license_to_spdx(lic, document, d): |
@@ -55,9 +58,8 @@ def convert_license_to_spdx(lic, document, d): | |||
55 | def add_extracted_license(ident, name, text): | 58 | def add_extracted_license(ident, name, text): |
56 | nonlocal document | 59 | nonlocal document |
57 | 60 | ||
58 | for lic_data in license_data["licenses"]: | 61 | if ident in license_data["licenses"]: |
59 | if lic_data["licenseId"] == ident: | 62 | return False |
60 | return False | ||
61 | 63 | ||
62 | spdx_lic = oe.spdx.SPDXExtractedLicensingInfo() | 64 | spdx_lic = oe.spdx.SPDXExtractedLicensingInfo() |
63 | spdx_lic.name = name | 65 | spdx_lic.name = name |
@@ -79,9 +81,8 @@ def convert_license_to_spdx(lic, document, d): | |||
79 | return "OR" | 81 | return "OR" |
80 | 82 | ||
81 | spdx_license = d.getVarFlag("SPDXLICENSEMAP", l) or l | 83 | spdx_license = d.getVarFlag("SPDXLICENSEMAP", l) or l |
82 | for lic_data in license_data["licenses"]: | 84 | if spdx_license in license_data["licenses"]: |
83 | if lic_data["licenseId"] == spdx_license: | 85 | return spdx_license |
84 | return spdx_license | ||
85 | 86 | ||
86 | spdx_license = "LicenseRef-" + l | 87 | spdx_license = "LicenseRef-" + l |
87 | 88 | ||