doc: extend classes and include/require documentation
PATCH 1/1 doc: extend classes and include/require documentation
The current documentation is lacking details on the different kinds of directories for putting classes as well as the order in which BitBake includes files (classes or include files).
This patch does the following changes:
- Mention the missing classes-recipe and classes-global when applicable.
- Add a Class Types section detailed the three different directories for putting classes.
- Move the existing section on locating classes/include files below the documentation on the different directives (include/require/inherit).
- Extend the documentation on locating files with include/require and inherit to give proper examples, hopefully demystifying this mechanism a bit.
[YOCTO #15724]
--- .../bitbake-user-manual-execution.rst | 10 +- .../bitbake-user-manual-intro.rst | 34 ++++-- .../bitbake-user-manual-metadata.rst | 116 ++++++++++++++++++--- 3 files changed, 131 insertions(+), 29 deletions(-)
doc/bitbake-user-manual/bitbake-user-manual-execution.rst +5 -5
@@ -64,11 +64,11 @@ data itself is of various types: together. The ``layer.conf`` files are used to construct key variables such as -:term:`BBPATH` and :term:`BBFILES`. -:term:`BBPATH` is used to search for configuration and class files under the -``conf`` and ``classes`` directories, respectively. :term:`BBFILES` is used -to locate both recipe and recipe append files (``.bb`` and -``.bbappend``). If there is no ``bblayers.conf`` file, it is assumed the +:term:`BBPATH` and :term:`BBFILES`. :term:`BBPATH` is used to search for +configuration files under the ``conf`` directory and class files under the +``classes-global``, ``classes-recipe`` and ``classes`` directories. +:term:`BBFILES` is used to locate both recipe and recipe append files (``.bb`` +and ``.bbappend``). If there is no ``bblayers.conf`` file, it is assumed the user has set the :term:`BBPATH` and :term:`BBFILES` directly in the environment. Next, the ``bitbake.conf`` file is located using the :term:`BBPATH` variable
doc/bitbake-user-manual/bitbake-user-manual-intro.rst +25 -9
@@ -206,17 +206,33 @@ installing (empty by default) and packaging (empty by default). These tasks are often overridden or extended by other classes added during the project development process. -.. note:: +Class Types +~~~~~~~~~~~ + +BitBake supports class files installed in three different directories: + +- ``classes-global/``: these classes must be inherited globally through the + :term:`INHERIT` variable in a :ref:`configuration file + <bitbake-user-manual/bitbake-user-manual-intro:Configuration Files>`. These + classes are included for every recipe being built. For example, you would use + the global class named ``myclass`` like so:: + + INHERIT += "myclass" + +- ``classes-recipe/``: these classes must be inherited from a recipe using the + :ref:`inherit <ref-bitbake-user-manual-metadata-inherit>` directive. They do + not support being inherited globally. For example, you would use the recipe + class named ``myclass`` like so:: + + inherit myclass - While BitBake comes with just the one ``base.bbclass`` file in the - ``classes`` directory, it supports class files also being installed - in related directories ``classes-global`` and ``classes-recipe`` and - will automatically search all three directories for a selected class - file. +- ``classes/``: this final directory is meant for classes that can be used in + the two contexts explain above. In other words, they can be inherit either + globally or in a recipe. - This means that, in this documentation, when you see a reference to - class files being in the ``classes`` directory, you can interpret that - as meaning in any one of the above three directories. +For details on how BitBake locates class files, see the +:ref:`bitbake-user-manual/bitbake-user-manual-metadata:Locating Class Files` +section of the Bitbake User Manual. Layers ------
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +101 -15
140 lines not on this page · raw message
---
base-commit: 546b347b4d3d82c01ecc99f45296f66e44638adc
change-id: 20250917-classes-order-d4d9ae602a8f
Best regards,
Signature · 1 line
Antonin Godard <[email protected]>
Hi Antonin,
Just had the time to review this, sorry for the delay. I'll send a few typo and rewording patches soon. However...
On 9/18/25 2:16 PM, Antonin Godard via lists.yoctoproject.org wrote:
[...]
Quoted 39 lines
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +39
-0+Locating Include Files +---------------------- + +BitBake uses the :term:`BBPATH` variable to locate needed include files. +Additionally, BitBake searches the current directory for :ref:`include +<ref-include-directive>` and :ref:`require <require-inclusion>` directives. + +.. note:: + + The BBPATH variable is analogous to the environment variable PATH . + +For these two directives, BitBake includes the first file it finds. + +.. note:: + + It is also possible to include *all* occurences of a file with the same name + with the :ref:`include_all <ref-include-all-directive>` directive. + +Let's consider the following statement called from a recipe file located in +``/layers/meta-custom2/recipes-example/example_0.1.bb``:: + + require myfile.inc + +Where ``myfile.inc`` is located in ``/layers/meta-custom2/recipes-example/``. + +And let's assume that the value of :term:`BBPATH` is +``/layers/meta-custom1:/layers/meta-custom2``. Then BitBake will try to find +``myfile.inc`` in this order:: + + /layers/meta-custom2/recipes-example/example/myfile.inc + /layers/meta-custom1/myfile.inc + /layers/meta-custom2/myfile.inc + +In this case the first path of the list matches and BitBake includes this file +in ``example_0.1.bb``. + +Another common example would be:: + + require recipes-other/other/otherfile.inc
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst bitbake will treat that as direct value assignment in its configuration:: · line 1102
Quoted 10 lines
doc/bitbake-user-manual/bitbake-user-manual-metadata.rst +10
-0+ +Where ``otherfile.inc`` is located in +``/layers/meta-custom1/recipes-other/other/``. + +In this case, the following paths would be searched:: + + /layers/meta-custom2/recipes-example/example/recipes-other/other/otherfile.inc + /layers/meta-custom1/recipes-other/other/otherfile.inc + /layers/meta-custom2/recipes-other/other/otherfile.inc +
I think we should provide an example for include_all directive as well? After reading the code, I believe include_all does NOT search the local path first, it only searches paths in BBPATH so I think it's worth providing an example and maybe notes on how it differs from the other directives.
What do you think?
Cheers,
Quentin
Hi,
On Wed Dec 3, 2025 at 5:55 PM CET, Quentin Schulz via lists.yoctoproject.org wrote:
[...]
Quoted 7 lines
I think we should provide an example for
include_alldirective as well? After reading the code, I believeinclude_alldoes NOT search the local path first, it only searches paths in BBPATH so I think it's worth providing an example and maybe notes on how it differs from the other directives.What do you think?
That's a good point I forgot here, yes, we should explain it to be complete. Can you send a patch of file a bug?
Thanks,
Antonin
Signature · 3 lines
Antonin Godard, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi Antonin,
Quoted 10 lines · Antonin Godard
Hi,
On Wed Dec 3, 2025 at 5:55 PM CET, Quentin Schulz via lists.yoctoproject.org wrote:
[...]Quoted 6 lines
I think we should provide an example for
include_alldirective as well? After reading the code, I believeinclude_alldoes NOT search the local path first, it only searches paths in BBPATH so I think it's worth providing an example and maybe notes on how it differs from the other directives.
Quoted 5 lines
Quoted 1 line
What do you think?
That's a good point I forgot here, yes, we should explain it to be complete. Can you send a patch of file a bug?
Finally took the time to write a patch, see
https://lore.kernel.org/yocto-docs/[email protected]/
Cheers,
Quentin