From 2bd54942917d8ed51d85cc291162002eac7bd133 Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Sat, 1 Mar 2025 13:20:07 +0000 Subject: [PATCH] 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 --- meta/classes-global/buildstats.bbclass | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/meta/classes-global/buildstats.bbclass b/meta/classes-global/buildstats.bbclass index 8a50bede5f..fe64789e10 100644 --- a/meta/classes-global/buildstats.bbclass +++ b/meta/classes-global/buildstats.bbclass @@ -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