diff mbox series

spdx30: test the existence of directory before walking

Message ID 20250318113254.3556987-1-hongxu.jia@windriver.com
State Accepted, archived
Commit cb1792e4950d5075be9bbe4c5337a5215db9669e
Headers show
Series spdx30: test the existence of directory before walking | expand

Commit Message

Hongxu Jia March 18, 2025, 11:32 a.m. UTC
Due to commit [spdx30: Improve os.walk() handling][1] applied,
it reported an error if walk directory failed

While SPDX_INCLUDE_SOURCES = "1", if recipe does not provide sysroots,
the walk in function add_package_files is broken

$ echo 'SPDX_INCLUDE_SOURCES = "1"' >> conf/local.conf
$ bitbake packagegroup-core-boot
|DEBUG: Adding sysroot files to SPDX
|ERROR: packagegroup-core-boot-1.0-r0 do_create_spdx: ERROR walking tmp/sysroots-components/intel_x86_64/packagegroup-core-boot: [Errno 2]
| No such file or directory: 'tmp/sysroots-components/intel_x86_64/packagegroup-core-boot'

Test the existence of directory before walking

[1] https://git.openembedded.org/openembedded-core/commit/?id=86b581e80637cd8136ce7a7e95db94d9553d2f60

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
---
 meta/lib/oe/spdx30_tasks.py | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Joshua Watt March 18, 2025, 2:37 p.m. UTC | #1
LGTM, Thanks

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

On Tue, Mar 18, 2025 at 5:32 AM Hongxu Jia <hongxu.jia@windriver.com> wrote:
>
> Due to commit [spdx30: Improve os.walk() handling][1] applied,
> it reported an error if walk directory failed
>
> While SPDX_INCLUDE_SOURCES = "1", if recipe does not provide sysroots,
> the walk in function add_package_files is broken
>
> $ echo 'SPDX_INCLUDE_SOURCES = "1"' >> conf/local.conf
> $ bitbake packagegroup-core-boot
> |DEBUG: Adding sysroot files to SPDX
> |ERROR: packagegroup-core-boot-1.0-r0 do_create_spdx: ERROR walking tmp/sysroots-components/intel_x86_64/packagegroup-core-boot: [Errno 2]
> | No such file or directory: 'tmp/sysroots-components/intel_x86_64/packagegroup-core-boot'
>
> Test the existence of directory before walking
>
> [1] https://git.openembedded.org/openembedded-core/commit/?id=86b581e80637cd8136ce7a7e95db94d9553d2f60
>
> Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
> ---
>  meta/lib/oe/spdx30_tasks.py | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
> index 3d80f05612f..0618f2f139d 100644
> --- a/meta/lib/oe/spdx30_tasks.py
> +++ b/meta/lib/oe/spdx30_tasks.py
> @@ -152,6 +152,10 @@ def add_package_files(
>      spdx_files = set()
>
>      file_counter = 1
> +    if not os.path.exists(topdir):
> +        bb.note(f"Skip {topdir}")
> +        return spdx_files
> +
>      for subdir, dirs, files in os.walk(topdir, onerror=walk_error):
>          dirs[:] = [d for d in dirs if d not in ignore_dirs]
>          if subdir == str(topdir):
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/meta/lib/oe/spdx30_tasks.py b/meta/lib/oe/spdx30_tasks.py
index 3d80f05612f..0618f2f139d 100644
--- a/meta/lib/oe/spdx30_tasks.py
+++ b/meta/lib/oe/spdx30_tasks.py
@@ -152,6 +152,10 @@  def add_package_files(
     spdx_files = set()
 
     file_counter = 1
+    if not os.path.exists(topdir):
+        bb.note(f"Skip {topdir}")
+        return spdx_files
+
     for subdir, dirs, files in os.walk(topdir, onerror=walk_error):
         dirs[:] = [d for d in dirs if d not in ignore_dirs]
         if subdir == str(topdir):