]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
buildstats: Avoid rare UnboundLocalError
authorRichard Purdie <richard.purdie@linuxfoundation.org>
Sat, 1 Mar 2025 13:20:07 +0000 (13:20 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 3 Mar 2025 18:00:47 +0000 (18:00 +0000)
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 <richard.purdie@linuxfoundation.org>
meta/classes-global/buildstats.bbclass

index 8a50bede5f924e02ca842a95d2ed805d80873074..fe64789e1009a99171120ffe6bc2f0cedd0edc88 100644 (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