Skip to contentSkip to conversation

event: Prevent bitbake from executing event handler for wrong multiconfig target

PATCH Superseded Tomasz Dziendzielski 2 participants 5 messages Feb 4, 2021 – Feb 5, 2021

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

I added a mc target name as a prefix to event handler name so there won't be two different handlers with the same name.

---
 lib/bb/cookerdata.py | 3 ++-
 lib/bb/event.py      | 5 +++++
 lib/bb/parse/ast.py  | 7 ++++++-
 3 files changed, 13 insertions(+), 2 deletions(-)
lib/bb/cookerdata.py +2 -1
index c39b5681..108346ce 100644
@@ -429,7 +429,8 @@ class CookerDataBuilder(object):
                 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)
+            nvar = mc + var
+            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 +5 -0
index 694b4705..d0ddac23 100644
@@ -118,6 +118,11 @@ def fire_class_handlers(event, d):
             if _eventfilter:
                 if not _eventfilter(name, handler, event, d):
                     continue
+
+            mc_prefix = d.getVar('BB_CURRENT_MC') or ""
+            if mc_prefix and not name[len(mc_prefix):] in (d.getVar("__BBHANDLERS") or []):
+                continue
+
             execute_handler(name, handler, event, d)
 
 ui_queue = []
lib/bb/parse/ast.py +6 -1
index 0714296a..202cbffb 100644
@@ -335,7 +335,12 @@ def finalize(fn, d, variant = None):
             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)
+
+            nvar = var
+            if d.getVar('BB_CURRENT_MC', False):
+                nvar = d.getVar('BB_CURRENT_MC', False) + var
+
+            bb.event.register(nvar, d.getVar(var, False), (d.getVarFlag(var, "eventmask") or "").split(), handlerfn, handlerln)
 
         bb.event.fire(bb.event.RecipePreFinalise(fn), d)
 
Signature · 1 line
2.30.0
#1 lore raw
Quoted 11 lines · Tomasz Dziendzielski

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.

Quoted 4 lines

See [YOCTO #13071] for detailed bug information.

I added a mc target name as a prefix to event handler name so there won't be two different handlers with the same name.

This looks like it solves a few issues, thanks!

I'll include it in the next test runs and see where we go from there but it looks right.

Cheers,

Richard

#2 lore raw

I can already see the bitbake test failed, after adding "if d" it passed. Sorry that I forgot to run tests before submitting a patch. Another thing, I ran locally oe-selftest -r multiconfig and build fails with "When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed". During the build it appeared only if I made changes to the code during the build. Here it's most probably caused because of events' handlers renaming.
Do you think there is some way to handle this issue or I should just add:

         ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') ==

'1')
+ if d.getVar("__BBMULTICONFIG", False):
+ ignore_mismatch = True
to bitbake/lib/bb/siggen.py?

Best regards,
Tomasz Dziendzielski

#3 lore raw
Quoted 8 lines · Tomasz Dziendzielski

I can already see the bitbake test failed, after adding "if d" it passed. Sorry that I forgot to run tests before submitting a patch. Another thing, I ran locally oe-selftest -r multiconfig and build fails with "When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed". During the build it appeared only if I made changes to the code during the build. Here it's most probably caused because of events' handlers renaming.

That is going to be a problem, we need to make sure the hashes are deterministic.

Quoted 7 lines

Do you think there is some way to handle this issue or I should just add:
         ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or '') == '1')
+        if d.getVar("__BBMULTICONFIG", False):
+            ignore_mismatch = True
to bitbake/lib/bb/siggen.py?

No, that is definitely going to just mask the problem.

These tests are designed to detect problems which will cause us "pain" later. The hashes are designed to be stable to whether something is built as a multiconfig or not shouldn't change its hashes. The tests are warning us that is happening so we need to fix that.

Cheers,

Richard

#4 lore raw
Quoted 6 lines

No, that is definitely going to just mask the problem.

These tests are designed to detect problems which will cause us "pain" later. The hashes are designed to be stable to whether something is built as a multiconfig or not shouldn't change its hashes. The tests are warning us that this is happening so we need to fix that.

Thanks, I think I already found the solution. I need to add the mc prefix before it is written to __BBHANDLERS variable and now I don't see any metadata hashes changing on test. I will submit a patch after oe-selftest for multiconfig finishes with success.

@@ -259,6 +259,9 @@ 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)

Best regards,
Tomasz Dziendzielski

pt., 5 lut 2021 o 15:42 Richard Purdie <[email protected]> napisał(a):

Quoted 33 lines · Tomasz Dziendzielski
Quoted 8 lines

I can already see the bitbake test failed, after adding "if d" it passed. Sorry that I forgot to run tests before submitting a patch. Another thing, I ran locally oe-selftest -r multiconfig and build fails with "When reparsing %s, the basehash value changed from %s to %s. The metadata is not deterministic and this needs to be fixed". During the build it appeared only if I made changes to the code during the build. Here it's most probably caused because of events' handlers renaming.

That is going to be a problem, we need to make sure the hashes are deterministic.

Quoted 7 lines

Do you think there is some way to handle this issue or I should just add:
ignore_mismatch = ((d.getVar("BB_HASH_IGNORE_MISMATCH") or
'') == '1')

(quoted diff) +2 -0
+        if d.getVar("__BBMULTICONFIG", False):
+            ignore_mismatch = True

to bitbake/lib/bb/siggen.py?

No, that is definitely going to just mask the problem.

These tests are designed to detect problems which will cause us "pain" later. The hashes are designed to be stable to whether something is built as a multiconfig or not shouldn't change its hashes. The tests are warning us that is happening so we need to fix that.

Cheers,

Richard