diff options
author | Tomasz Dziendzielski <tomasz.dziendzielski@gmail.com> | 2021-02-10 12:15:15 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-02-16 11:26:11 +0000 |
commit | 8b792d4f75b451f9e08fdb13464a0b66c11bc075 (patch) | |
tree | 0f02eba054c6eb9b498be77ef70e53fbda04b064 /bitbake/lib | |
parent | f162c34fdba51902abb9e8fb79ddc5044deab275 (diff) | |
download | poky-8b792d4f75b451f9e08fdb13464a0b66c11bc075.tar.gz |
bitbake: 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. Add internal __BBHANDLERS_MC
variable to have the handlers lists per machine.
(Bitbake rev: 5f7fdf7b2d8c59805c8ef4dae84f536baa5e172b)
Signed-off-by: Tomasz Dziendzielski <tomasz.dziendzielski@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/cookerdata.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/event.py | 26 | ||||
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 2 | ||||
-rw-r--r-- | bitbake/lib/bb/runqueue.py | 4 |
4 files changed, 28 insertions, 6 deletions
diff --git a/bitbake/lib/bb/cookerdata.py b/bitbake/lib/bb/cookerdata.py index c39b568130..1c1e008c6b 100644 --- a/bitbake/lib/bb/cookerdata.py +++ b/bitbake/lib/bb/cookerdata.py | |||
@@ -429,7 +429,7 @@ class CookerDataBuilder(object): | |||
429 | parselog.critical("Undefined event handler function '%s'" % var) | 429 | parselog.critical("Undefined event handler function '%s'" % var) |
430 | raise bb.BBHandledException() | 430 | raise bb.BBHandledException() |
431 | handlerln = int(data.getVarFlag(var, "lineno", False)) | 431 | handlerln = int(data.getVarFlag(var, "lineno", False)) |
432 | bb.event.register(var, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) | 432 | bb.event.register(var, data.getVar(var, False), (data.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln, data) |
433 | 433 | ||
434 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) | 434 | data.setVar('BBINCLUDED',bb.parse.get_file_depends(data)) |
435 | 435 | ||
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 694b470520..ff89959460 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
@@ -118,6 +118,8 @@ def fire_class_handlers(event, d): | |||
118 | if _eventfilter: | 118 | if _eventfilter: |
119 | if not _eventfilter(name, handler, event, d): | 119 | if not _eventfilter(name, handler, event, d): |
120 | continue | 120 | continue |
121 | if d and not name in (d.getVar("__BBHANDLERS_MC") or []): | ||
122 | continue | ||
121 | execute_handler(name, handler, event, d) | 123 | execute_handler(name, handler, event, d) |
122 | 124 | ||
123 | ui_queue = [] | 125 | ui_queue = [] |
@@ -227,9 +229,13 @@ def fire_from_worker(event, d): | |||
227 | fire_ui_handlers(event, d) | 229 | fire_ui_handlers(event, d) |
228 | 230 | ||
229 | noop = lambda _: None | 231 | noop = lambda _: None |
230 | def register(name, handler, mask=None, filename=None, lineno=None): | 232 | def register(name, handler, mask=None, filename=None, lineno=None, data=None): |
231 | """Register an Event handler""" | 233 | """Register an Event handler""" |
232 | 234 | ||
235 | if data and data.getVar("BB_CURRENT_MC"): | ||
236 | mc = data.getVar("BB_CURRENT_MC") | ||
237 | name = '%s%s' % (mc, name) | ||
238 | |||
233 | # already registered | 239 | # already registered |
234 | if name in _handlers: | 240 | if name in _handlers: |
235 | return AlreadyRegistered | 241 | return AlreadyRegistered |
@@ -268,10 +274,20 @@ def register(name, handler, mask=None, filename=None, lineno=None): | |||
268 | _event_handler_map[m] = {} | 274 | _event_handler_map[m] = {} |
269 | _event_handler_map[m][name] = True | 275 | _event_handler_map[m][name] = True |
270 | 276 | ||
277 | if data: | ||
278 | bbhands_mc = (data.getVar("__BBHANDLERS_MC") or []) | ||
279 | bbhands_mc.append(name) | ||
280 | data.setVar("__BBHANDLERS_MC", bbhands_mc) | ||
281 | |||
271 | return Registered | 282 | return Registered |
272 | 283 | ||
273 | def remove(name, handler): | 284 | def remove(name, handler, data=None): |
274 | """Remove an Event handler""" | 285 | """Remove an Event handler""" |
286 | if data: | ||
287 | if data.getVar("BB_CURRENT_MC"): | ||
288 | mc = data.getVar("BB_CURRENT_MC") | ||
289 | name = '%s%s' % (mc, name) | ||
290 | |||
275 | _handlers.pop(name) | 291 | _handlers.pop(name) |
276 | if name in _catchall_handlers: | 292 | if name in _catchall_handlers: |
277 | _catchall_handlers.pop(name) | 293 | _catchall_handlers.pop(name) |
@@ -279,6 +295,12 @@ def remove(name, handler): | |||
279 | if name in _event_handler_map[event]: | 295 | if name in _event_handler_map[event]: |
280 | _event_handler_map[event].pop(name) | 296 | _event_handler_map[event].pop(name) |
281 | 297 | ||
298 | if data: | ||
299 | bbhands_mc = (data.getVar("__BBHANDLERS_MC") or []) | ||
300 | if name in bbhands_mc: | ||
301 | bbhands_mc.remove(name) | ||
302 | data.setVar("__BBHANDLERS_MC", bbhands_mc) | ||
303 | |||
282 | def get_handlers(): | 304 | def get_handlers(): |
283 | return _handlers | 305 | return _handlers |
284 | 306 | ||
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index 0596993d01..50a88f7da7 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -335,7 +335,7 @@ def finalize(fn, d, variant = None): | |||
335 | if not handlerfn: | 335 | if not handlerfn: |
336 | bb.fatal("Undefined event handler function '%s'" % var) | 336 | bb.fatal("Undefined event handler function '%s'" % var) |
337 | handlerln = int(d.getVarFlag(var, "lineno", False)) | 337 | handlerln = int(d.getVarFlag(var, "lineno", False)) |
338 | bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln) | 338 | bb.event.register(var, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln, data=d) |
339 | 339 | ||
340 | bb.event.fire(bb.event.RecipePreFinalise(fn), d) | 340 | bb.event.fire(bb.event.RecipePreFinalise(fn), d) |
341 | 341 | ||
diff --git a/bitbake/lib/bb/runqueue.py b/bitbake/lib/bb/runqueue.py index 2f521e5a14..b8b217c64a 100644 --- a/bitbake/lib/bb/runqueue.py +++ b/bitbake/lib/bb/runqueue.py | |||
@@ -1466,7 +1466,7 @@ class RunQueue: | |||
1466 | if not self.dm_event_handler_registered: | 1466 | if not self.dm_event_handler_registered: |
1467 | res = bb.event.register(self.dm_event_handler_name, | 1467 | res = bb.event.register(self.dm_event_handler_name, |
1468 | lambda x: self.dm.check(self) if self.state in [runQueueRunning, runQueueCleanUp] else False, | 1468 | lambda x: self.dm.check(self) if self.state in [runQueueRunning, runQueueCleanUp] else False, |
1469 | ('bb.event.HeartbeatEvent',)) | 1469 | ('bb.event.HeartbeatEvent',), data=self.cfgData) |
1470 | self.dm_event_handler_registered = True | 1470 | self.dm_event_handler_registered = True |
1471 | 1471 | ||
1472 | dump = self.cooker.configuration.dump_signatures | 1472 | dump = self.cooker.configuration.dump_signatures |
@@ -1505,7 +1505,7 @@ class RunQueue: | |||
1505 | build_done = self.state is runQueueComplete or self.state is runQueueFailed | 1505 | build_done = self.state is runQueueComplete or self.state is runQueueFailed |
1506 | 1506 | ||
1507 | if build_done and self.dm_event_handler_registered: | 1507 | if build_done and self.dm_event_handler_registered: |
1508 | bb.event.remove(self.dm_event_handler_name, None) | 1508 | bb.event.remove(self.dm_event_handler_name, None, data=self.cfgData) |
1509 | self.dm_event_handler_registered = False | 1509 | self.dm_event_handler_registered = False |
1510 | 1510 | ||
1511 | if build_done and self.rqexe: | 1511 | if build_done and self.rqexe: |