summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonin Godard <antonin.godard@bootlin.com>2024-11-20 10:30:02 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-11-28 00:06:24 +0000
commitf53fe9c84aca500f12915a2e1c5d3f189fc8af0c (patch)
treec4a92fe482c3c2ad92d6a04a794df38a53d9e20c
parent4ffd0e559af909fa7afa43a62f91c3e4f3d5c48e (diff)
downloadpoky-f53fe9c84aca500f12915a2e1c5d3f189fc8af0c.tar.gz
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 <yoann.congal@smile.fr> (Bitbake rev: eb10df5a9619e243e28e0f4cd6122c24ed668f52) Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst43
1 files changed, 36 insertions, 7 deletions
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
771to be located in a "classes" subdirectory that can be found in 771to be located in a "classes" subdirectory that can be found in
772:term:`BBPATH`. 772:term:`BBPATH`.
773 773
774.. _ref-bitbake-user-manual-metadata-inherit:
775
774``inherit`` Directive 776``inherit`` Directive
775--------------------- 777---------------------
776 778
@@ -809,19 +811,43 @@ An advantage with the inherit directive as compared to both the
809:ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` and :ref:`require <bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>` 811:ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` and :ref:`require <bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>`
810directives is that you can inherit class files conditionally. You can 812directives is that you can inherit class files conditionally. You can
811accomplish this by using a variable expression after the ``inherit`` 813accomplish this by using a variable expression after the ``inherit``
812statement. Here is an example:: 814statement.
815
816For inheriting classes conditionally, using the :ref:`inherit_defer
817<ref-bitbake-user-manual-metadata-inherit-defer>` directive is advised as
818:ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>` is
819evaluated at the end of parsing.
820
821.. _ref-bitbake-user-manual-metadata-inherit-defer:
822
823``inherit_defer`` Directive
824~~~~~~~~~~~~~~~~~~~~~~~~~~~
825
826The :ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>`
827directive works like the :ref:`inherit
828<ref-bitbake-user-manual-metadata-inherit>` directive, except that it is only
829evaluated at the end of parsing. Its usage is recommended when a conditional
830expression is used.
813 831
814 inherit ${VARNAME} 832This allows conditional expressions to be evaluated "late", meaning changes to
833the variable after the line is parsed will take effect. With the :ref:`inherit
834<ref-bitbake-user-manual-metadata-inherit>` directive this is not the case.
835
836Here is an example::
837
838 inherit_defer ${VARNAME}
815 839
816If ``VARNAME`` is 840If ``VARNAME`` is
817going to be set, it needs to be set before the ``inherit`` statement is 841going to be set, it needs to be set before the ``inherit_defer`` statement is
818parsed. One way to achieve a conditional inherit in this case is to use 842parsed. One way to achieve a conditional inherit in this case is to use
819overrides:: 843overrides::
820 844
821 VARIABLE = "" 845 VARIABLE = ""
822 VARIABLE:someoverride = "myclass" 846 VARIABLE:someoverride = "myclass"
823 847
824Another method is by using anonymous Python. Here is an example:: 848Another method is by using :ref:`anonymous Python
849<bitbake-user-manual/bitbake-user-manual-metadata:Anonymous Python Functions>`.
850Here is an example::
825 851
826 python () { 852 python () {
827 if condition == value: 853 if condition == value:
@@ -830,11 +856,14 @@ Another method is by using anonymous Python. Here is an example::
830 d.setVar('VARIABLE', '') 856 d.setVar('VARIABLE', '')
831 } 857 }
832 858
833Alternatively, you could use an in-line Python expression in the 859Alternatively, you could use an inline Python expression in the
834following form:: 860following form::
835 861
836 inherit ${@'classname' if condition else ''} 862 inherit_defer ${@'classname' if condition else ''}
837 inherit ${@functionname(params)} 863
864Or::
865
866 inherit_defer ${@bb.utils.contains('VARIABLE', 'something', 'classname', '', d)}
838 867
839In all cases, if the expression evaluates to an 868In all cases, if the expression evaluates to an
840empty string, the statement does not trigger a syntax error because it 869empty string, the statement does not trigger a syntax error because it