diff mbox series

[2/3] event: Add event for deferred inherits

Message ID 20250609095621.937299-2-richard.purdie@linuxfoundation.org
State New
Headers show
Series [1/3] ast: Change deferred inherits to happen per recipe | expand

Commit Message

Richard Purdie June 9, 2025, 9:56 a.m. UTC
Now that deferred inherits are extension specific, we can pass this
list to an event, which our metadata can use to set class overrides
earlier (as an example).

There are limitations to this, the list of classes is unexpanded and
recursive classes are not visible. There isn't much that can be done
about this, the ones we are interested in would usually be visible
at the top level (such as class extensions).

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/event.py     | 10 ++++++++++
 lib/bb/parse/ast.py |  3 +++
 2 files changed, 13 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/event.py b/lib/bb/event.py
index a12adbc937..b29f0a5568 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -431,6 +431,16 @@  class RecipeEvent(Event):
         self.fn = fn
         Event.__init__(self)
 
+class RecipePreDeferredInherits(RecipeEvent):
+    """
+    Called before deferred inherits are processed so code can snoop on class extensions for example
+    Limitations: It won't see inherits of inherited classes and the data is unexpanded
+    """
+    def __init__(self, fn, inherits):
+        self.fn = fn
+        self.inherits = inherits
+        Event.__init__(self)
+
 class RecipePreFinalise(RecipeEvent):
     """ Recipe Parsing Complete but not yet finalised"""
 
diff --git a/lib/bb/parse/ast.py b/lib/bb/parse/ast.py
index f9998798d8..5a086b4e95 100644
--- a/lib/bb/parse/ast.py
+++ b/lib/bb/parse/ast.py
@@ -471,6 +471,9 @@  def finalize(fn, d, variant = None):
         if d.getVar("_FAILPARSINGERRORHANDLED", False) == True:
             raise bb.BBHandledException()
 
+        inherits = [x[0] for x in (d.getVar('__BBDEFINHERITS', False) or [('',)])]
+        bb.event.fire(bb.event.RecipePreDeferredInherits(fn, inherits), d)
+
         while True:
             inherits = d.getVar('__BBDEFINHERITS', False) or []
             if not inherits: