summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorPeter Kjellerstedt <peter.kjellerstedt@axis.com>2022-03-24 00:14:57 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-03-24 17:45:29 +0000
commitfb0a43cd2f0dafd568b98432070954b791f3858c (patch)
tree162ebf0e4f06376f9c02a52ff7b0c85d64fab0a1 /meta
parent1f1fcb41b4ad7c588fa4851b1eb32e2a6541b6de (diff)
downloadpoky-fb0a43cd2f0dafd568b98432070954b791f3858c.tar.gz
create-spdx.bbclass: Simplify extraction of license text
There is no reason to first search for all available licenses using avail_licenses() and then search through the same paths looking for the actual license texts. Just look for the license texts directly instead. (From OE-Core rev: 59eb405a80f0a0acf9b754b2b78399bacb0094ae) Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/create-spdx.bbclass25
1 files changed, 10 insertions, 15 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 1a4804a7c5..cae8cccd8d 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -94,7 +94,6 @@ def convert_license_to_spdx(lic, document, d, existing={}):
94 from pathlib import Path 94 from pathlib import Path
95 import oe.spdx 95 import oe.spdx
96 96
97 avail_licenses = available_licenses(d)
98 license_data = d.getVar("SPDX_LICENSE_DATA") 97 license_data = d.getVar("SPDX_LICENSE_DATA")
99 extracted = {} 98 extracted = {}
100 99
@@ -112,8 +111,8 @@ def convert_license_to_spdx(lic, document, d, existing={}):
112 if name == "PD": 111 if name == "PD":
113 # Special-case this. 112 # Special-case this.
114 extracted_info.extractedText = "Software released to the public domain" 113 extracted_info.extractedText = "Software released to the public domain"
115 elif name in avail_licenses: 114 else:
116 # This license can be found in COMMON_LICENSE_DIR or LICENSE_PATH 115 # Seach for the license in COMMON_LICENSE_DIR and LICENSE_PATH
117 for directory in [d.getVar('COMMON_LICENSE_DIR')] + (d.getVar('LICENSE_PATH') or '').split(): 116 for directory in [d.getVar('COMMON_LICENSE_DIR')] + (d.getVar('LICENSE_PATH') or '').split():
118 try: 117 try:
119 with (Path(directory) / name).open(errors="replace") as f: 118 with (Path(directory) / name).open(errors="replace") as f:
@@ -122,18 +121,14 @@ def convert_license_to_spdx(lic, document, d, existing={}):
122 except FileNotFoundError: 121 except FileNotFoundError:
123 pass 122 pass
124 if extracted_info.extractedText is None: 123 if extracted_info.extractedText is None:
125 # Error out, as the license was in avail_licenses so should 124 # If it's not SPDX or PD, then NO_GENERIC_LICENSE must be set
126 # be on disk somewhere. 125 filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
127 bb.error("Cannot find text for license %s" % name) 126 if filename:
128 else: 127 filename = d.expand("${S}/" + filename)
129 # If it's not SPDX, or PD, or in avail_licenses, then NO_GENERIC_LICENSE must be set 128 with open(filename, errors="replace") as f:
130 filename = d.getVarFlag('NO_GENERIC_LICENSE', name) 129 extracted_info.extractedText = f.read()
131 if filename: 130 else:
132 filename = d.expand("${S}/" + filename) 131 bb.error("Cannot find any text for license %s" % name)
133 with open(filename, errors="replace") as f:
134 extracted_info.extractedText = f.read()
135 else:
136 bb.error("Cannot find any text for license %s" % name)
137 132
138 extracted[name] = extracted_info 133 extracted[name] = extracted_info
139 document.hasExtractedLicensingInfos.append(extracted_info) 134 document.hasExtractedLicensingInfos.append(extracted_info)