From f53fe9c84aca500f12915a2e1c5d3f189fc8af0c Mon Sep 17 00:00:00 2001 From: Antonin Godard Date: Wed, 20 Nov 2024 10:30:02 +0100 Subject: bitbake: doc: bitbake-user-manual: document inherit_defer This was added in 2.7.2. Since using inherit_defer is safer that inherit when inheriting conditionally, move the instructions about that in inherit_defer. Fixes [YOCTO #15640]. Reported-by: Yoann Congal (Bitbake rev: eb10df5a9619e243e28e0f4cd6122c24ed668f52) Signed-off-by: Antonin Godard Signed-off-by: Mathieu Dubois-Briand Signed-off-by: Richard Purdie --- .../bitbake-user-manual-metadata.rst | 43 ++++++++++++++++++---- 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'bitbake') diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst index 58975f4c88..40a0c6f02d 100644 --- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst @@ -771,6 +771,8 @@ In order for include and class files to be found by BitBake, they need to be located in a "classes" subdirectory that can be found in :term:`BBPATH`. +.. _ref-bitbake-user-manual-metadata-inherit: + ``inherit`` Directive --------------------- @@ -809,19 +811,43 @@ An advantage with the inherit directive as compared to both the :ref:`include ` and :ref:`require ` directives is that you can inherit class files conditionally. You can accomplish this by using a variable expression after the ``inherit`` -statement. Here is an example:: +statement. + +For inheriting classes conditionally, using the :ref:`inherit_defer +` directive is advised as +:ref:`inherit_defer ` is +evaluated at the end of parsing. + +.. _ref-bitbake-user-manual-metadata-inherit-defer: + +``inherit_defer`` Directive +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The :ref:`inherit_defer ` +directive works like the :ref:`inherit +` directive, except that it is only +evaluated at the end of parsing. Its usage is recommended when a conditional +expression is used. - inherit ${VARNAME} +This allows conditional expressions to be evaluated "late", meaning changes to +the variable after the line is parsed will take effect. With the :ref:`inherit +` directive this is not the case. + +Here is an example:: + + inherit_defer ${VARNAME} If ``VARNAME`` is -going to be set, it needs to be set before the ``inherit`` statement is +going to be set, it needs to be set before the ``inherit_defer`` statement is parsed. One way to achieve a conditional inherit in this case is to use overrides:: VARIABLE = "" VARIABLE:someoverride = "myclass" -Another method is by using anonymous Python. Here is an example:: +Another method is by using :ref:`anonymous Python +`. +Here is an example:: python () { if condition == value: @@ -830,11 +856,14 @@ Another method is by using anonymous Python. Here is an example:: d.setVar('VARIABLE', '') } -Alternatively, you could use an in-line Python expression in the +Alternatively, you could use an inline Python expression in the following form:: - inherit ${@'classname' if condition else ''} - inherit ${@functionname(params)} + inherit_defer ${@'classname' if condition else ''} + +Or:: + + inherit_defer ${@bb.utils.contains('VARIABLE', 'something', 'classname', '', d)} In all cases, if the expression evaluates to an empty string, the statement does not trigger a syntax error because it -- cgit v1.2.3-54-g00ecf