buildstats: Avoid rare UnboundLocalError

In rare cases BUILDNAME can seemingly be None outside of heartbeat events
which leads to UnboundLocalErrors as bsdir and taskdir aren't defined.

Skip the code in these cases rather than generate tracebacks which cause
bitbake server to exit.

(From OE-Core rev: 0f74d804ba0daf7e8bd6481597740b9d89821414)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie 2025-03-01 13:20:07 +00:00
parent 44f2059a93
commit 2bd5494291

View File

@ -188,14 +188,17 @@ python run_buildstats () {
# bitbake fires HeartbeatEvent even before a build has been
# triggered, causing BUILDNAME to be None
########################################################################
if bn is not None:
bsdir = os.path.join(d.getVar('BUILDSTATS_BASE'), bn)
taskdir = os.path.join(bsdir, d.getVar('PF'))
if isinstance(e, bb.event.HeartbeatEvent) and bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_INTERVAL")):
if bn is None:
return
bsdir = os.path.join(d.getVar('BUILDSTATS_BASE'), bn)
taskdir = os.path.join(bsdir, d.getVar('PF'))
if isinstance(e, bb.event.HeartbeatEvent):
if bb.utils.to_boolean(d.getVar("BB_LOG_HOST_STAT_ON_INTERVAL")):
bb.utils.mkdirhier(bsdir)
write_host_data(os.path.join(bsdir, "host_stats_interval"), e, d, "interval")
if isinstance(e, bb.event.BuildStarted):
elif isinstance(e, bb.event.BuildStarted):
########################################################################
# If the kernel was not configured to provide I/O statistics, issue
# a one time warning.
@ -234,7 +237,7 @@ python run_buildstats () {
if cpu:
f.write("CPU usage: %0.1f%% \n" % cpu)
if isinstance(e, bb.build.TaskStarted):
elif isinstance(e, bb.build.TaskStarted):
set_timedata("__timedata_task", d, e.time)
bb.utils.mkdirhier(taskdir)
# write into the task event file the name and start time