creating-fragments.rst 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Creating New Configuration Fragments In Your Build
  3. **************************************************
  4. :term:`Configuration Fragments <Configuration Fragment>` define top level build
  5. configuration features that can be independently enabled and disabled using
  6. standard tooling. Such features are made of one or several build configuration
  7. statements that are either contained in a fragment file, or are set indirectly
  8. using the :term:`Built-in Fragment` mechanism.
  9. This section will describe how to create new fragments for your builds.
  10. There are two kinds of configuration fragments:
  11. - Standard :term:`Configuration Fragments <Configuration Fragment>` which a
  12. stored in a file. These fragments include a summary and a description,
  13. following by configuration statements.
  14. - :term:`Built-in Fragments <Built-in Fragment>` which can be used to assign a
  15. value to a single variable and do not require a separate definition file.
  16. They are especially useful when a list of possible values is very long (or
  17. infinite).
  18. Creating A Standard Configuration Fragment
  19. ==========================================
  20. By default, all configuration fragments are located within the
  21. ``conf/fragments`` directory of a :term:`layer`. This location is defined by the
  22. :term:`OE_FRAGMENTS_PREFIX` variable which, in turn, is used as a parameter in an
  23. :ref:`addfragments <bitbake-user-manual/bitbake-user-manual-metadata:\`\`addfragments\`\`
  24. directive>` directive in :oe_git:`bitbake.conf </openembedded-core/tree/meta/conf/bitbake.conf>`.
  25. You can create one or more :term:`configuration fragment` files in your
  26. :term:`layer` in this directory. Let's take the following example, where
  27. ``custom-fragment.conf`` is our custom fragment file::
  28. meta-custom
  29. ├── conf
  30. │   ├── fragments
  31. │   │   └── custom-fragment.conf
  32. │   └── layer.conf
  33. ...
  34. For our ``custom-fragment.conf`` file, the following variables **must** be set
  35. for our fragment to be considered a valid fragment by the :term:`OpenEmbedded
  36. Build System`:
  37. - :term:`BB_CONF_FRAGMENT_SUMMARY`: a one-line summary of this fragment.
  38. - :term:`BB_CONF_FRAGMENT_DESCRIPTION`: a description of this fragment.
  39. .. note::
  40. The :term:`BB_CONF_FRAGMENT_SUMMARY` and :term:`BB_CONF_FRAGMENT_DESCRIPTION`
  41. variables are also passed as parameters in an :ref:`addfragments
  42. <bitbake-user-manual/bitbake-user-manual-metadata:\`\`addfragments\`\`
  43. directive>` directive in :oe_git:`bitbake.conf
  44. </openembedded-core/tree/meta/conf/bitbake.conf>`.
  45. After creating these variables, our custom fragment should look like the
  46. following:
  47. .. code-block::
  48. :caption: custom-fragment.conf
  49. BB_CONF_FRAGMENT_SUMMARY = "This fragment sets a limit of 4 bitbake threads and 4 parsing threads"
  50. BB_CONF_FRAGMENT_DESCRIPTION = "This fragment is useful to constrain resource consumption when the Yocto default \
  51. is causing an overload of host machine's memory and CPU resources."
  52. For now, our fragment does not have any additional configuration statement.
  53. Let's add the following assignments to our fragment:
  54. .. code-block::
  55. :caption: custom-fragment.conf (continued)
  56. BB_NUMBER_THREADS = "4"
  57. BB_NUMBER_PARSE_THREADS = "4"
  58. This means that our fragment can be enabled to set a limit on the number of
  59. threads :term:`BitBake` will use with the :term:`BB_NUMBER_THREADS` and
  60. :term:`BB_NUMBER_PARSE_THREADS` variables.
  61. For now, our fragment exists and is listed by the
  62. :ref:`ref-bitbake-config-build-list-fragments` command, but is not enabled. To
  63. enable this fragment, use the :ref:`ref-bitbake-config-build-enable-fragment`
  64. command::
  65. bitbake-config-build enable-fragment meta-custom/custom-fragment
  66. .. note::
  67. The ``meta-custom`` prefix in the above command depends on the name of your
  68. layer. This name is defined by the :term:`BBFILE_COLLECTIONS` variable in
  69. the ``conf/layer.conf`` file of your layer.
  70. Standard Configuration fragments can be organized in a more complex way. For
  71. example, it's possible to create sub-directories to organize your fragments::
  72. meta-custom
  73. ├── conf
  74. │   ├── fragments
  75. │   │   ├── networking
  76. │   │   │   └── mirrors.conf
  77. │   │   └── resources
  78. │   │   └── numberthreads.conf
  79. │   └── layer.conf
  80. ...
  81. In the above example, the ``meta-custom/networking/mirrors`` and
  82. ``meta-custom/resources/numberthreads`` fragments will be available in your
  83. build.
  84. Creating A Built-in Fragment
  85. ============================
  86. Within the :term:`OpenEmbedded Build System`, Built-in Fragments are defined
  87. with the :term:`OE_FRAGMENTS_BUILTIN` variable, which is passed as a
  88. parameter in an :ref:`addfragments <bitbake-user-manual/bitbake-user-manual-metadata:\`\`addfragments\`\`
  89. directive>` directive in :oe_git:`bitbake.conf </openembedded-core/tree/meta/conf/bitbake.conf>`.
  90. Adding new :term:`Built-in Fragments <Built-in Fragment>` can be done by
  91. appending the :term:`OE_FRAGMENTS_BUILTIN` variable from your :term:`layer`
  92. configuration file:
  93. .. code-block::
  94. :caption: layer.conf
  95. OE_FRAGMENTS_BUILTIN:append = " custom-builtin-fragment:CUSTOM_VARIABLE"
  96. .. warning::
  97. Make sure to use the ``:append`` override in the above assignment, as using
  98. ``+=`` can lead to unexpected behavior.
  99. .. warning::
  100. Due to the way :term:`BitBake` parses files, it is not possible to modify
  101. :term:`OE_FRAGMENTS_BUILTIN` from any kind of :term:`configuration file`.
  102. Setting it from the :term:`layer` configuration file (``conf/layer.conf``) is
  103. the retained solution to create new built-in fragments.
  104. You can then use the :ref:`ref-bitbake-config-build-enable-fragment` command to
  105. set a value to the ``CUSTOM_VARIABLE`` variable::
  106. bitbake-config-build enable-fragment custom-builtin-fragment/somevalue