@@ -21,6 +21,7 @@ import time
import re
import stat
import datetime
+import json
import bb
import bb.msg
import bb.process
@@ -668,6 +669,13 @@ def _exec_task(fn, task, d, quieterr):
except OSError:
pass
+ # Task log records, for sstate log replay. Written right after the task
+ # body, before the postfuncs, so the sstate packaging postfunc can read them.
+ # Stored under TMPDIR, keyed by multiconfig, virtual class and recipe, so
+ # any sstate task can reach the records of covered tasks from other recipes.
+ logrecords = bb.utils.logrecords_path(localdata, fn, task)
+ bb.utils.remove(logrecords)
+
prefuncs = localdata.getVarFlag(task, 'prefuncs', expand=True)
postfuncs = localdata.getVarFlag(task, 'postfuncs', expand=True)
@@ -710,6 +718,9 @@ def _exec_task(fn, task, d, quieterr):
errchk = ErrorCheckHandler()
bblogger.addHandler(errchk)
+ tasklogcatcher = bb.utils.LogCatcher()
+ bblogger.addHandler(tasklogcatcher)
+
localdata.setVar('BB_LOGFILE', logfn)
localdata.setVar('BB_RUNTASK', task)
localdata.setVar('BB_TASK_LOGGER', bblogger)
@@ -723,6 +734,9 @@ def _exec_task(fn, task, d, quieterr):
for func in (prefuncs or '').split():
exec_func(func, localdata)
exec_func(task, localdata)
+ bb.utils.mkdirhier(os.path.dirname(logrecords))
+ with open(logrecords, 'w') as f:
+ json.dump(tasklogcatcher.records, f)
for func in (postfuncs or '').split():
exec_func(func, localdata)
finally:
@@ -732,6 +746,7 @@ def _exec_task(fn, task, d, quieterr):
sys.stderr.flush()
bblogger.removeHandler(handler)
+ bblogger.removeHandler(tasklogcatcher)
# Restore the backup fds
os.dup2(osi[0], osi[1])
@@ -2150,6 +2150,15 @@ def load_plugins(logger, plugins, pluginpath):
plugins.append(plugin)
+def logrecords_path(d, fn, task):
+ from bb.cache import virtualfn2realfn
+
+ realfn, cls, mc = virtualfn2realfn(fn)
+ mc = "mc:" + mc if mc else ""
+ recipe = os.path.splitext(os.path.basename(realfn))[0]
+ return os.path.join(d.getVar("TMPDIR"), "logrecords", mc, cls, recipe,
+ "logrecords.%s.json" % task)
+
class LogCatcher(logging.Handler):
"""Logging handler for collecting logged messages so you can check them later"""
def __init__(self):
Every task gets a LogCatcher which records its warnings and errors during execution. Right after the task body, and before the postfuncs, the records are written to ${TMPDIR}/logrecords/[mc:<mc>/][<virtual class>/]<recipe>/logrecords.<task>.json, so records from other recipes can be bundled too. The sstate packaging postfunc reads the current task's file to bundle the messages for replay when the task is later restored from the sstate cache. Writing the file before the postfuncs makes both the current task's own record and the files of already finished dependency tasks readable from the same place. AI-Generated: Uses opencode (DeepSeek V4 Flash) Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> --- lib/bb/build.py | 15 +++++++++++++++ lib/bb/utils.py | 9 +++++++++ 2 files changed, 24 insertions(+)