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