diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-12-31 13:29:10 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-01-18 10:15:58 +0000 |
commit | c56fce9e5621bf4353eb112a2555be7aadb048e6 (patch) | |
tree | c2f6e9010fbeebe12ad7fe4557b5e94f59caa7d6 /bitbake/lib/bb/parse/ast.py | |
parent | 663f1805742ff6fb6955719d0ab7846a425debcf (diff) | |
download | poky-c56fce9e5621bf4353eb112a2555be7aadb048e6.tar.gz |
bitbake: ast/BBHandler: Add inherit_defer support
Add support for an inherit_defer statement which works as
inherit does but is only evaulated at the end of parsing.
This allows conditional expressions to be evaulated 'late' meaning changes
to PACKAGECONFIG from bbappends can be applied for example. This addresses
a usability/confusion issue users have with the current conditional
inherit mechanism since they don't realise the condition has to be
expanded immediately with the current model.
There is a commented out warning we could enable in future which
warns about the use of a conditional inherit that isn't deferred.
There is a behaviour difference in the placement of the inherit,
particularly around variables set using ?= which means wen swapping
from one to the other, caution must be used as values can change.
(Bitbake rev: 5c2e840eafeba1f0f754c226b87bfb674f7bea29)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/parse/ast.py')
-rw-r--r-- | bitbake/lib/bb/parse/ast.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/bitbake/lib/bb/parse/ast.py b/bitbake/lib/bb/parse/ast.py index d30b688965..7581d003fd 100644 --- a/bitbake/lib/bb/parse/ast.py +++ b/bitbake/lib/bb/parse/ast.py | |||
@@ -314,6 +314,16 @@ class InheritNode(AstNode): | |||
314 | def eval(self, data): | 314 | def eval(self, data): |
315 | bb.parse.BBHandler.inherit(self.classes, self.filename, self.lineno, data) | 315 | bb.parse.BBHandler.inherit(self.classes, self.filename, self.lineno, data) |
316 | 316 | ||
317 | class InheritDeferredNode(AstNode): | ||
318 | def __init__(self, filename, lineno, classes): | ||
319 | AstNode.__init__(self, filename, lineno) | ||
320 | self.inherit = (classes, filename, lineno) | ||
321 | |||
322 | def eval(self, data): | ||
323 | inherits = data.getVar('__BBDEFINHERITS', False) or [] | ||
324 | inherits.append(self.inherit) | ||
325 | data.setVar('__BBDEFINHERITS', inherits) | ||
326 | |||
317 | def handleInclude(statements, filename, lineno, m, force): | 327 | def handleInclude(statements, filename, lineno, m, force): |
318 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) | 328 | statements.append(IncludeNode(filename, lineno, m.group(1), force)) |
319 | 329 | ||
@@ -364,6 +374,10 @@ def handleInherit(statements, filename, lineno, m): | |||
364 | classes = m.group(1) | 374 | classes = m.group(1) |
365 | statements.append(InheritNode(filename, lineno, classes)) | 375 | statements.append(InheritNode(filename, lineno, classes)) |
366 | 376 | ||
377 | def handleInheritDeferred(statements, filename, lineno, m): | ||
378 | classes = m.group(1) | ||
379 | statements.append(InheritDeferredNode(filename, lineno, classes)) | ||
380 | |||
367 | def runAnonFuncs(d): | 381 | def runAnonFuncs(d): |
368 | code = [] | 382 | code = [] |
369 | for funcname in d.getVar("__BBANONFUNCS", False) or []: | 383 | for funcname in d.getVar("__BBANONFUNCS", False) or []: |
@@ -430,6 +444,14 @@ def multi_finalize(fn, d): | |||
430 | logger.debug("Appending .bbappend file %s to %s", append, fn) | 444 | logger.debug("Appending .bbappend file %s to %s", append, fn) |
431 | bb.parse.BBHandler.handle(append, d, True) | 445 | bb.parse.BBHandler.handle(append, d, True) |
432 | 446 | ||
447 | while True: | ||
448 | inherits = d.getVar('__BBDEFINHERITS', False) or [] | ||
449 | if not inherits: | ||
450 | break | ||
451 | inherit, filename, lineno = inherits.pop(0) | ||
452 | d.setVar('__BBDEFINHERITS', inherits) | ||
453 | bb.parse.BBHandler.inherit(inherit, filename, lineno, d, deferred=True) | ||
454 | |||
433 | onlyfinalise = d.getVar("__ONLYFINALISE", False) | 455 | onlyfinalise = d.getVar("__ONLYFINALISE", False) |
434 | 456 | ||
435 | safe_d = d | 457 | safe_d = d |