diff mbox series

[1/2] ptest-cargo: refactor run-ptest generation to remove redundancy

Message ID 20250424123217.885006-1-ines.kchelfi@smile.fr
State New
Headers show
Series [1/2] ptest-cargo: refactor run-ptest generation to remove redundancy | expand

Commit Message

ines.kchelfi@smile.fr April 24, 2025, 12:32 p.m. UTC
From: Ines KCHELFI <ines.kchelfi@smile.fr>

This refactoring simplifies the generation of the run-ptest script by
removing redundant logic and improving readability.
Signed-off-by: Ines KCHELFI <ines.kchelfi@smile.fr>
---
 meta/classes-recipe/ptest-cargo.bbclass | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

Yoann Congal April 24, 2025, 2:55 p.m. UTC | #1
Le jeudi 24 avril 2025, ines.kchelfi via lists.openembedded.org
<ines.kchelfi=smile.fr@lists.openembedded.org> a écrit :
> From: Ines KCHELFI <ines.kchelfi@smile.fr>
>
> This refactoring simplifies the generation of the run-ptest script by
> removing redundant logic and improving readability.
> Signed-off-by: Ines KCHELFI <ines.kchelfi@smile.fr>

Reviewed-by: Yoann Congal <yoann.congal@smile.fr>

> ---
>  meta/classes-recipe/ptest-cargo.bbclass | 20 +++++++++++---------
>  1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/meta/classes-recipe/ptest-cargo.bbclass
b/meta/classes-recipe/ptest-cargo.bbclass
> index fd1df9d7c9..6799a454ac 100644
> --- a/meta/classes-recipe/ptest-cargo.bbclass
> +++ b/meta/classes-recipe/ptest-cargo.bbclass
> @@ -97,17 +97,19 @@ python do_install_ptest_cargo() {
>          test_paths.append(os.path.join(ptest_path,
os.path.basename(test_bin)))
>
>      ptest_script = os.path.join(ptest_dir, "run-ptest")
> -    if os.path.exists(ptest_script):
> -        with open(ptest_script, "a") as f:
> +    script_exists = os.path.exists(ptest_script)
> +    with open(ptest_script, "a") as f:
> +        if not script_exists:
> +            f.write("#!/bin/sh\n")
> +
> +        else:
>              f.write(f"\necho \"\"\n")
>              f.write(f"echo \"## starting to run rust tests ##\"\n")
> -            for test_path in test_paths:
> -                f.write(f"{test_path} {rust_test_args}\n")
> -    else:
> -        with open(ptest_script, "a") as f:
> -            f.write("#!/bin/sh\n")
> -            for test_path in test_paths:
> -                f.write(f"{test_path} {rust_test_args}\n")
> +
> +        for test_path in test_paths:
> +            f.write(f"{test_path} {rust_test_args}\n")
> +
> +    if not script_exists:
>          os.chmod(ptest_script, 0o755)
>
>      # this is chown -R root:root ${D}${PTEST_PATH}
> --
> 2.43.0
>
>
diff mbox series

Patch

diff --git a/meta/classes-recipe/ptest-cargo.bbclass b/meta/classes-recipe/ptest-cargo.bbclass
index fd1df9d7c9..6799a454ac 100644
--- a/meta/classes-recipe/ptest-cargo.bbclass
+++ b/meta/classes-recipe/ptest-cargo.bbclass
@@ -97,17 +97,19 @@  python do_install_ptest_cargo() {
         test_paths.append(os.path.join(ptest_path, os.path.basename(test_bin)))
 
     ptest_script = os.path.join(ptest_dir, "run-ptest")
-    if os.path.exists(ptest_script):
-        with open(ptest_script, "a") as f:
+    script_exists = os.path.exists(ptest_script)
+    with open(ptest_script, "a") as f:
+        if not script_exists:
+            f.write("#!/bin/sh\n")
+                
+        else:
             f.write(f"\necho \"\"\n")
             f.write(f"echo \"## starting to run rust tests ##\"\n")
-            for test_path in test_paths:
-                f.write(f"{test_path} {rust_test_args}\n")
-    else:
-        with open(ptest_script, "a") as f:
-            f.write("#!/bin/sh\n")
-            for test_path in test_paths:
-                f.write(f"{test_path} {rust_test_args}\n")
+                
+        for test_path in test_paths:
+            f.write(f"{test_path} {rust_test_args}\n")
+        
+    if not script_exists:
         os.chmod(ptest_script, 0o755)
 
     # this is chown -R root:root ${D}${PTEST_PATH}