aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoss Burton <ross@burtonini.com>2021-09-03 17:00:32 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-09-03 18:10:54 +0100
commitc638f4ae579520cab8cf30e1b4306bd0e2d2a788 (patch)
tree31b2912b1ea0ab14d76c8ed42aab36de7b91a47b
parent03f084251510c810c8434d9ddd459187827c1ca8 (diff)
downloadopenembedded-core-contrib-c638f4ae579520cab8cf30e1b4306bd0e2d2a788.tar.gz
openembedded-core-contrib-c638f4ae579520cab8cf30e1b4306bd0e2d2a788.tar.bz2
openembedded-core-contrib-c638f4ae579520cab8cf30e1b4306bd0e2d2a788.zip
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. 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.bbclass51
1 files changed, 37 insertions, 14 deletions
diff --git a/meta/classes/create-spdx.bbclass b/meta/classes/create-spdx.bbclass
index 529dee2291..cbb9239991 100644
--- a/meta/classes/create-spdx.bbclass
+++ b/meta/classes/create-spdx.bbclass
@@ -51,21 +51,49 @@ python() {
}
def convert_license_to_spdx(lic, document, d):
+ from pathlib import Path
import oe.spdx
+ available_licenses = d.getVar("AVAILABLE_LICENSES").split()
license_data = d.getVar("SPDX_LICENSE_DATA")
+ extracted = {}
- def add_extracted_license(ident, name, text):
+ def add_extracted_license(ident, name):
nonlocal document
- spdx_lic = oe.spdx.SPDXExtractedLicensingInfo()
- spdx_lic.name = name
- spdx_lic.licenseId = ident
- spdx_lic.extractedText = text
-
- document.hasExtractedLicensingInfos.append(spdx_lic)
+ if name in extracted:
+ return
+
+ extracted_info = oe.spdx.SPDXExtractedLicensingInfo()
+ extracted_info.name = name
+ extracted_info.licenseId = ident
+
+ if name == "PD":
+ # Special-case this.
+ extracted_info.extractedText = "Software released to the public domain"
+ elif name in available_licenses:
+ # This license can be found in COMMON_LICENSE_DIR or LICENSE_PATH
+ for directory in [d.getVar('COMMON_LICENSE_DIR')] + d.getVar('LICENSE_PATH').split():
+ try:
+ with (Path(directory) / name).open(errors="replace") as f:
+ extracted_info.extractedText = f.read()
+ break
+ except Exception as e:
+ # Error out, as the license was in available_licenses so
+ # should be on disk somewhere.
+ bb.error(f"Cannot find text for license {name}: {e}")
+ else:
+ # If it's not SPDX, or PD, or in available licenses, then NO_GENERIC_LICENSE must be set
+ filename = d.getVarFlag('NO_GENERIC_LICENSE', name)
+ if filename:
+ filename = d.expand("${S}/" + filename)
+ with open(filename, errors="replace") as f:
+ extracted_info.extractedText = f.read()
+ else:
+ bb.error(f"Cannot find any text for license {name}")
- return True
+ extracted[name] = extracted_info
+ document.hasExtractedLicensingInfos.append(extracted_info)
def convert(l):
if l == "(" or l == ")":
@@ -82,12 +110,7 @@ def convert_license_to_spdx(lic, document, d):
return spdx_license
spdx_license = "LicenseRef-" + l
-
- if l == "PD":
- add_extracted_license(spdx_license, l, "Software released to the public domain")
- elif add_extracted_license(spdx_license, l, "This software is licensed under the %s license" % l):
- pass
- #bb.warn("No SPDX License found for %s. Creating a place holder" % l)
+ add_extracted_license(spdx_license, l)
return spdx_license