All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] cooker: fix -w with a file name that has no directory
@ 2026-11-14 18:55 Babanpreet Singh
  2026-11-17 12:32 ` [bitbake-devel] " Richard Purdie
  0 siblings, 1 reply; 3+ messages in thread
From: Babanpreet Singh @ 2026-11-14 18:55 UTC (permalink / raw)
  To: bitbake-devel; +Cc: Mathieu Dubois-Briand, Babanpreet Singh

"bitbake -w events.json" fails with:

  FileNotFoundError: [Errno 2] No such file or directory: ''

There is no directory to create for a bare file name, so don't try.

Fixes: ee174b231897 ("cooker: Add support for BB_DEFAULT_EVENTLOG")
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---

Notes:
    Found while looking at YOCTO #16492. Applies with or without Mathieu's
    patch for that bug.

 lib/bb/cooker.py       |  5 +++--
 lib/bb/tests/cooker.py | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 8a422e506..f79cd5e6c 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -457,8 +457,9 @@ You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
         if not self.eventlog or self.eventlog[0] != eventlog:
             # we log all events to a file if so directed
             # register the log file writer as UI Handler
-            if not os.path.exists(os.path.dirname(eventlog)):
-                bb.utils.mkdirhier(os.path.dirname(eventlog))
+            dirname = os.path.dirname(eventlog)
+            if dirname and not os.path.exists(dirname):
+                bb.utils.mkdirhier(dirname)
             writer = EventWriter(self, eventlog)
             EventLogWriteHandler = namedtuple('EventLogWriteHandler', ['event'])
             self.eventlog = (eventlog, bb.event.register_UIHhandler(EventLogWriteHandler(writer)), writer)
diff --git a/lib/bb/tests/cooker.py b/lib/bb/tests/cooker.py
index db4104d40..c6a0cac2a 100644
--- a/lib/bb/tests/cooker.py
+++ b/lib/bb/tests/cooker.py
@@ -409,3 +409,21 @@ addtask marker
             with open(os.path.join(builddir, "marker.log")) as f:
                 self.assertEqual(f.read(), "bbappend-applied",
                                  "bitbake -b did not apply the recipe's bbappend")
+
+
+class EventLogTest(_BitbakeSubprocessTestCase):
+    """Tests for the event log ("bitbake -w")."""
+
+    _parsetests = os.path.realpath(os.path.join(os.path.dirname(__file__), "parse-tests"))
+
+    def test_write_log_bare_filename(self):
+        """bitbake -w must accept a file name without a directory."""
+        with self._build_dir(prefix="eventlogtest") as builddir:
+            env = os.environ.copy()
+            env["BBPATH"] = self._parsetests
+            env["BB_ENV_PASSTHROUGH_ADDITIONS"] = "TOPDIR"
+            env["TOPDIR"] = builddir
+
+            self._run_subprocess(["bitbake", "-w", "events.json", "-e"], env, builddir)
+
+            self.assertTrue(os.path.exists(os.path.join(builddir, "events.json")))
-- 
2.43.0


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

* Re: [bitbake-devel] [PATCH] cooker: fix -w with a file name that has no directory
  2026-11-14 18:55 [PATCH] cooker: fix -w with a file name that has no directory Babanpreet Singh
@ 2026-11-17 12:32 ` Richard Purdie
  2026-11-18 21:54   ` [PATCH v2] cooker: make the event log path absolute Babanpreet Singh
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Purdie @ 2026-11-17 12:32 UTC (permalink / raw)
  To: bbnpreetsingh, bitbake-devel; +Cc: Mathieu Dubois-Briand

On Sat, 2026-11-14 at 18:55 +0000, Baban via bitbake-devel wrote:
> "bitbake -w events.json" fails with:
> 
>   FileNotFoundError: [Errno 2] No such file or directory: ''
> 
> There is no directory to create for a bare file name, so don't try.
> 
> Fixes: ee174b231897 ("cooker: Add support for BB_DEFAULT_EVENTLOG")
> Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
> ---
> 
> Notes:
>     Found while looking at YOCTO #16492. Applies with or without Mathieu's
>     patch for that bug.
> 
>  lib/bb/cooker.py       |  5 +++--
>  lib/bb/tests/cooker.py | 18 ++++++++++++++++++
>  2 files changed, 21 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
> index 8a422e506..f79cd5e6c 100644
> --- a/lib/bb/cooker.py
> +++ b/lib/bb/cooker.py
> @@ -457,8 +457,9 @@ You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in si
>          if not self.eventlog or self.eventlog[0] != eventlog:
>              # we log all events to a file if so directed
>              # register the log file writer as UI Handler
> -            if not os.path.exists(os.path.dirname(eventlog)):
> -                bb.utils.mkdirhier(os.path.dirname(eventlog))
> +            dirname = os.path.dirname(eventlog)
> +            if dirname and not os.path.exists(dirname):
> +                bb.utils.mkdirhier(dirname)
>              writer = EventWriter(self, eventlog)
>              EventLogWriteHandler = namedtuple('EventLogWriteHandler', ['event'])
>              self.eventlog = (eventlog, bb.event.register_UIHhandler(EventLogWriteHandler(writer)), writer)

Thanks for the patch. When reviewing this I realised that the current
working directory in the server code might not be the same as the
commandline.

Would you be able to tweak the code in main.py where it sets 
"options.writeeventlog = eventlog" to resolve the path there to a full
path?

It can also be set via BB_DEFAULT_EVENTLOG and I think we should just
show an error if that path isn't absolute?

I think that would resolve my concerns.

Thanks,

Richard


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

* [PATCH v2] cooker: make the event log path absolute
  2026-11-17 12:32 ` [bitbake-devel] " Richard Purdie
@ 2026-11-18 21:54   ` Babanpreet Singh
  0 siblings, 0 replies; 3+ messages in thread
From: Babanpreet Singh @ 2026-11-18 21:54 UTC (permalink / raw)
  To: bitbake-devel; +Cc: Richard Purdie, Mathieu Dubois-Briand, Babanpreet Singh

The server's current directory may not be the one bitbake was run
from, so a relative -w path is not safe to hand over. A bare file name
fails outright:

  FileNotFoundError: [Errno 2] No such file or directory: ''

Resolve the -w path in main.py, and show an error if
BB_DEFAULT_EVENTLOG is relative.

Fixes: ee174b231897 ("cooker: Add support for BB_DEFAULT_EVENTLOG")
AI-Generated: Uses Claude (claude-opus-5-5)
Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com>
---

 lib/bb/cooker.py       |  2 ++
 lib/bb/main.py         |  4 ++++
 lib/bb/tests/cooker.py | 45 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+)

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index a6bc2827d..54f87278f 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -314,6 +314,8 @@ class BBCooker:
 
         eventlog = self.data.getVar("BB_DEFAULT_EVENTLOG")
         if not self.configuration.writeeventlog and eventlog:
+            if not os.path.isabs(eventlog):
+                bb.fatal("BB_DEFAULT_EVENTLOG must be an absolute path, not \"%s\"" % eventlog)
             self.setupEventLog(eventlog)
 
         if consolelog:
diff --git a/lib/bb/main.py b/lib/bb/main.py
index 5cce8eb27..5a49f73b3 100755
--- a/lib/bb/main.py
+++ b/lib/bb/main.py
@@ -338,6 +338,10 @@ class BitBakeConfigParameters(cookerdata.ConfigParameters):
             eventlog = "bitbake_eventlog_%s.json" % datetime.now().strftime("%Y%m%d%H%M%S")
             options.writeeventlog = eventlog
 
+        # the server may not share our current directory
+        if options.writeeventlog:
+            options.writeeventlog = os.path.abspath(options.writeeventlog)
+
         if options.bind:
             try:
                 #Checking that the port is a number and is a ':' delimited value
diff --git a/lib/bb/tests/cooker.py b/lib/bb/tests/cooker.py
index db4104d40..923adc156 100644
--- a/lib/bb/tests/cooker.py
+++ b/lib/bb/tests/cooker.py
@@ -409,3 +409,48 @@ addtask marker
             with open(os.path.join(builddir, "marker.log")) as f:
                 self.assertEqual(f.read(), "bbappend-applied",
                                  "bitbake -b did not apply the recipe's bbappend")
+
+
+class EventLogTest(_BitbakeSubprocessTestCase):
+    """Tests for the event log ("bitbake -w" and BB_DEFAULT_EVENTLOG)."""
+
+    _parsetests = os.path.realpath(os.path.join(os.path.dirname(__file__), "parse-tests"))
+
+    def _make_env(self, builddir):
+        env = os.environ.copy()
+        env.pop("BBEVENTLOG", None)
+        env["BBPATH"] = self._parsetests
+        env["BB_ENV_PASSTHROUGH_ADDITIONS"] = "TOPDIR BB_DEFAULT_EVENTLOG"
+        env["TOPDIR"] = builddir
+        return env
+
+    def test_write_log_path_is_absolute(self):
+        """The -w path is resolved against the client's directory, since the
+        server may run in another one."""
+        import bb.main
+        for arg in ("events.json", ""):
+            with self.subTest(arg=arg):
+                params = bb.main.BitBakeConfigParameters(["bitbake", "-w", arg])
+                self.assertTrue(os.path.isabs(params.writeeventlog))
+                self.assertEqual(os.path.dirname(params.writeeventlog), os.getcwd())
+
+    def test_write_log_bare_filename(self):
+        """bitbake -w must accept a file name without a directory."""
+        with self._build_dir(prefix="eventlogtest") as builddir:
+            self._run_subprocess(["bitbake", "-w", "events.json", "-e"],
+                                 self._make_env(builddir), builddir)
+
+            self.assertTrue(os.path.exists(os.path.join(builddir, "events.json")))
+
+    def test_default_eventlog_relative_is_error(self):
+        """A relative BB_DEFAULT_EVENTLOG is refused with an error."""
+        with self._build_dir(prefix="eventlogtest") as builddir:
+            env = self._make_env(builddir)
+            env["BB_DEFAULT_EVENTLOG"] = "events.json"
+            proc = subprocess.run(["bitbake", "-e"], env=env, cwd=builddir,
+                                  stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+                                  universal_newlines=True)
+
+            self.assertNotEqual(proc.returncode, 0, proc.stdout)
+            self.assertRegex(proc.stdout, r"ERROR: .*BB_DEFAULT_EVENTLOG")
+            self.assertFalse(os.path.exists(os.path.join(builddir, "events.json")))
-- 
2.43.0


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

end of thread, other threads:[~2026-11-18 21:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-14 18:55 [PATCH] cooker: fix -w with a file name that has no directory Babanpreet Singh
2026-11-17 12:32 ` [bitbake-devel] " Richard Purdie
2026-11-18 21:54   ` [PATCH v2] cooker: make the event log path absolute Babanpreet Singh

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.