@@ -54,6 +54,12 @@ SPDX_CONCLUDED_LICENSE[doc] = "The license concluded by manual or external \
SPDX_MULTILIB_SSTATE_ARCHS ??= "${SSTATE_ARCHS}"
+SPDX_FILE_EXCLUDE_PATTERNS ??= ""
+SPDX_FILE_EXCLUDE_PATTERNS[doc] = "Space-separated list of patterns to exclude \
+ from SPDX file output. Files whose paths contain any of these patterns will \
+ be filtered out. Defaults to empty (no filtering). Example: \
+ SPDX_FILE_EXCLUDE_PATTERNS = '.patch .diff /test/ .pyc .o'"
+
python () {
from oe.cve_check import extend_cve_status
extend_cve_status(d)
@@ -161,6 +161,9 @@ def add_package_files(
compiled_sources, types = oe.spdx_common.get_compiled_sources(d)
bb.debug(1, f"Total compiled files: {len(compiled_sources)}")
+ # File exclusion filtering
+ exclude_patterns = (d.getVar("SPDX_FILE_EXCLUDE_PATTERNS") or "").split()
+
for subdir, dirs, files in os.walk(topdir, onerror=walk_error):
dirs[:] = [d for d in dirs if d not in ignore_dirs]
if subdir == str(topdir):
@@ -174,6 +177,13 @@ def add_package_files(
continue
filename = str(filepath.relative_to(topdir))
+
+ # Apply file exclusion filtering
+ if exclude_patterns:
+ filename_lower = filename.lower()
+ if any(pattern in filename_lower for pattern in exclude_patterns):
+ continue
+
file_purposes = get_purposes(filepath)
# Check if file is compiled
@@ -219,6 +229,8 @@ def add_package_files(
def get_package_sources_from_debug(
d, package, package_files, sources, source_hash_cache
):
+ exclude_patterns = (d.getVar("SPDX_FILE_EXCLUDE_PATTERNS") or "").split()
+
def file_path_match(file_path, pkg_file):
if file_path.lstrip("/") == pkg_file.name.lstrip("/"):
return True
@@ -251,10 +263,18 @@ def get_package_sources_from_debug(
continue
if not any(file_path_match(file_path, pkg_file) for pkg_file in package_files):
- bb.fatal(
- "No package file found for %s in %s; SPDX found: %s"
- % (str(file_path), package, " ".join(p.name for p in package_files))
- )
+ # When file exclusion patterns are active, some files may be filtered out
+ if exclude_patterns:
+ bb.debug(
+ 1,
+ f"Skipping debug source lookup for {file_path} in {package} (file exclusion active)",
+ )
+ continue
+ else:
+ bb.fatal(
+ "No package file found for %s in %s; SPDX found: %s"
+ % (str(file_path), package, " ".join(p.name for p in package_files))
+ )
continue
for debugsrc in file_data["debugsrc"]: