create-spdx-{2.2,3.0}: support SPDX include source for work-share directory

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

(From OE-Core rev: 64454b1956a9b50d6c89a3f3d7c594c1272cb289)

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Reviewed-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Hongxu Jia
2024-10-29 22:07:44 -07:00
committed by Richard Purdie
parent 8f4759806e
commit ce192383d5
2 changed files with 23 additions and 25 deletions

View File

@@ -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)

View File

@@ -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)
src_dir = spdx_workdir + "/" + d.getVar('BP')
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)
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):