summaryrefslogtreecommitdiffstats
path: root/meta/lib
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/spdx.py42
1 files changed, 42 insertions, 0 deletions
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