All of lore.kernel.org
 help / color / mirror / Atom feed
From: Babanpreet Singh <bbnpreetsingh@gmail.com>
To: bitbake-devel@lists.openembedded.org
Cc: Richard Purdie <richard.purdie@linuxfoundation.org>,
	Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>,
	Babanpreet Singh <bbnpreetsingh@gmail.com>
Subject: [PATCH v2] cooker: make the event log path absolute
Date: Wed, 18 Nov 2026 21:54:23 +0000	[thread overview]
Message-ID: <20261118215423.7-1-bbnpreetsingh@gmail.com> (raw)
In-Reply-To: <a41c1517f39b3f6ea520094767ee2b98ab010b7a.camel@linuxfoundation.org>

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


      reply	other threads:[~2026-11-18 21:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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   ` Babanpreet Singh [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118215423.7-1-bbnpreetsingh@gmail.com \
    --to=bbnpreetsingh@gmail.com \
    --cc=bitbake-devel@lists.openembedded.org \
    --cc=mathieu.dubois-briand@bootlin.com \
    --cc=richard.purdie@linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.