diff mbox series

oeqa/selftest: add a newline in local.conf (newbuilddir)

Message ID 20250222125822.385265-1-gavrosc@yahoo.com
State Accepted, archived
Commit d2fcd9e880126bc33be2ef14e678cc1aa72683c3
Headers show
Series oeqa/selftest: add a newline in local.conf (newbuilddir) | expand

Commit Message

Christos Gavros Feb. 22, 2025, 12:58 p.m. UTC
If the build-st/conf/local.conf does not end with a newline
when is generated then add one
Fixes [YOCTO #15734]

CC: Yoann Congal <yoann.congal@smile.fr>
CC: Randy MacLeod <randy.macleod@windriver.com>
Signed-off-by: Christos Gavros <gavrosc@yahoo.com>
---
 meta/lib/oeqa/selftest/context.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Yoann Congal Feb. 22, 2025, 11:37 p.m. UTC | #1
Hello,

Le sam. 22 févr. 2025 à 13:59, Christos Gavros <gavrosc@yahoo.com> a écrit :

> If the build-st/conf/local.conf does not end with a newline
> when is generated then add one
> Fixes [YOCTO #15734]
>
> CC: Yoann Congal <yoann.congal@smile.fr>
> CC: Randy MacLeod <randy.macleod@windriver.com>
> Signed-off-by: Christos Gavros <gavrosc@yahoo.com>
> ---
>

Thanks for looking into this!


>  meta/lib/oeqa/selftest/context.py | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/meta/lib/oeqa/selftest/context.py
> b/meta/lib/oeqa/selftest/context.py
> index 5eb4cc44fd..986fe8e1db 100644
> --- a/meta/lib/oeqa/selftest/context.py
> +++ b/meta/lib/oeqa/selftest/context.py
> @@ -102,6 +102,16 @@ class OESelftestTestContext(OETestContext):
>          oe.path.copytree(builddir + "/cache", newbuilddir + "/cache")
>          oe.path.copytree(selftestdir, newselftestdir)
>
> +        # if the last line of local.conf in newbuilddir is not empty or
> does not end with newline then add one
>
That comment should read  "... is not empty AND does not end with
newline..." ?

+        localconf_path = newbuilddir + "/conf/local.conf"
> +        last_line = ""
> +        with open(localconf_path, "r", encoding="utf-8") as f:
> +            for line in f:
> +                last_line = line
> +
> +        if last_line != "" and not last_line.endswith("\n"):
> +            subprocess.check_output("echo >> %s/conf/local.conf" %
> newbuilddir, cwd=newbuilddir, shell=True)
>

I'm no Python expert but I would simplify by writing the "\n" directly from
Python with something like (using the "update" mode "r+"):

with open(localconf_path, "r+", encoding="utf-8") as f:
    last_line=None
    for line in f:
        last_line = line
    if last_line and not last_line.endswith("\n"):
        f.write("\n")

Also, I find using None instead of "" better to mean "missing value"

> +
>          subprocess.check_output("git init && git add * && git commit -a
> -m 'initial'", cwd=newselftestdir, shell=True)
>
>          # Tried to used bitbake-layers add/remove but it requires recipe
> parsing and hence is too slow
> --
> 2.34.1
>
>
Regards,
Christos Gavros Feb. 23, 2025, 7:47 a.m. UTC | #2
hi

I will change the comment.

Regarding 'None'(NoneType) and ""(str) ,  I don't see any significant difference here but it can be changed.

I considered "f.write" and is simpler as you said but lower in "context.py" is used subprocess to write SSTATE_DIR
and I thought of using the same to keep consistency.

I will wait a bit to see if someone else will comment something and I will submit v2.

Br
Christos
diff mbox series

Patch

diff --git a/meta/lib/oeqa/selftest/context.py b/meta/lib/oeqa/selftest/context.py
index 5eb4cc44fd..986fe8e1db 100644
--- a/meta/lib/oeqa/selftest/context.py
+++ b/meta/lib/oeqa/selftest/context.py
@@ -102,6 +102,16 @@  class OESelftestTestContext(OETestContext):
         oe.path.copytree(builddir + "/cache", newbuilddir + "/cache")
         oe.path.copytree(selftestdir, newselftestdir)
 
+        # if the last line of local.conf in newbuilddir is not empty or does not end with newline then add one
+        localconf_path = newbuilddir + "/conf/local.conf"
+        last_line = ""
+        with open(localconf_path, "r", encoding="utf-8") as f:
+            for line in f:
+                last_line = line
+
+        if last_line != "" and not last_line.endswith("\n"):
+            subprocess.check_output("echo >> %s/conf/local.conf" % newbuilddir, cwd=newbuilddir, shell=True)
+
         subprocess.check_output("git init && git add * && git commit -a -m 'initial'", cwd=newselftestdir, shell=True)
 
         # Tried to used bitbake-layers add/remove but it requires recipe parsing and hence is too slow