summaryrefslogtreecommitdiffstats
path: root/meta/classes/create-spdx.bbclass
diff options
context:
space:
mode:
authorRoss Burton <ross@burtonini.com>2021-09-03 16:00:32 (GMT)
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-09-04 07:44:11 (GMT)
commit41a29f0b9642668538f9e5e84db9623304b5c820 (patch)
tree01dfd6eb87c5e6a1b57fadae619ef0720782516f /meta/classes/create-spdx.bbclass
parent734f5badefd0bff6419ca94e4a5823b85149398a (diff)
downloadpoky-41a29f0b9642668538f9e5e84db9623304b5c820.tar.gz
create-spdx: embed unknown license texts
For licenses which are not known to SPDX, find and embed the actual license text in an ExtractedLicesingInfo block. (From OE-Core rev: c638f4ae579520cab8cf30e1b4306bd0e2d2a788) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/create-spdx.bbclass')
-rw-r--r--meta/classes/create-spdx.bbclass51
1 files changed, 37 insertions, 14 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 529dee2..cbb9239 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -51,21 +51,49 @@ python() {
51} 51}
52 52
53def convert_license_to_spdx(lic, document, d): 53def convert_license_to_spdx(lic, document, d):
54 from pathlib import Path
54 import oe.spdx 55 import oe.spdx
55 56
57 available_licenses = d.getVar("AVAILABLE_LICENSES").split()
56 license_data = d.getVar("SPDX_LICENSE_DATA") 58 license_data = d.getVar("SPDX_LICENSE_DATA")
59 extracted = {}
57 60
58 def add_extracted_license(ident, name, text): 61 def add_extracted_license(ident, name):
59 nonlocal document 62 nonlocal document
60 63
61 spdx_lic = oe.spdx.SPDXExtractedLicensingInfo() 64 if name in extracted:
62 spdx_lic.name = name 65 return
63 spdx_lic.licenseId = ident 66
64 spdx_lic.extractedText = text 67 extracted_info = oe.spdx.SPDXExtractedLicensingInfo()
65 68 extracted_info.name = name
66 document.hasExtractedLicensingInfos.append(spdx_lic) 69 extracted_info.licenseId = ident
70
71 if name == "PD":
72 # Special-case this.
73 extracted_info.extractedText = "Software released to the public domain"
74 elif name in available_licenses:
75 # This license can be found in COMMON_LICENSE_DIR or LICENSE_PATH
76 for directory in [d.getVar('COMMON_LICENSE_DIR')] + d.getVar('LICENSE_PATH').split():
77 try:
78 with (Path(directory) / name).open(errors="replace") as f:
79 extracted_info.extractedText = f.read()
80 break
81 except Exception as e:
82 # Error out, as the license was in available_licenses so
83 # should be on disk somewhere.
84 bb.error(f"Cannot find text for license {name}: {e}")
85 else:
86 # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set
87 filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
88 if filename:
89 filename = d.expand("${S}/" + filename)
90 with open(filename, errors="replace") as f:
91 extracted_info.extractedText = f.read()
92 else:
93 bb.error(f"Cannot find any text for license {name}")
67 94
68 return True 95 extracted[name] = extracted_info
96 document.hasExtractedLicensingInfos.append(extracted_info)
69 97
70 def convert(l): 98 def convert(l):
71 if l == "(" or l == ")": 99 if l == "(" or l == ")":
@@ -82,12 +110,7 @@ def convert_license_to_spdx(lic, document, d):
82 return spdx_license 110 return spdx_license
83 111
84 spdx_license = "LicenseRef-" + l 112 spdx_license = "LicenseRef-" + l
85 113 add_extracted_license(spdx_license, l)
86 if l == "PD":
87 add_extracted_license(spdx_license, l, "Software released to the public domain")
88 elif add_extracted_license(spdx_license, l, "This software is licensed under the %s license" % l):
89 pass
90 #bb.warn("No SPDX License found for %s. Creating a place holder" % l)
91 114
92 return spdx_license 115 return spdx_license
93 116