diff mbox series

[RFC,3/3] spdx_common: In get_patched_src() ensure kernel dir name to be ${BP}

Message ID 20260727-fix-get-patched-src-v1-3-f5054ca10e14@bootlin.com
State New
Headers show
Series spdx_common: improve get_patched_src() | expand

Commit Message

Benjamin Robin July 27, 2026, 8:34 a.m. UTC
If a kernel recipe is using a tar file instead of git repository, it is
necessary to override `S` to point to the unpacked tar archive.
In this case `${S}` is not going to be in work-shared. So we must handle
this case in get_patched_src() to ensure that the kernel is extracted in
the following path: `${SPDXWORK}/${BP}`.

For a full detailed analysis see [1], but in summary this change is
necessary because:
- In `save_debugsources_info()` the sources are extracted from the debug
  symbol. For the kernel Linux the source file path is modified to look
  like `${BP}/init/main.c` (`${KERNEL_SRC_PATH}` is replaced by `${BP}`).
- In `get_patched_src()` the sources of the recipe are extracted (again)
  in a sub-directory of `${SPDXWORK}`. If `${S}` is in work-shared and if
  the recipe inherits the kernel class, then the sources are extracted in
  `${SPDXWORK}/${BP}`.
- In `add_package_files()`, with topdir equal to `${SPDXWORK}`, all the
  files (recursively) found in topdir are listed. For each source file,
  if the file path (relative to topdir) is in the list of source files
  retrieved by save_debugsources_info, then the file is added to the SPDX
  SBoM.
- If we are using a tar archive, `${S}` is set for example to
  `${UNPACKDIR}/linux-${PV}`, so in `get_patched_src()` the sources are
  extracted in `${SPDXWORK}/sources/linux-${PV}` since
  `UNPACKDIR = ${WORKDIR}/sources`. `${BP}/init/main.c` is not in
  `${SPDXWORK}`, but `sources/linux-${PV}/init/main.c` is.

[1] https://github.com/bootlin/yocto-kiss/pull/26#discussion_r3626224833

Signed-off-by: Benjamin Robin <benjamin.robin@bootlin.com>
---
 meta/lib/oe/spdx_common.py | 8 ++++++++
 1 file changed, 8 insertions(+)
diff mbox series

Patch

diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index 013f23ae7c65..e40cf36bba18 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -187,6 +187,14 @@  def get_patched_src(d):
                 bb.build.exec_func("do_convert_crlf_to_lf", localdata)
             bb.build.exec_func("do_patch", localdata)
 
+        if bb.data.inherits_class("kernel", localdata):
+            # For kernel source, rename suffix dir to ${BP} (${BPN}-${PV})
+            dir_name = localdata.getVar("BP")
+            kernel_dst_path = f"{spdx_workdir}/{dir_name}"
+            kernel_src_path = localdata.getVar("S")
+            if not os.path.exists(kernel_dst_path):
+                shutil.move(kernel_src_path, kernel_dst_path)
+
     # Copy source from work-shared to spdx_workdir
     else:
         share_src = d.getVar("S")