diff options
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.rst | 144 |
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. | |||
754 | This section presents the mechanisms BitBake provides to allow you to | 754 | This section presents the mechanisms BitBake provides to allow you to |
755 | share functionality between recipes. Specifically, the mechanisms | 755 | share functionality between recipes. Specifically, the mechanisms |
756 | include ``include``, ``inherit``, :term:`INHERIT`, and ``require`` | 756 | include ``include``, ``inherit``, :term:`INHERIT`, and ``require`` |
757 | directives. | 757 | directives. There is also a higher-level abstraction called |
758 | ``configuration fragments`` that is enabled with ``addfragments`` | ||
759 | directive. | ||
758 | 760 | ||
759 | Locating Include and Class Files | 761 | Locating Include and Class Files |
760 | -------------------------------- | 762 | -------------------------------- |
@@ -771,6 +773,8 @@ In order for include and class files to be found by BitBake, they need | |||
771 | to be located in a "classes" subdirectory that can be found in | 773 | to 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>` |
810 | directives is that you can inherit class files conditionally. You can | 814 | directives is that you can inherit class files conditionally. You can |
811 | accomplish this by using a variable expression after the ``inherit`` | 815 | accomplish this by using a variable expression after the ``inherit`` |
812 | statement. Here is an example:: | 816 | statement. |
817 | |||
818 | For 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 | ||
821 | evaluated at the end of parsing. | ||
822 | |||
823 | .. _ref-bitbake-user-manual-metadata-inherit-defer: | ||
824 | |||
825 | ``inherit_defer`` Directive | ||
826 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
827 | |||
828 | The :ref:`inherit_defer <ref-bitbake-user-manual-metadata-inherit-defer>` | ||
829 | directive works like the :ref:`inherit | ||
830 | <ref-bitbake-user-manual-metadata-inherit>` directive, except that it is only | ||
831 | evaluated at the end of parsing. Its usage is recommended when a conditional | ||
832 | expression is used. | ||
813 | 833 | ||
814 | inherit ${VARNAME} | 834 | This allows conditional expressions to be evaluated "late", meaning changes to |
835 | the 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 | |||
838 | Here is an example:: | ||
839 | |||
840 | inherit_defer ${VARNAME} | ||
815 | 841 | ||
816 | If ``VARNAME`` is | 842 | If ``VARNAME`` is |
817 | going to be set, it needs to be set before the ``inherit`` statement is | 843 | going to be set, it needs to be set before the ``inherit_defer`` statement is |
818 | parsed. One way to achieve a conditional inherit in this case is to use | 844 | parsed. One way to achieve a conditional inherit in this case is to use |
819 | overrides:: | 845 | overrides:: |
820 | 846 | ||
821 | VARIABLE = "" | 847 | VARIABLE = "" |
822 | VARIABLE:someoverride = "myclass" | 848 | VARIABLE:someoverride = "myclass" |
823 | 849 | ||
824 | Another method is by using anonymous Python. Here is an example:: | 850 | Another method is by using :ref:`anonymous Python |
851 | <bitbake-user-manual/bitbake-user-manual-metadata:Anonymous Python Functions>`. | ||
852 | Here 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 | ||
833 | Alternatively, you could use an in-line Python expression in the | 861 | Alternatively, you could use an inline Python expression in the |
834 | following form:: | 862 | following form:: |
835 | 863 | ||
836 | inherit ${@'classname' if condition else ''} | 864 | inherit_defer ${@'classname' if condition else ''} |
837 | inherit ${@functionname(params)} | 865 | |
866 | Or:: | ||
867 | |||
868 | inherit_defer ${@bb.utils.contains('VARIABLE', 'something', 'classname', '', d)} | ||
838 | 869 | ||
839 | In all cases, if the expression evaluates to an | 870 | In all cases, if the expression evaluates to an |
840 | empty string, the statement does not trigger a syntax error because it | 871 | empty 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 | |||
906 | The ``include_all`` directive works like the :ref:`include | ||
907 | <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` | ||
908 | directive but will include all of the files that match the specified path in | ||
909 | the enabled layers (layers part of :term:`BBLAYERS`). | ||
910 | |||
911 | For example, let's say a ``maintainers.inc`` file is present in different layers | ||
912 | and is conventionally placed in the ``conf/distro/include`` directory of each | ||
913 | layer. In that case the ``include_all`` directive can be used to include | ||
914 | the ``maintainers.inc`` file for all of these layers:: | ||
915 | |||
916 | include_all conf/distro/include/maintainers.inc | ||
917 | |||
918 | In other words, the ``maintainers.inc`` file for each layer is included through | ||
919 | the :ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` | ||
920 | directive. | ||
921 | |||
922 | BitBake will iterate through the colon-separated :term:`BBPATH` list to look for | ||
923 | matching files to include, from left to right. As a consequence, matching files | ||
924 | are included in that order. | ||
925 | |||
926 | As the ``include_all`` directive uses the :ref:`include | ||
927 | <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` | ||
928 | directive 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 | |||
997 | This directive allows fine-tuning local configurations with configuration | ||
998 | snippets contained in layers in a structured, controlled way. Typically it would | ||
999 | go 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 | |||
1016 | This allows listing enabled configuration fragments in ``OE_FRAGMENTS`` | ||
1017 | variable like this:: | ||
1018 | |||
1019 | OE_FRAGMENTS = "core/domain/somefragment core/someotherfragment anotherlayer/anotherdomain/anotherfragment" | ||
1020 | |||
1021 | Fragment names listed in this variable must be prefixed by the layer name | ||
1022 | where a fragment file is located, defined by :term:`BBFILE_COLLECTIONS` in ``layer.conf``. | ||
1023 | |||
1024 | The implementation then expands this list into | ||
1025 | :ref:`require <bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>` | ||
1026 | directives 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 | |||
1032 | The 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 | |||
1036 | The implementation will add a flag containing the fragment name to each of those variables | ||
1037 | when parsing fragments, so that the variables are namespaced by fragment name, and do not override | ||
1038 | each other when several fragments are enabled. | ||
1039 | |||
1040 | The variable containing a built-in fragment definitions could look like this:: | ||
1041 | |||
1042 | OE_BUILTIN_FRAGMENTS = "someprefix:SOMEVARIABLE anotherprefix:ANOTHERVARIABLE" | ||
1043 | |||
1044 | and then if 'someprefix/somevalue' is added to the variable that holds the list | ||
1045 | of enabled fragments: | ||
1046 | |||
1047 | OE_FRAGMENTS = "... someprefix/somevalue" | ||
1048 | |||
1049 | bitbake will treat that as direct value assignment in its configuration:: | ||
1050 | |||
1051 | SOMEVARIABLE = "somevalue" | ||
1052 | |||
936 | Functions | 1053 | Functions |
937 | ========= | 1054 | ========= |
938 | 1055 | ||
@@ -1303,8 +1420,8 @@ the task and other tasks. Here is an example that shows how to define a | |||
1303 | task and declare some dependencies:: | 1420 | task 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: | |||
1972 | Other Functions | 2089 | Other Functions |
1973 | --------------- | 2090 | --------------- |
1974 | 2091 | ||
1975 | You can find many other functions that can be called from Python by | 2092 | Other functions are documented in the |
1976 | looking 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 | ||
1978 | the commonly used functions ``bb.utils.contains()`` and | ||
1979 | ``bb.utils.mkdirhier()``, which come with docstrings. | ||
1980 | 2094 | ||
1981 | Extending Python Library Code | 2095 | Extending Python Library Code |
1982 | ----------------------------- | 2096 | ----------------------------- |