From: Richard Purdie Date: Sat, 1 Mar 2025 13:20:07 +0000 (+0000) Subject: buildstats: Avoid rare UnboundLocalError X-Git-Tag: yocto-5.2~364 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0f74d804ba0daf7e8bd6481597740b9d89821414;p=thirdparty%2Fopenembedded%2Fopenembedded-core-contrib.git 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. Signed-off-by: Richard Purdie --- diff --git a/meta/classes-global/buildstats.bbclass b/meta/classes-global/buildstats.bbclass index 8a50bede5f9..fe64789e100 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