diff mbox series

cooker: create missing eventlog directory

Message ID 20261113-mathieu-b16492-write-variables-v1-1-9f1f86aebc8b@bootlin.com
State New
Headers show
Series cooker: create missing eventlog directory | expand

Commit Message

Mathieu Dubois-Briand Nov. 13, 2026, 2:34 p.m. UTC
If the eventlog folder is removed while bitbake is still resident in
memory, it will not be re-created on the next build and result in an
exception while trying to write event logs. Catch this exception and
create the folder as expected.

[YOCTO #16492]

Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
---
 lib/bb/cooker.py | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)


---
base-commit: f22df7e0e00be1f3c406138b8b7269d47ea491fe
change-id: 20261113-mathieu-b16492-write-variables-4944e8e88bb0

Best regards,
diff mbox series

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 8a422e50621a..5b8b35c133bd 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -112,12 +112,22 @@  class EventWriter:
         self.eventfile = eventfile
         self.event_queue = []
 
+    def _open(self):
+        try:
+            return open(self.eventfile, "a")
+        except FileNotFoundError:
+            # setupEventLog() creates the folder, but will not re-create it if
+            # it is removed between two builds, with the resident process still
+            # in memory. Catch the resulting exception and re-create it.
+            bb.utils.mkdirhier(os.path.dirname(self.eventfile))
+            return open(self.eventfile, "a")
+
     def write_variables(self):
-        with open(self.eventfile, "a") as f:
+        with self._open() as f:
             f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
 
     def send(self, event):
-        with open(self.eventfile, "a") as f:
+        with self._open() as f:
             try:
                 str_event = codecs.encode(pickle.dumps(event), 'base64').decode('utf-8')
                 f.write("%s\n" % json.dumps({"class": event.__module__ + "." + event.__class__.__name__,