event: Prevent bitbake from executing event handler for wrong multiconfig target
PATCH v4 1/1 event: Prevent bitbake from executing event handler for wrong multiconfig target
When multiconfig is used bitbake might try to run events that don't exist for specific mc target. In cooker.py we pass self.databuilder.mcdata[mc] data that contains names of events' handlers per mc target, but fire_class_handlers uses global _handlers variable that is created during parsing of all the targets.
This leads to a problem where bitbake runs event handler that don't exist for a target or even overrides them - if multiple targets use event handler with the same name but different code then only one version will be executed for all targets.
See [YOCTO #13071] for detailed bug information.
Add mc target name as a prefix to event handler name so there won't be two different handlers with the same name.
--- v4 add mc prefix to _bb_diskmonitor event handler to fix build, both build and test_stoptask_behavior should be working now
--- lib/bb/cookerdata.py | 5 ++++- lib/bb/event.py | 2 ++ lib/bb/parse/ast.py | 7 ++++++- lib/bb/runqueue.py | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-)
lib/bb/cookerdata.py +4 -1
@@ -424,12 +424,15 @@ class CookerDataBuilder(object): # Nomally we only register event handlers at the end of parsing .bb files # We register any handlers we've found so far here... for var in data.getVar('__BBHANDLERS', False) or []: + nvar=var + if mc: + var = nvar[len(mc):] handlerfn = data.getVarFlag(var, "filename", False) if not handlerfn: parselog.critical("Undefined event handler function '%s'" % var) raise bb.BBHandledException() handlerln = int(data.getVarFlag(var, "lineno", False)) - bb.event.register(var, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) + bb.event.register(nvar, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) data.setVar('BBINCLUDED',bb.parse.get_file_depends(data))
lib/bb/event.py +2 -0
@@ -118,6 +118,8 @@ def fire_class_handlers(event, d): if _eventfilter: if not _eventfilter(name, handler, event, d): continue + if d and name not in (d.getVar("__BBHANDLERS") or []): + continue execute_handler(name, handler, event, d) ui_queue = []
lib/bb/parse/ast.py +6 -1
@@ -261,6 +261,8 @@ class BBHandlerNode(AstNode): def eval(self, data): bbhands = data.getVar('__BBHANDLERS', False) or [] for h in self.hs: + if data.getVar('BB_CURRENT_MC', False): + h = data.getVar('BB_CURRENT_MC', False) + h bbhands.append(h) data.setVarFlag(h, "handler", 1) data.setVar('__BBHANDLERS', bbhands)
@@ -331,11 +333,14 @@ def finalize(fn, d, variant = None): try: for var in d.getVar('__BBHANDLERS', False) or []: # try to add the handler + nvar=var + if d.getVar('BB_CURRENT_MC', False): + var = nvar[len(d.getVar('BB_CURRENT_MC', False)):] handlerfn = d.getVarFlag(var, "filename", False) if not handlerfn: bb.fatal("Undefined event handler function '%s'" % var) handlerln = int(d.getVarFlag(var, "lineno", False)) - bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) + bb.event.register(nvar, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) bb.event.fire(bb.event.RecipePreFinalise(fn), d)
lib/bb/runqueue.py +13 -2
@@ -1464,7 +1464,14 @@ class RunQueue: bb.event.fire(bb.event.DepTreeGenerated(depgraph), self.cooker.data) if not self.dm_event_handler_registered: - res = bb.event.register(self.dm_event_handler_name, + bbhands = self.cfgData.getVar('__BBHANDLERS', False) or [] + nvar = self.dm_event_handler_name + if self.cfgData.getVar('BB_CURRENT_MC', False): + nvar = self.cfgData.getVar('BB_CURRENT_MC', False) + nvar + + bbhands.append(nvar) + self.cfgData.setVar('__BBHANDLERS', bbhands) + res = bb.event.register(nvar, lambda x: self.dm.check(self) if self.state in [runQueueRunning, runQueueCleanUp] else False, ('bb.event.HeartbeatEvent',)) self.dm_event_handler_registered = True
@@ -1505,7 +1512,11 @@ class RunQueue: build_done = self.state is runQueueComplete or self.state is runQueueFailed if build_done and self.dm_event_handler_registered: - bb.event.remove(self.dm_event_handler_name, None) + nvar = self.dm_event_handler_name + if self.cfgData.getVar('BB_CURRENT_MC', False): + nvar = self.cfgData.getVar('BB_CURRENT_MC', False) + nvar + + bb.event.remove(nvar, None) self.dm_event_handler_registered = False if build_done and self.rqexe:
Signature · 1 line
2.30.0
Quoted 18 lines · Tomasz Dziendzielski
When multiconfig is used bitbake might try to run events that don't exist for specific mc target. In
cooker.pywe passself.databuilder.mcdata[mc]data that contains names of events' handlers per mc target, butfire_class_handlersuses global_handlersvariable that is created during parsing of all the targets.This leads to a problem where bitbake runs event handler that don't exist for a target or even overrides them - if multiple targets use event handler with the same name but different code then only one version will be executed for all targets.
See [YOCTO #13071] for detailed bug information.
Add mc target name as a prefix to event handler name so there won't be two different handlers with the same name.
Signed-off-by Tomasz Dziendzielski <[email protected]>
Quoted 7 lines
--- v4 add mc prefix to
_bb_diskmonitorevent handler to fix build, both build andtest_stoptask_behaviorshould be working now
---lib/bb/cookerdata.py | 5 ++++- lib/bb/event.py | 2 ++ lib/bb/parse/ast.py | 7 ++++++- lib/bb/runqueue.py | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-)
This still isn't right I'm afraid:
https://autobuilder.yoctoproject.org/typhoon/#/builders/39/builds/3057
I did also wonder if we should be changing each of the event register callers, or doing something inside the event register function instead?
Cheers,
Richard
Quoted 2 lines
I did also wonder if we should be changing each of the event register callers, or doing something inside the event register function instead?
That should be possible. I'll work on that. Thanks and sorry for the problem.
Best regards,
Tomasz Dziendzielski
wt., 9 lut 2021 o 16:50 Richard Purdie <[email protected]> napisał(a):
Quoted 40 lines · Tomasz Dziendzielski
Quoted 11 lines
When multiconfig is used bitbake might try to run events that don't exist for specific mc target. In
cooker.pywe passself.databuilder.mcdata[mc]data that contains names of events' handlers per mc target, butfire_class_handlersuses global_handlersvariable that is created during parsing of all the targets.This leads to a problem where bitbake runs event handler that don't exist for a target or even overrides them - if multiple targets use event handler with the same name but different code then only one version will be executed for all targets.
Quoted 8 lines
See [YOCTO #13071] for detailed bug information.
Add mc target name as a prefix to event handler name so there won't be two different handlers with the same name.
Signed-off-by Tomasz Dziendzielski <[email protected]>--- v4 add mc prefix to
_bb_diskmonitorevent handler to fix build, bothbuild and
test_stoptask_behaviorshould be working nowQuoted 6 lines
--- lib/bb/cookerdata.py | 5 ++++- lib/bb/event.py | 2 ++ lib/bb/parse/ast.py | 7 ++++++- lib/bb/runqueue.py | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 4 deletions(-)This still isn't right I'm afraid:
https://autobuilder.yoctoproject.org/typhoon/#/builders/39/builds/3057
I did also wonder if we should be changing each of the event register callers, or doing something inside the event register function instead?
Cheers,
Richard
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 2 lines
Quoted 2 lines
I did also wonder if we should be changing each of the event register callers, or doing something inside the event register function instead?
Thanks again for your suggestion, it was the right way to go that solved the inconsistency with bb_diskmonitor event handler (and any other that would be registered manually, without addhandler statement). I prepared the change and it does not trigger any errors. I tested it with:
$ bitbake-selftest $ oe-selftest -r multiconfig, $ oe-selftest -r buildoptions.DiskMonTest.test_stoptask_behavior $ yocto-check-layer-wrapper ../meta-mingw $ bitbake core-image-sato:do_testsdkext core-image-minimal:do_testsdkext core-image-sato:do_testsdkext (only for qemux86-64, one of the machines that was failing) which are the tests that failed with previous patches and now all tests passed.
Please check the next patch:
https://lists.openembedded.org/g/bitbake-devel/message/12020
Best regards,
Tomasz Dziendzielski