diff mbox series

[V3,5/6] create-spdx-{2.2,3.0}: support SPDX include source for work-share directory

Message ID 20241030050745.3702603-6-hongxu.jia@windriver.com
State Accepted, archived
Commit 64454b1956a9b50d6c89a3f3d7c594c1272cb289
Headers show
Series Support SPDX include source for work-share directory | expand

Commit Message

Hongxu Jia Oct. 30, 2024, 5:07 a.m. UTC
Originally, while SPDX_INCLUDE_SOURCES = "1" [1], there is bug in scan
for gcc, libgcc in which the sources locates in work-share directory.
Copy source from ${WORKDIR} to ${SPDXWORK} did not satisfy the situation
while ${S} was not included in ${WORKDIR}

This commit aim to support SPDX include source for work-share directory

1. If is_work_shared_spdx, Copy source from ${S} to ${SPDXWORK},
normally the dest dir in ${SPDXWORK} has the same basename dir of ${S};
but for kernel source, rename basename dir 'kernel-source' to ${BP} (${BPN}-${PV})

2. For SPDX source copy, do hard link copy to save copy time

3. Move do_patch to no work shared situation along with do_unpack

4. Tweak task do_create_spdx dependencies to assure the patched source
in work share is ready for SPDX source copy

5. Remove bb.data.inherits_class('kernel', d) from is_work_shared_spdx,
the kernel source locates in 'work-shared', test kernel.bbclass is not
necessary

[1] https://docs.yoctoproject.org/dev/ref-manual/variables.html#term-SPDX_INCLUDE_SOURCES

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/classes/spdx-common.bbclass |  9 +++++++
 meta/lib/oe/spdx_common.py       | 41 ++++++++++++--------------------
 2 files changed, 24 insertions(+), 26 deletions(-)

Comments

Joshua Watt Oct. 31, 2024, 8:34 p.m. UTC | #1
LGTM

Reviewed-by: Joshua Watt <JPEWhacker@gmail.com>

On Tue, Oct 29, 2024 at 11:07 PM Hongxu Jia <hongxu.jia@windriver.com> wrote:
>
> Originally, while SPDX_INCLUDE_SOURCES = "1" [1], there is bug in scan
> for gcc, libgcc in which the sources locates in work-share directory.
> Copy source from ${WORKDIR} to ${SPDXWORK} did not satisfy the situation
> while ${S} was not included in ${WORKDIR}
>
> This commit aim to support SPDX include source for work-share directory
>
> 1. If is_work_shared_spdx, Copy source from ${S} to ${SPDXWORK},
> normally the dest dir in ${SPDXWORK} has the same basename dir of ${S};
> but for kernel source, rename basename dir 'kernel-source' to ${BP} (${BPN}-${PV})
>
> 2. For SPDX source copy, do hard link copy to save copy time
>
> 3. Move do_patch to no work shared situation along with do_unpack
>
> 4. Tweak task do_create_spdx dependencies to assure the patched source
> in work share is ready for SPDX source copy
>
> 5. Remove bb.data.inherits_class('kernel', d) from is_work_shared_spdx,
> the kernel source locates in 'work-shared', test kernel.bbclass is not
> necessary
>
> [1] https://docs.yoctoproject.org/dev/ref-manual/variables.html#term-SPDX_INCLUDE_SOURCES
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/classes/spdx-common.bbclass |  9 +++++++
>  meta/lib/oe/spdx_common.py       | 41 ++++++++++++--------------------
>  2 files changed, 24 insertions(+), 26 deletions(-)
>
> diff --git a/meta/classes/spdx-common.bbclass b/meta/classes/spdx-common.bbclass
> index ad02da5cd6..d3cdc8b6ce 100644
> --- a/meta/classes/spdx-common.bbclass
> +++ b/meta/classes/spdx-common.bbclass
> @@ -57,6 +57,15 @@ def create_spdx_source_deps(d):
>              if oe.spdx_common.has_task(d, "do_shared_workdir"):
>                  deps.append("%s:do_shared_workdir" % pn)
>
> +            # For gcc-source-${PV} source code
> +            if oe.spdx_common.has_task(d, "do_preconfigure"):
> +                deps.append("%s:do_preconfigure" % pn)
> +            elif oe.spdx_common.has_task(d, "do_patch"):
> +                deps.append("%s:do_patch" % pn)
> +            # For gcc-cross-x86_64 source code
> +            elif oe.spdx_common.has_task(d, "do_configure"):
> +                deps.append("%s:do_configure" % pn)
> +
>      return " ".join(deps)
>
>
> diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
> index 7a85579f64..ff18d91780 100644
> --- a/meta/lib/oe/spdx_common.py
> +++ b/meta/lib/oe/spdx_common.py
> @@ -38,7 +38,7 @@ def extract_licenses(filename):
>
>
>  def is_work_shared_spdx(d):
> -    return bb.data.inherits_class("kernel", d) or ("work-shared" in d.getVar("WORKDIR"))
> +    return '/work-shared/' in d.getVar('S')
>
>
>  def load_spdx_license_data(d):
> @@ -74,11 +74,6 @@ def process_sources(d):
>      if d.getVar("PN") == "shadow-sysroot":
>          return False
>
> -    # We just archive gcc-source for all the gcc related recipes
> -    if d.getVar("BPN") in ["gcc", "libgcc"]:
> -        bb.debug(1, "spdx: There is bug in scan of %s is, do nothing" % pn)
> -        return False
> -
>      return True
>
>
> @@ -190,34 +185,28 @@ def get_patched_src(d):
>              bb.utils.mkdirhier(d.getVar("B"))
>
>              bb.build.exec_func("do_unpack", d)
> -        # Copy source of kernel to spdx_workdir
> +
> +            if d.getVar("SRC_URI") != "":
> +                bb.build.exec_func("do_patch", d)
> +
> +        # Copy source from work-share to spdx_workdir
>          if is_work_shared_spdx(d):
> -            share_src = d.getVar("WORKDIR")
> +            share_src = d.getVar('S')
>              d.setVar("WORKDIR", spdx_workdir)
>              d.setVar("STAGING_DIR_NATIVE", spdx_sysroot_native)
> +            # Copy source to ${SPDXWORK}, same basename dir of ${S};
>              src_dir = (
>                  spdx_workdir
>                  + "/"
> -                + d.getVar("PN")
> -                + "-"
> -                + d.getVar("PV")
> -                + "-"
> -                + d.getVar("PR")
> +                + os.path.basename(share_src)
>              )
> -            bb.utils.mkdirhier(src_dir)
> +            # For kernel souce, rename suffix dir 'kernel-source'
> +            # to ${BP} (${BPN}-${PV})
>              if bb.data.inherits_class("kernel", d):
> -                share_src = d.getVar("STAGING_KERNEL_DIR")
> -            cmd_copy_share = "cp -rf " + share_src + "/* " + src_dir + "/"
> -            cmd_copy_shared_res = os.popen(cmd_copy_share).read()
> -            bb.note("cmd_copy_shared_result = " + cmd_copy_shared_res)
> -
> -            git_path = src_dir + "/.git"
> -            if os.path.exists(git_path):
> -                shutils.rmtree(git_path)
> -
> -        # Make sure gcc and kernel sources are patched only once
> -        if not (d.getVar("SRC_URI") == "" or is_work_shared_spdx(d)):
> -            bb.build.exec_func("do_patch", d)
> +                src_dir = spdx_workdir + "/" + d.getVar('BP')
> +
> +            bb.note(f"copyhardlinktree {share_src} to {src_dir}")
> +            oe.path.copyhardlinktree(share_src, src_dir)
>
>          # Some userland has no source.
>          if not os.path.exists(spdx_workdir):
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/meta/classes/spdx-common.bbclass b/meta/classes/spdx-common.bbclass
index ad02da5cd6..d3cdc8b6ce 100644
--- a/meta/classes/spdx-common.bbclass
+++ b/meta/classes/spdx-common.bbclass
@@ -57,6 +57,15 @@  def create_spdx_source_deps(d):
             if oe.spdx_common.has_task(d, "do_shared_workdir"):
                 deps.append("%s:do_shared_workdir" % pn)
 
+            # For gcc-source-${PV} source code
+            if oe.spdx_common.has_task(d, "do_preconfigure"):
+                deps.append("%s:do_preconfigure" % pn)
+            elif oe.spdx_common.has_task(d, "do_patch"):
+                deps.append("%s:do_patch" % pn)
+            # For gcc-cross-x86_64 source code
+            elif oe.spdx_common.has_task(d, "do_configure"):
+                deps.append("%s:do_configure" % pn)
+
     return " ".join(deps)
 
 
diff --git a/meta/lib/oe/spdx_common.py b/meta/lib/oe/spdx_common.py
index 7a85579f64..ff18d91780 100644
--- a/meta/lib/oe/spdx_common.py
+++ b/meta/lib/oe/spdx_common.py
@@ -38,7 +38,7 @@  def extract_licenses(filename):
 
 
 def is_work_shared_spdx(d):
-    return bb.data.inherits_class("kernel", d) or ("work-shared" in d.getVar("WORKDIR"))
+    return '/work-shared/' in d.getVar('S')
 
 
 def load_spdx_license_data(d):
@@ -74,11 +74,6 @@  def process_sources(d):
     if d.getVar("PN") == "shadow-sysroot":
         return False
 
-    # We just archive gcc-source for all the gcc related recipes
-    if d.getVar("BPN") in ["gcc", "libgcc"]:
-        bb.debug(1, "spdx: There is bug in scan of %s is, do nothing" % pn)
-        return False
-
     return True
 
 
@@ -190,34 +185,28 @@  def get_patched_src(d):
             bb.utils.mkdirhier(d.getVar("B"))
 
             bb.build.exec_func("do_unpack", d)
-        # Copy source of kernel to spdx_workdir
+
+            if d.getVar("SRC_URI") != "":
+                bb.build.exec_func("do_patch", d)
+
+        # Copy source from work-share to spdx_workdir
         if is_work_shared_spdx(d):
-            share_src = d.getVar("WORKDIR")
+            share_src = d.getVar('S')
             d.setVar("WORKDIR", spdx_workdir)
             d.setVar("STAGING_DIR_NATIVE", spdx_sysroot_native)
+            # Copy source to ${SPDXWORK}, same basename dir of ${S};
             src_dir = (
                 spdx_workdir
                 + "/"
-                + d.getVar("PN")
-                + "-"
-                + d.getVar("PV")
-                + "-"
-                + d.getVar("PR")
+                + os.path.basename(share_src)
             )
-            bb.utils.mkdirhier(src_dir)
+            # For kernel souce, rename suffix dir 'kernel-source'
+            # to ${BP} (${BPN}-${PV})
             if bb.data.inherits_class("kernel", d):
-                share_src = d.getVar("STAGING_KERNEL_DIR")
-            cmd_copy_share = "cp -rf " + share_src + "/* " + src_dir + "/"
-            cmd_copy_shared_res = os.popen(cmd_copy_share).read()
-            bb.note("cmd_copy_shared_result = " + cmd_copy_shared_res)
-
-            git_path = src_dir + "/.git"
-            if os.path.exists(git_path):
-                shutils.rmtree(git_path)
-
-        # Make sure gcc and kernel sources are patched only once
-        if not (d.getVar("SRC_URI") == "" or is_work_shared_spdx(d)):
-            bb.build.exec_func("do_patch", d)
+                src_dir = spdx_workdir + "/" + d.getVar('BP')
+
+            bb.note(f"copyhardlinktree {share_src} to {src_dir}")
+            oe.path.copyhardlinktree(share_src, src_dir)
 
         # Some userland has no source.
         if not os.path.exists(spdx_workdir):