summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/create-spdx-2.2.bbclass12
-rw-r--r--meta/lib/oe/spdx.py42
2 files changed, 54 insertions, 0 deletions
diff --git a/meta/classes/create-spdx-2.2.bbclass b/meta/classes/create-spdx-2.2.bbclass
index ade1a04be3..1fc11ad7ac 100644
--- a/meta/classes/create-spdx-2.2.bbclass
+++ b/meta/classes/create-spdx-2.2.bbclass
@@ -100,6 +100,9 @@ python() {
100 # Transform the license array to a dictionary 100 # Transform the license array to a dictionary
101 data["licenses"] = {l["licenseId"]: l for l in data["licenses"]} 101 data["licenses"] = {l["licenseId"]: l for l in data["licenses"]}
102 d.setVar("SPDX_LICENSE_DATA", data) 102 d.setVar("SPDX_LICENSE_DATA", data)
103
104 if d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1":
105 d.setVar("SPDX_INCLUDE_SOURCES", "1")
103} 106}
104 107
105def convert_license_to_spdx(lic, document, d, existing={}): 108def convert_license_to_spdx(lic, document, d, existing={}):
@@ -215,6 +218,11 @@ def add_package_files(d, doc, spdx_pkg, topdir, get_spdxid, get_types, *, archiv
215 spdx_files = [] 218 spdx_files = []
216 219
217 file_counter = 1 220 file_counter = 1
221
222 check_compiled_sources = d.getVar("SPDX_INCLUDE_COMPILED_SOURCES") == "1"
223 if check_compiled_sources:
224 compiled_sources, types = oe.spdx.get_compiled_sources(d)
225 bb.debug(1, f"Total compiled files: {len(compiled_sources)}")
218 for subdir, dirs, files in os.walk(topdir): 226 for subdir, dirs, files in os.walk(topdir):
219 dirs[:] = [d for d in dirs if d not in ignore_dirs] 227 dirs[:] = [d for d in dirs if d not in ignore_dirs]
220 if subdir == str(topdir): 228 if subdir == str(topdir):
@@ -225,6 +233,10 @@ def add_package_files(d, doc, spdx_pkg, topdir, get_spdxid, get_types, *, archiv
225 filename = str(filepath.relative_to(topdir)) 233 filename = str(filepath.relative_to(topdir))
226 234
227 if not filepath.is_symlink() and filepath.is_file(): 235 if not filepath.is_symlink() and filepath.is_file():
236 # Check if file is compiled
237 if check_compiled_sources:
238 if not oe.spdx.is_compiled_source(filename, compiled_sources, types):
239 continue
228 spdx_file = oe.spdx.SPDXFile() 240 spdx_file = oe.spdx.SPDXFile()
229 spdx_file.SPDXID = get_spdxid(file_counter) 241 spdx_file.SPDXID = get_spdxid(file_counter)
230 for t in get_types(filepath): 242 for t in get_types(filepath):
diff --git a/meta/lib/oe/spdx.py b/meta/lib/oe/spdx.py
index 7aaf2af5ed..92dcd2da05 100644
--- a/meta/lib/oe/spdx.py
+++ b/meta/lib/oe/spdx.py
@@ -355,3 +355,45 @@ class SPDXDocument(SPDXObject):
355 if r.spdxDocument == namespace: 355 if r.spdxDocument == namespace:
356 return r 356 return r
357 return None 357 return None
358
359def is_compiled_source (filename, compiled_sources, types):
360 """
361 Check if the file is a compiled file
362 """
363 import os
364 # If we don't have compiled source, we assume all are compiled.
365 if not compiled_sources:
366 return True
367
368 # We return always true if the file type is not in the list of compiled files.
369 # Some files in the source directory are not compiled, for example, Makefiles,
370 # but also python .py file. We need to include them in the SPDX.
371 basename = os.path.basename(filename)
372 ext = basename.partition(".")[2]
373 if ext not in types:
374 return True
375 # Check that the file is in the list
376 return filename in compiled_sources
377
378def get_compiled_sources(d):
379 """
380 Get list of compiled sources from debug information and normalize the paths
381 """
382 import itertools
383 import oe.package
384 source_info = oe.package.read_debugsources_info(d)
385 if not source_info:
386 bb.debug(1, "Do not have debugsources.list. Skipping")
387 return [], []
388
389 # Sources are not split now in SPDX, so we aggregate them
390 sources = set(itertools.chain.from_iterable(source_info.values()))
391 # Check extensions of files
392 types = set()
393 for src in sources:
394 basename = os.path.basename(src)
395 ext = basename.partition(".")[2]
396 if ext not in types and ext:
397 types.add(ext)
398 bb.debug(1, f"Num of sources: {len(sources)} and types: {len(types)} {str(types)}")
399 return sources, types