summaryrefslogtreecommitdiffstats
path: root/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst')
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst144
1 files changed, 129 insertions, 15 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..f60a9d8312 100644
--- a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-metadata.rst
@@ -754,7 +754,9 @@ share the task.
754This section presents the mechanisms BitBake provides to allow you to 754This section presents the mechanisms BitBake provides to allow you to
755share functionality between recipes. Specifically, the mechanisms 755share functionality between recipes. Specifically, the mechanisms
756include ``include``, ``inherit``, :term:`INHERIT`, and ``require`` 756include ``include``, ``inherit``, :term:`INHERIT`, and ``require``
757directives. 757directives. There is also a higher-level abstraction called
758``configuration fragments`` that is enabled with ``addfragments``
759directive.
758 760
759Locating Include and Class Files 761Locating Include and Class Files
760-------------------------------- 762--------------------------------
@@ -771,6 +773,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 773to be located in a "classes" subdirectory that can be found in
772:term:`BBPATH`. 774:term:`BBPATH`.
773 775
776.. _ref-bitbake-user-manual-metadata-inherit:
777
774``inherit`` Directive 778``inherit`` Directive
775--------------------- 779---------------------
776 780
@@ -809,19 +813,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>` 813: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 814directives is that you can inherit class files conditionally. You can
811accomplish this by using a variable expression after the ``inherit`` 815accomplish this by using a variable expression after the ``inherit``
812statement. Here is an example:: 816statement.
817
818For inheriting classes conditionally, using the :ref:`inherit_defer
819<ref-bitbake-user-manual-metadata-inherit-defer>` directive is advised as
820:ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>` is
821evaluated at the end of parsing.
822
823.. _ref-bitbake-user-manual-metadata-inherit-defer:
824
825``inherit_defer`` Directive
826~~~~~~~~~~~~~~~~~~~~~~~~~~~
827
828The :ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>`
829directive works like the :ref:`inherit
830<ref-bitbake-user-manual-metadata-inherit>` directive, except that it is only
831evaluated at the end of parsing. Its usage is recommended when a conditional
832expression is used.
813 833
814 inherit ${VARNAME} 834This allows conditional expressions to be evaluated "late", meaning changes to
835the variable after the line is parsed will take effect. With the :ref:`inherit
836<ref-bitbake-user-manual-metadata-inherit>` directive this is not the case.
837
838Here is an example::
839
840 inherit_defer ${VARNAME}
815 841
816If ``VARNAME`` is 842If ``VARNAME`` is
817going to be set, it needs to be set before the ``inherit`` statement is 843going 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 844parsed. One way to achieve a conditional inherit in this case is to use
819overrides:: 845overrides::
820 846
821 VARIABLE = "" 847 VARIABLE = ""
822 VARIABLE:someoverride = "myclass" 848 VARIABLE:someoverride = "myclass"
823 849
824Another method is by using anonymous Python. Here is an example:: 850Another method is by using :ref:`anonymous Python
851<bitbake-user-manual/bitbake-user-manual-metadata:Anonymous Python Functions>`.
852Here is an example::
825 853
826 python () { 854 python () {
827 if condition == value: 855 if condition == value:
@@ -830,11 +858,14 @@ Another method is by using anonymous Python. Here is an example::
830 d.setVar('VARIABLE', '') 858 d.setVar('VARIABLE', '')
831 } 859 }
832 860
833Alternatively, you could use an in-line Python expression in the 861Alternatively, you could use an inline Python expression in the
834following form:: 862following form::
835 863
836 inherit ${@'classname' if condition else ''} 864 inherit_defer ${@'classname' if condition else ''}
837 inherit ${@functionname(params)} 865
866Or::
867
868 inherit_defer ${@bb.utils.contains('VARIABLE', 'something', 'classname', '', d)}
838 869
839In all cases, if the expression evaluates to an 870In all cases, if the expression evaluates to an
840empty string, the statement does not trigger a syntax error because it 871empty string, the statement does not trigger a syntax error because it
@@ -869,6 +900,33 @@ definitions::
869 of include . Doing so makes sure that an error is produced if the file cannot 900 of include . Doing so makes sure that an error is produced if the file cannot
870 be found. 901 be found.
871 902
903``include_all`` Directive
904-------------------------
905
906The ``include_all`` directive works like the :ref:`include
907<bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>`
908directive but will include all of the files that match the specified path in
909the enabled layers (layers part of :term:`BBLAYERS`).
910
911For example, let's say a ``maintainers.inc`` file is present in different layers
912and is conventionally placed in the ``conf/distro/include`` directory of each
913layer. In that case the ``include_all`` directive can be used to include
914the ``maintainers.inc`` file for all of these layers::
915
916 include_all conf/distro/include/maintainers.inc
917
918In other words, the ``maintainers.inc`` file for each layer is included through
919the :ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>`
920directive.
921
922BitBake will iterate through the colon-separated :term:`BBPATH` list to look for
923matching files to include, from left to right. As a consequence, matching files
924are included in that order.
925
926As the ``include_all`` directive uses the :ref:`include
927<bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>`
928directive in the background, no error is produced if no files are matched.
929
872.. _require-inclusion: 930.. _require-inclusion:
873 931
874``require`` Directive 932``require`` Directive
@@ -933,6 +991,65 @@ the ``autotools`` and ``pkgconfig`` classes::
933 991
934 INHERIT += "autotools pkgconfig" 992 INHERIT += "autotools pkgconfig"
935 993
994``addfragments`` Directive
995--------------------------
996
997This directive allows fine-tuning local configurations with configuration
998snippets contained in layers in a structured, controlled way. Typically it would
999go into ``bitbake.conf``, for example::
1000
1001 addfragments conf/fragments OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS OE_BUILTIN_FRAGMENTS
1002
1003``addfragments`` takes four parameters:
1004
1005- path prefix for fragment files inside the layer file tree that bitbake
1006 uses to construct full paths to the fragment files
1007
1008- name of variable that holds the list of enabled fragments in an
1009 active build
1010
1011- name of variable that contains a list of variable names containing
1012 fragment-specific metadata (such as descriptions)
1013
1014- name of variable that contains definitions for built-in fragments
1015
1016This allows listing enabled configuration fragments in ``OE_FRAGMENTS``
1017variable like this::
1018
1019 OE_FRAGMENTS = "core/domain/somefragment core/someotherfragment anotherlayer/anotherdomain/anotherfragment"
1020
1021Fragment names listed in this variable must be prefixed by the layer name
1022where a fragment file is located, defined by :term:`BBFILE_COLLECTIONS` in ``layer.conf``.
1023
1024The implementation then expands this list into
1025:ref:`require <bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>`
1026directives with full paths to respective layers::
1027
1028 require /path/to/core-layer/conf/fragments/domain/somefragment.conf
1029 require /path/to/core-layer/conf/fragments/someotherfragment.conf
1030 require /path/to/another-layer/conf/fragments/anotherdomain/anotherfragment.conf
1031
1032The variable containing a list of fragment metadata variables could look like this::
1033
1034 OE_FRAGMENTS_METADATA_VARS = "BB_CONF_FRAGMENT_SUMMARY BB_CONF_FRAGMENT_DESCRIPTION"
1035
1036The implementation will add a flag containing the fragment name to each of those variables
1037when parsing fragments, so that the variables are namespaced by fragment name, and do not override
1038each other when several fragments are enabled.
1039
1040The variable containing a built-in fragment definitions could look like this::
1041
1042 OE_BUILTIN_FRAGMENTS = "someprefix:SOMEVARIABLE anotherprefix:ANOTHERVARIABLE"
1043
1044and then if 'someprefix/somevalue' is added to the variable that holds the list
1045of enabled fragments:
1046
1047 OE_FRAGMENTS = "... someprefix/somevalue"
1048
1049bitbake will treat that as direct value assignment in its configuration::
1050
1051 SOMEVARIABLE = "somevalue"
1052
936Functions 1053Functions
937========= 1054=========
938 1055
@@ -1303,8 +1420,8 @@ the task and other tasks. Here is an example that shows how to define a
1303task and declare some dependencies:: 1420task and declare some dependencies::
1304 1421
1305 python do_printdate () { 1422 python do_printdate () {
1306 import time 1423 import datetime
1307 print time.strftime('%Y%m%d', time.gmtime()) 1424 bb.plain('Date: %s' % (datetime.date.today()))
1308 } 1425 }
1309 addtask printdate after do_fetch before do_build 1426 addtask printdate after do_fetch before do_build
1310 1427
@@ -1972,11 +2089,8 @@ access. Here is a list of available operations:
1972Other Functions 2089Other Functions
1973--------------- 2090---------------
1974 2091
1975You can find many other functions that can be called from Python by 2092Other functions are documented in the
1976looking at the source code of the ``bb`` module, which is in 2093:doc:`/bitbake-user-manual/bitbake-user-manual-library-functions` document.
1977``bitbake/lib/bb``. For example, ``bitbake/lib/bb/utils.py`` includes
1978the commonly used functions ``bb.utils.contains()`` and
1979``bb.utils.mkdirhier()``, which come with docstrings.
1980 2094
1981Extending Python Library Code 2095Extending Python Library Code
1982----------------------------- 2096-----------------------------