]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
create-spdx: support line numbers
authorDenis OSTERLAND-HEIM <denis.osterland@diehl.com>
Mon, 20 Jan 2025 13:04:58 +0000 (13:04 +0000)
committerRoss Burton <ross.burton@arm.com>
Thu, 23 Jan 2025 12:05:57 +0000 (12:05 +0000)
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 <denis.osterland@diehl.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Ross Burton <ross.burton@arm.com>
meta/classes/create-spdx-2.2.bbclass

index 27242ecf7076942ab2741fe11fb01d386713258f..494bde117fe9307d18638c852d67df16553bfc16 100644 (file)
@@ -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)