summaryrefslogtreecommitdiffstats
path: root/documentation
diff options
context:
space:
mode:
authorAntonin Godard <antonin.godard@bootlin.com>2024-11-13 16:28:12 +0100
committerSteve Sakoman <steve@sakoman.com>2024-11-18 06:59:35 -0800
commitbc6bd220a0cdc98e5d46319c6a091a44740a3e7a (patch)
treeeeb2e7b66719f0351c97eef9eb8f01c7b2a9c852 /documentation
parenta9cdf867e4ea3f6606b7711333b3266cac5ca9fb (diff)
downloadpoky-bc6bd220a0cdc98e5d46319c6a091a44740a3e7a.tar.gz
dev-manual: document how to provide confs from layer.conf
Add a section on providing global level configuration from the layer.conf file. Since this file is parsed at an earlier stage in the parsing process, it's not possible to combine bb.utils.contains and {DISTRO,MACHINE}_FEATURES to conditionally set some configurations. This patch documents: - First that this file can be used for providing such configuration. - Then demonstrate how to conditionally provide them, using a technique that is currently used in meta-virtualization (https://git.yoctoproject.org/meta-virtualization/tree/conf/layer.conf#n50). Fixes [YOCTO #12688]. Reviewed-by: Quentin Schulz <quentin.schulz@cherry.de> (From yocto-docs rev: 36f2a230ca810b1dd221b7c8ce71e8086291131a) Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> (cherry picked from commit 31e5bd3e82e11f77da2abd96eb8c17a7c8194b7c) Signed-off-by: Antonin Godard <antonin.godard@bootlin.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'documentation')
-rw-r--r--documentation/dev-manual/layers.rst90
1 files changed, 90 insertions, 0 deletions
diff --git a/documentation/dev-manual/layers.rst b/documentation/dev-manual/layers.rst
index 91889bd0ae..89c8466933 100644
--- a/documentation/dev-manual/layers.rst
+++ b/documentation/dev-manual/layers.rst
@@ -644,6 +644,96 @@ variable and append the layer's root name::
644 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake 644 order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake
645 might address this. 645 might address this.
646 646
647Providing Global-level Configurations With Your Layer
648-----------------------------------------------------
649
650When creating a layer, you may need to define configurations that should take
651effect globally in your build environment when the layer is part of the build.
652The ``layer.conf`` file is a :term:`configuration file` that affects the build
653system globally, so it is a candidate for this use-case.
654
655.. warning::
656
657 Providing unconditional global level configuration from the ``layer.conf``
658 file is *not* a good practice, and should be avoided. For this reason, the
659 section :ref:`ref-conditional-layer-confs` below shows how the ``layer.conf``
660 file can be used to provide configurations only if a certain condition is
661 met.
662
663For example, if your layer provides a Linux kernel recipe named
664``linux-custom``, you may want to make :term:`PREFERRED_PROVIDER_virtual/kernel
665<PREFERRED_PROVIDER>` point to ``linux-custom``::
666
667 PREFERRED_PROVIDER_virtual/kernel = "linux-custom"
668
669This can be defined in the ``layer.conf`` file. If your layer is at the last
670position in the :term:`BBLAYERS` list, it will take precedence over previous
671``PREFERRED_PROVIDER_virtual/kernel`` assignments (unless one is set from a
672:term:`configuration file` that is parsed later, such as machine or distro
673configuration files).
674
675.. _ref-conditional-layer-confs:
676
677Conditionally Provide Global-level Configurations With Your Layer
678^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
679
680In some cases, your layer may provide global configurations only if some
681features it provides are enabled. Since the ``layer.conf`` file is parsed at an
682earlier stage in the parsing process, the :term:`DISTRO_FEATURES` and
683:term:`MACHINE_FEATURES` variables are not yet available to ``layer.conf``, and
684declaring conditional assignments based on these variables is not possible. The
685following technique shows a way to bypass this limitation by using the
686:term:`USER_CLASSES` variable and a conditional ``require`` command.
687
688In the following steps, let's assume our layer is named ``meta-mylayer`` and
689that this layer defines a custom :ref:`distro feature <ref-features-distro>`
690named ``mylayer-kernel``. We will set the :term:`PREFERRED_PROVIDER` variable
691for the kernel only if our feature ``mylayer-kernel`` is part of the
692:term:`DISTRO_FEATURES`:
693
694#. Create an include file in the directory
695 ``meta-mylayer/conf/distro/include/``, for example a file named
696 ``mylayer-kernel-provider.inc`` that sets the kernel provider to
697 ``linux-custom``::
698
699 PREFERRED_PROVIDER_virtual/kernel = "linux-custom"
700
701#. Provide a path to this include file in your ``layer.conf``::
702
703 META_MYLAYER_KERNEL_PROVIDER_PATH = "${LAYERDIR}/conf/distro/include/mylayer-kernel-provider.inc"
704
705#. Create a new class in ``meta-mylayer/classes-global/``, for example a class
706 ``meta-mylayer-cfg.bbclass``. Make it conditionally require the file
707 ``mylayer-kernel-provider.inc`` defined above, using the variable
708 ``META_MYLAYER_KERNEL_PROVIDER_PATH`` defined in ``layer.conf``::
709
710 require ${@bb.utils.contains('DISTRO_FEATURES', 'mylayer-kernel', '${META_MYLAYER_KERNEL_PROVIDER_PATH}', '', d)}
711
712 For details on the ``bb.utils.contains`` function, see its definition in
713 :bitbake_git:`lib/bb/utils.py </tree/lib/bb/utils.py>`.
714
715 .. note::
716
717 The ``require`` command is designed to not fail if the function
718 ``bb.utils.contains`` returns an empty string.
719
720#. Back to your ``layer.conf`` file, add the class ``meta-mylayer-cfg`` class to
721 the :term:`USER_CLASSES` variable::
722
723 USER_CLASSES:append = " meta-mylayer-cfg"
724
725 This will add the class ``meta-mylayer-cfg`` to the list of classes to
726 globally inherit. Since the ``require`` command is conditional in
727 ``meta-mylayer-cfg.bbclass``, even though inherited the class will have no
728 effect unless the feature ``mylayer-kernel`` is enabled through
729 :term:`DISTRO_FEATURES`.
730
731This technique can also be used for :ref:`Machine features
732<ref-features-machine>` by following the same steps. Though not mandatory, it is
733recommended to put include files for :term:`DISTRO_FEATURES` in your layer's
734``conf/distro/include`` and the ones for :term:`MACHINE_FEATURES` in your
735layer's ``conf/machine/include``.
736
647Managing Layers 737Managing Layers
648=============== 738===============
649 739