diff mbox series

spdx_common: fix source inclusion with externalsrc

Message ID 20261015-spdx_externalsrc-v1-1-553edd1570f2@valla.it
State New
Headers show
Series spdx_common: fix source inclusion with externalsrc | expand

Commit Message

Francesco Valla Oct. 15, 2026, 8:58 p.m. UTC
The source inclusion logic activated by SPDX_INCLUDE_SOURCES creates a
dedicated source directory and fills it either:

 - calling do_unpack and do_patch into that directory, or
 - copying sources from the work-shared directory for recipes that use
   one.

This mechanism however does not work properly when coupled with the
externalsrc class, which deletes the do_unpack and do_patch tasks as
part of its logic; one notable use case is the devtool development flow.
In this case, the following issues are observed:

  - the tools required by the removed tasks (e.g.: quilt for do_patch)
    are not included in the recipe sysroot, leading to a failure when
    the task is forcibly executed as part of the spdx source collection;
  - for a recipe inheriting kernel.bbclass, the directory hosting the
    external source is deleted (because is moved to spdx_workdir and
    then wiped) and the kernel-source symlink pointing to it is
    replaced with an empty directory.

As a solution, treat the external source directory case just like the
work-shared case, copying the source code from the externalsrc location
to the SPDX dedicated directory instead of re-unpacking it there.

It should be noted that if an in-tree build is performed while using
externalsrc (i.e., if EXTERNALSRC_BUILD is equal or under EXTERNALSRC),
build artifacts will be treated as source files and added to the
generated SPDX files.

Signed-off-by: Francesco Valla <francesco@valla.it>
---
 meta/lib/oe/spdx_common.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)


---
base-commit: 7803450fd5ecc1bb714abadfbe3ec340e930139a
change-id: 20261014-spdx_externalsrc-18d2327f0990

Best regards,
--  
Francesco Valla <francesco@valla.it>
diff mbox series

Patch

diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index ad2bc0ffda31..07bf9650e21e 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -42,6 +42,10 @@  def is_work_shared_spdx(d):
     return "/work-shared/" in d.getVar("S")
 
 
+def is_external_src_spdx(d):
+    return bb.data.inherits_class("externalsrc", d) and bool(d.getVar("EXTERNALSRC"))
+
+
 def load_spdx_license_data(d):
     with open(d.getVar("SPDX_LICENSES"), "r") as f:
         data = json.load(f)
@@ -174,8 +178,9 @@  def get_patched_src(d):
     """
     spdx_workdir = d.getVar("SPDXWORK")
 
-    # Do not unpack the sources again for the recipe using work-shared
-    if not is_work_shared_spdx(d):
+    # Do not unpack the sources again for the recipe using work-shared or an
+    # external source directory
+    if not is_work_shared_spdx(d) and not is_external_src_spdx(d):
         localdata = d.createCopy()
 
         # Change the UNPACKDIR to make do_unpack do_patch run in another dir.
@@ -196,7 +201,7 @@  def get_patched_src(d):
             if not os.path.exists(kernel_dst_path):
                 shutil.move(kernel_src_path, kernel_dst_path)
 
-    # Copy source from work-shared to spdx_workdir
+    # Copy source from work-shared or external source directory to spdx_workdir
     else:
         share_src = d.getVar("S")