From: Denis OSTERLAND-HEIM Date: Mon, 20 Jan 2025 13:04:58 +0000 (+0000) Subject: create-spdx: support line numbers X-Git-Tag: yocto-5.2~710 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e7ee19fc9e74cf042880f4bc317782482ba6f66;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git create-spdx: support line numbers LIC_FILES_CHKSUM supports begin-/endline for licenses included in for instance header files. This patch adds support for line numbers to NO_GENERIC_LICENSE, too. Signed-off-by: Denis Osterland-Heim Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Ross Burton --- diff --git a/meta/classes/create-spdx-2.2.bbclass b/meta/classes/create-spdx-2.2.bbclass index 27242ecf707..494bde117fe 100644 --- a/meta/classes/create-spdx-2.2.bbclass +++ b/meta/classes/create-spdx-2.2.bbclass @@ -75,11 +75,17 @@ def convert_license_to_spdx(lic, license_data, document, d, existing={}): pass if extracted_info.extractedText is None: # If it's not SPDX or PD, then NO_GENERIC_LICENSE must be set - filename = d.getVarFlag('NO_GENERIC_LICENSE', name) + entry = d.getVarFlag('NO_GENERIC_LICENSE', name).split(';') + filename = entry[0] + params = {i.split('=')[0]: i.split('=')[1] for i in entry[1:] if '=' in i} + beginline = int(params.get('beginline', 1)) + endline = params.get('endline', None) + if endline: + endline = int(endline) if filename: filename = d.expand("${S}/" + filename) with open(filename, errors="replace") as f: - extracted_info.extractedText = f.read() + extracted_info.extractedText = "".join(line for idx, line in enumerate(f, 1) if beginline <= idx and idx <= (endline or idx)) else: bb.fatal("Cannot find any text for license %s" % name)