cooker: fix -w with a file name that has no directory
PATCH 1/1 cooker: fix -w with a file name that has no directory
"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.
---
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(-)
lib/bb/cooker.py +3 -2
@@ -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)
lib/bb/tests/cooker.py +18 -0
@@ -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")))
Signature · 1 line
2.43.0
Quoted 24 lines · Baban via bitbake-devel
"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 <[email protected]>---
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(-)lib/bb/cooker.py +0
-0@@ -457,8 +457,9 @@ You can also remove the BB_HASHSERVE_UPSTREAM setting, but this may result in siif not self.eventlog or self.eventlog[0] != eventlog:
Quoted 10 lines
# 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
PATCH v2 1/1 cooker: make the event log path absolute
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.
AI-Generated: Uses Claude (claude-opus-5-5)
---
lib/bb/cooker.py | 2 ++ lib/bb/main.py | 4 ++++ lib/bb/tests/cooker.py | 45 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+)
lib/bb/cooker.py +2 -0
@@ -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:
lib/bb/main.py +4 -0
@@ -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
lib/bb/tests/cooker.py +45 -0
48 lines not on this page · raw message
Signature · 1 line
2.43.0