Skip to contentSkip to conversation

package: no longer modify paths in save_debugsources_info()

PATCH New Benjamin Robin 1 participant 1 message Aug 22

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 package: no longer modify paths in save_debugsources_info()

The source files saved in ${PN}-debugsources.json.zstd are now saved as
is: "/usr/src/kernel/" is no longer replaced by "${BP}/". However, the file list is still filtered to exclude "<internal>" or "<built-in>", ...

With this modification, the content of ${PN}-debugsources.json.zstd is no longer specific or tied to SPDX generation.

The logic that modified the source file paths to match what SPDX generation expects is now in oe.spdx_common.get_compiled_sources().

Furthermore, previously, for all non-kernel recipes the source paths were never "resolved", since the KERNEL_SRC_PATH variable is always defined. So the returned source file paths always started with /usr/src/debug/${PN}/${PV} (the value of TARGET_DBGSRC_DIR).

Update the source file paths to match what the SPDX generation expects:
- In get_patched_src(), the sources of the recipe are extracted (again). The unpack task runs in a modified local context with UNPACKDIR set to the value of ${SPDXWORK}, so the sources end up extracted in a sub-directory of ${SPDXWORK}.
- In add_package_files(), all files below topdir, set to ${SPDXWORK}, are (recursively) listed. For each source file, if its path (relative to topdir) is in the list returned by get_compiled_sources(), the file is added to the SPDX SBoM.

Handle this by replacing ${TARGET_DBGSRC_DIR} with the relative path of ${S} relative to ${UNPACKDIR}. If ${S} is not relative to ${UNPACKDIR}, do nothing.

---
The overall goal of this series is to fix SPDX SBoM generation in such a way that it correctly includes compiled sources for "normal" recipes (a recipe which does not inherit the kernel class).

This was tested with the busybox recipe. The following command list the effective list of compiled sources.

python3 -m json.tool \
tmp/deploy/spdx/3.0.1/cortexa15t2hf-neon/builds/build-busybox.spdx.json | \
grep -F '.c"'

This is the same list (however without the same prefix) as the extracted sources from the debug symbol:

zstdcat tmp/pkgdata/qemuarm/debugsources/busybox-debugsources.json.zstd | \
python3 -m json.tool
---
Changes in v2:
- No longer modify the source file paths in debugsources.json.zstd
- Move the logic in oe.spdx_common.get_compiled_sources()
- Link to v1: https://patch.msgid.link/20260810-fix-save-debugsources-info-v1-0-2e83131bcf01@bootlin.com

---
 meta/lib/oe/package.py     | 54 +++++++++++++++++++++-------------------------
 meta/lib/oe/spdx_common.py | 42 ++++++++++++++++++++++++++++++------
 2 files changed, 61 insertions(+), 35 deletions(-)
meta/lib/oe/package.py +25 -29
index 4a244ec9801e..551681d4e153 100644
@@ -1088,37 +1088,33 @@ def copydebugsources(debugsrcdir, sources, d):
                 os.rmdir(p)
 
 @bb.parse.vardepsexclude("BB_NUMBER_THREADS")
-def save_debugsources_info(debugsrcdir, sources_raw, d):
+def save_debugsources_info(sources_raw, d):
     import json
     import bb.compress.zstd
-    if debugsrcdir and sources_raw:
-        debugsources_file = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
-        debugsources_dir = os.path.dirname(debugsources_file)
-        if not os.path.isdir(debugsources_dir):
-            bb.utils.mkdirhier(debugsources_dir)
-        bb.utils.remove(debugsources_file)
 
-        workdir = d.getVar("WORKDIR")
-        pn = d.getVar('PN')
-
-        # Kernel sources are in a different directory and are special case
-        # we format the sources as expected by spdx by replacing /usr/src/kernel/
-        # into BP/
-        kernel_src = d.getVar('KERNEL_SRC_PATH')
-        bp = d.getVar('BP')
-        sources_dict = {}
-        for file, src_files in sources_raw:
-            file_clean = file.replace(f"{workdir}/package/","")
-            sources_clean = [
-                src.replace(f"{debugsrcdir}/{pn}/", "")
-                if not kernel_src else src.replace(f"{kernel_src}/", f"{bp}/")
-                for src in src_files
-                if not any(keyword in src for keyword in ("<internal>", "<built-in>")) and not src.endswith("/")
-            ]
-            sources_dict[file_clean] = sorted(sources_clean)
-        num_threads = int(d.getVar("BB_NUMBER_THREADS"))
-        with bb.compress.zstd.open(debugsources_file, "wt", encoding="utf-8", num_threads=num_threads) as f:
-            json.dump(sources_dict, f, sort_keys=True)
+    if not sources_raw:
+        return
+
+    debugsources_file = d.expand("${PKGDESTWORK}/debugsources/${PN}-debugsources.json.zstd")
+    debugsources_dir = os.path.dirname(debugsources_file)
+    if not os.path.isdir(debugsources_dir):
+        bb.utils.mkdirhier(debugsources_dir)
+    bb.utils.remove(debugsources_file)
+
+    workdir = d.getVar("WORKDIR")
+
+    def _filter_src_file(src):
+        if src.endswith("/"):
+            return False
+        return not any(keyword in src for keyword in ("<internal>", "<built-in>"))
+
+    sources_dict = {}
+    for file, src_files in sources_raw:
+        file_clean = file.replace(f"{workdir}/package/", "")
+        sources_dict[file_clean] = sorted(filter(_filter_src_file, src_files))
+    num_threads = int(d.getVar("BB_NUMBER_THREADS"))
+    with bb.compress.zstd.open(debugsources_file, "wt", encoding="utf-8", num_threads=num_threads) as f:
+        json.dump(sources_dict, f, sort_keys=True)
 
 @bb.parse.vardepsexclude("BB_NUMBER_THREADS")
 def read_debugsources_info(d):
@@ -1364,7 +1360,7 @@ def process_split_and_strip_files(d):
         copydebugsources(dv["srcdir"], sources, d)
 
         # Save source info to be accessible to other tasks
-        save_debugsources_info(dv["srcdir"], results, d)
+        save_debugsources_info(results, d)
     #
     # End of debug splitting
     #
meta/lib/oe/spdx_common.py +36 -6

50 lines not on this page · raw message

---
base-commit: 7944665886cb0bf881807a5d849ebdf42a33d1bf
change-id: 20260810-fix-save-debugsources-info-b8d0ac4ea206

Best regards,

Signature · 1 line
Benjamin Robin <[email protected]>