Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] oeqa/selftest: add a newline in local.conf (newbuilddir)
       [not found] <20250222125822.385265-1-gavrosc.ref@yahoo.com>
@ 2025-02-22 12:58 ` Christos Gavros
  2025-02-22 23:37   ` Yoann Congal
  0 siblings, 1 reply; 3+ messages in thread
From: Christos Gavros @ 2025-02-22 12:58 UTC (permalink / raw)
  To: openembedded-core; +Cc: Christos Gavros, Yoann Congal, Randy MacLeod

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(+)

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
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] oeqa/selftest: add a newline in local.conf (newbuilddir)
  2025-02-22 12:58 ` [PATCH] oeqa/selftest: add a newline in local.conf (newbuilddir) Christos Gavros
@ 2025-02-22 23:37   ` Yoann Congal
  2025-02-23  7:47     ` Christos Gavros
  0 siblings, 1 reply; 3+ messages in thread
From: Yoann Congal @ 2025-02-22 23:37 UTC (permalink / raw)
  To: Christos Gavros; +Cc: openembedded-core, Randy MacLeod

[-- Attachment #1: Type: text/plain, Size: 2273 bytes --]

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,
-- 
Yoann Congal
Smile ECS - Tech expert

[-- Attachment #2: Type: text/html, Size: 3930 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] oeqa/selftest: add a newline in local.conf (newbuilddir)
  2025-02-22 23:37   ` Yoann Congal
@ 2025-02-23  7:47     ` Christos Gavros
  0 siblings, 0 replies; 3+ messages in thread
From: Christos Gavros @ 2025-02-23  7:47 UTC (permalink / raw)
  To: openembedded-core

[-- Attachment #1: Type: text/plain, Size: 424 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 607 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-23  7:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20250222125822.385265-1-gavrosc.ref@yahoo.com>
2025-02-22 12:58 ` [PATCH] oeqa/selftest: add a newline in local.conf (newbuilddir) Christos Gavros
2025-02-22 23:37   ` Yoann Congal
2025-02-23  7:47     ` Christos Gavros

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox