From patchwork Tue Nov 12 11:32:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonin Godard X-Patchwork-Id: 52355 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63800D32D96 for ; Tue, 12 Nov 2024 11:33:07 +0000 (UTC) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by mx.groups.io with SMTP id smtpd.web11.85005.1731411181250734857 for ; Tue, 12 Nov 2024 03:33:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=XCYFaWBi; spf=pass (domain: bootlin.com, ip: 217.70.183.198, mailfrom: antonin.godard@bootlin.com) Received: by mail.gandi.net (Postfix) with ESMTPSA id A16EEC0005; Tue, 12 Nov 2024 11:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731411179; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LNWvbcCGaHZ4HWAc1IWkeHgN2L+2SG1S/oHBgVXUnMU=; b=XCYFaWBidzwGDsV7td+XG+s/ooHh03uPq3mq340JifZXI+g3EjdyaE0pMWPZbX56kd9j4v hAYWEySt+yJdqEFVBXGLWxxbMqOFPbC5EI8qYaCS4dR5hnO0SrKZBdUjW2Pdxq8AOkXbqG o9EzL+pqMthEge2dW4rj7JXlXRkoOFSBSMfJFBOyhsOswdoR76+m6VyY0+3hUJXUIsf6hs 6tAEYZu9VFFBZuu70Ril7RXQ/5A4Kc75a1kAFIXMAYNzka7H+ktSS72lWeNxQFyn+za8LN Fjs3NKS7zwXGPHxYOUq035KFSrowA0GotihUFeXgFZhxlT4Z8T1guAuvjIF1fQ== From: Antonin Godard Date: Tue, 12 Nov 2024 12:32:53 +0100 Subject: [PATCH v2 1/2] conf.py: add a bitbake_git extlink MIME-Version: 1.0 Message-Id: <20241112-layer-confs-v2-1-22a09f1a0a8e@bootlin.com> References: <20241112-layer-confs-v2-0-22a09f1a0a8e@bootlin.com> In-Reply-To: <20241112-layer-confs-v2-0-22a09f1a0a8e@bootlin.com> To: docs@lists.yoctoproject.org Cc: Thomas Petazzoni , Quentin Schulz , Antonin Godard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=953; i=antonin.godard@bootlin.com; h=from:subject:message-id; bh=6ZNvm3WUu2JjNgLs8af7rSs7BtVbgsjHBX7632HItSc=; b=owEBbQKS/ZANAwAIAdGAQUApo6g2AcsmYgBnMzzq+nd9HcEl8kI+1P+V2jAI20IOxuoF8QbqG OiITst9y1+JAjMEAAEIAB0WIQSGSHJRiN1AG7mg0//RgEFAKaOoNgUCZzM86gAKCRDRgEFAKaOo NgcqD/9zTgWnpCLlx+utAcHaQQ8aOfdtgir5xlxZVqBaJUA0/4KptxmF2F3Lyip9zDRdRBej/ep XpM/ZTV9Glnw4weBnc7acyTnaccXLN91yXEy4Bz9Rg9iTwbZ0rBjj/+bJH1uzJ+XnpK8ssIHFuK DbdttbVFL0XC8A9KJQfjLklKHZ5enXa9xHBYYlmeBXE+uWS5qTowljOtbrS3YSk9SiZp/RHtP9f L2205WGWI+KK9kSxJgY342NOzspKInCxu8HoJ2Qz8s3qtNB4bN//0PW6PGcGihkM9/PeemCYkdV t+hlKEqCQ16hxZ8ehXL7j7qj145RHhCM5j0o4bYf8dU4pmWJLS1N9j0mB+tWepCZNXa9VGgkwMr oWdeSxKrcIuRd7djFlQYEeTef8da3Pe8vfMG9ptXJnh/ZMERS8svEuU26E0XD5VbZxsT4H3E3co QfcfGyAd7XDguPVIPYsIkaL/iN7aUywd7MNg1JTf9RJ847C39T22TIP5O5Jwyyujquj9d1EU6cg WR2dDwNGCK3rnKDzKOLLAl9Hjy8chqHKOQ2+SlEZzlFStQyfwpJPb2YhLAo0rDwmX/EV6ZNMNU9 jDTK3admsOZ8H5HaNY37cYD9SzEUids+XeTU3SraGGttfgDaPoSErYjjAU4+21qOdkQoWEJfTAu Pk9rs7sT/rDjXvw== X-Developer-Key: i=antonin.godard@bootlin.com; a=openpgp; fpr=8648725188DD401BB9A0D3FFD180414029A3A836 X-GND-Sasl: antonin.godard@bootlin.com List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 12 Nov 2024 11:33:07 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/docs/message/5714 To make references to the bitbake repo, add an extlink for it and use it in the docs with ":bitbake_git:`lib/bb/utils.py `". Reviewed-by: Quentin Schulz Signed-off-by: Antonin Godard --- documentation/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/documentation/conf.py b/documentation/conf.py index c7dd4e03fc0e99176a0fa2f74fda58efaf0af9b2..b0e7c91eb5d8e4e855c0ca46351586cdf237fcb3 100644 --- a/documentation/conf.py +++ b/documentation/conf.py @@ -90,6 +90,7 @@ rst_prolog = """ # external links and substitutions extlinks = { + 'bitbake_git': ('https://git.openembedded.org/bitbake%s', None), 'cve_mitre': ('https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-%s', 'CVE-%s'), 'cve_nist': ('https://nvd.nist.gov/vuln/detail/CVE-%s', 'CVE-%s'), 'yocto_home': ('https://www.yoctoproject.org%s', None), From patchwork Tue Nov 12 11:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonin Godard X-Patchwork-Id: 52356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64B3BD32D9C for ; Tue, 12 Nov 2024 11:33:07 +0000 (UTC) Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by mx.groups.io with SMTP id smtpd.web11.85006.1731411181351990945 for ; Tue, 12 Nov 2024 03:33:01 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=VAl+JQ+e; spf=pass (domain: bootlin.com, ip: 217.70.183.198, mailfrom: antonin.godard@bootlin.com) Received: by mail.gandi.net (Postfix) with ESMTPSA id E4391C0006; Tue, 12 Nov 2024 11:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1731411180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LxeIxqwEhkN7cBYjLxo/Hxm4JZ3/7uTMyNxIgkuySVE=; b=VAl+JQ+eCEN/r0JWzkem7Eo+wCPPniE+mSRHJwFKrE3A/5aLi9zsvSokFFqQGcYtw+6PUt FxFHewXaE1LMYySV2DfUttrAvyuirJH6d1cQmZicBo86sMO3jHBiAtc6BG+9QFsR3O/Uo7 kBpdbSBIRMtqpMd4OJ7nPh8DDuqNDYtj6v4GcUEm2/T0xX7vn3Xb59w7O5VYnfRKxeMvWD 3eY3ealaYP59KG138sdt+pgTUmtcvZjwl1ZzVN01sJhQXYO7X3ikgarap146dMA9lmdXmr BlPrP9Q9NyrxgT4232AQShZsBm48yjzoSyQKY3ucx4vIq55aEBjEs+AoZBxZyQ== From: Antonin Godard Date: Tue, 12 Nov 2024 12:32:54 +0100 Subject: [PATCH v2 2/2] dev-manual: document how to provide confs from layer.conf MIME-Version: 1.0 Message-Id: <20241112-layer-confs-v2-2-22a09f1a0a8e@bootlin.com> References: <20241112-layer-confs-v2-0-22a09f1a0a8e@bootlin.com> In-Reply-To: <20241112-layer-confs-v2-0-22a09f1a0a8e@bootlin.com> To: docs@lists.yoctoproject.org Cc: Thomas Petazzoni , Quentin Schulz , Antonin Godard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=5568; i=antonin.godard@bootlin.com; h=from:subject:message-id; bh=FY0n7gVHoLWZ/sbdFwMPwmhjER/hW9SdF9RDhn6yLOo=; b=owEBbQKS/ZANAwAIAdGAQUApo6g2AcsmYgBnMzzqfnIBVzUNh8gCW7/lmU+bV9zXojTi93f5D dst142nr62JAjMEAAEIAB0WIQSGSHJRiN1AG7mg0//RgEFAKaOoNgUCZzM86gAKCRDRgEFAKaOo Nh+BD/9hW8JozaX46E3nj5AvvTZgJ+Hle7ThZhcKnwJ2wK/U5/wmrx3FW2p/sJHz4Qjwz9d8D0k 8dpWtTSnI4Sb4vzjPBF2HbhDYpVFe8E/qtDY5QlSAhUIMpyHsgLSXVWIS95ILH3pbNyHyzRqTkq UYiDnrmufx6RAqC/iYpXJ8daxMzQGS6djNxAodX+OYScNH6LovLxa5Wz2DlgtuOwPpqYaSLV7e9 qvm+lN2cVEVbr3KJLiMWmz9A4fatIXFRF7j7+p6XETwEg3iqNCwOveNmwMBiD5VAnAz6eGzJ7f7 eRC1Yhy9Q8RqMHSx/kQMmR3bVNi7Yb39Ghcpj/k2IdRmxa1iTUy52SAQjayzLmjdyP6tJomAykQ dPGTx6iKtyY37aToVH6Ix62kbeabyYdQHuOvhl+/05gFHkCFN22t47OCv2/SsOUsNjCR4F8CluJ ocDptklsozzRkDG5vwvzdMNT/0LyoAHUc3JVGPcHh5WRUuHoccIaTdMPjOTvwNoMYeB/eUoRiDD 3ExbzO3RaqiCS2gbS8kgrqSp2jqSTmIN5aWISKHp6TIgSIipFyr+zd6xlCS6pcennZkiBPal+Ez /Ed7qa2OZewUvCPb7MSP5oAnAGUgDYbpw6hrSI4BcW9hngFhLwoTSW1snxmbf6eT5ZD87gnQGsh 68MPWdajlSX8jTg== X-Developer-Key: i=antonin.godard@bootlin.com; a=openpgp; fpr=8648725188DD401BB9A0D3FFD180414029A3A836 X-GND-Sasl: antonin.godard@bootlin.com List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Tue, 12 Nov 2024 11:33:07 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/docs/message/5716 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]. Signed-off-by: Antonin Godard --- documentation/dev-manual/layers.rst | 86 +++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/documentation/dev-manual/layers.rst b/documentation/dev-manual/layers.rst index 91889bd0ae391c7b6e62068778ae5c180c840762..e449fd43ad86c9a027e317e49b6e2f2f340a08d4 100644 --- a/documentation/dev-manual/layers.rst +++ b/documentation/dev-manual/layers.rst @@ -644,6 +644,92 @@ variable and append the layer's root name:: order of ``.conf`` or ``.bbclass`` files. Future versions of BitBake might address this. +Providing Global-level Configurations With Your Layer +----------------------------------------------------- + +When creating a layer, you may need to define configurations that should take +effect globally in your build environment when the layer is part of the build. +The ``layer.conf`` file is a :term:`configuration file` that affects the build +system globally, so it is a candidate for this use-case. + +.. attention:: + + Providing unconditional global level configuration from the ``layer.conf`` + file is *not* a good practice, and should be avoided. For this reason, the + section :ref:`Conditionally Provide Global-level Configurations With Your + Layer` below shows how the ``layer.conf`` file can be used to provide + configurations only if a certain condition is met. + +For example, if your layer provides a Linux kernel recipe named +``linux-custom``, you may want to define the :term:`PREFERRED_PROVIDER` for the +``linux-custom`` recipe:: + + PREFERRED_PROVIDER_virtual/kernel = "linux-custom" + +This can be defined in the ``layer.conf`` file. If your layer is at the last +position in the :term:`BBLAYERS` list, it will take precedence over previous +``PREFERRED_PROVIDER_virtual/kernel`` assignments. + +Conditionally Provide Global-level Configurations With Your Layer +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +In some cases, your layer may provide global configurations only if some +features it provides are enabled. Since the ``layer.conf`` file is parsed at an +earlier stage in the parsing process, the :term:`DISTRO_FEATURES` and +:term:`MACHINE_FEATURES` variables are not yet available to ``layer.conf``, and +declaring conditional assignments based on these variables is not possible. The +following technique shows a way to bypass this limitation by using the +:term:`USER_CLASSES` variable and a conditional ``include`` command. + +In the following steps, let's assume our layer is named ``meta-mylayer`` and +that this layer defines a custom :ref:`distro feature ` +named ``mylayer-kernel``. We will set the :term:`PREFERRED_PROVIDER` variable +for the kernel only if our feature ``mylayer-kernel`` is part of the +:term:`DISTRO_FEATURES`: + +#. Create an include file in the directory + ``meta-mylayer/conf/distro/include/``, for example a file named + ``mylayer-kernel-provider.inc`` that sets the kernel provider to + ``linux-custom``:: + + PREFERRED_PROVIDER_virtual/kernel = "linux-custom" + +#. Provide a path to this include file in your ``layer.conf``:: + + META_MYLAYER_KERNEL_PROVIDER_PATH = "${LAYERDIR}/conf/distro/include/mylayer-kernel-provider.inc" + +#. Create a new class in ``meta-mylayer/classes-global/``, for example a class + ``meta-mylayer-cfg.bbclass``. Make it conditionally include the file + ``mylayer-kernel-provider.inc`` defined above, using the variable + ``META_MYLAYER_KERNEL_PROVIDER_PATH`` defined in ``layer.conf``:: + + require ${@bb.utils.contains('DISTRO_FEATURES', 'mylayer-kernel', '${META_MYLAYER_KERNEL_PROVIDER_PATH}', '', d)} + + For details on the ``bb.utils.contains`` function, see its definition in + :bitbake_git:`lib/bb/utils.py `. + + .. note:: + + The ``require`` command is designed to not fail if the function + ``bb.utils.contains`` returns an empty string. + +#. Back to your ``layer.conf`` file, add the class ``meta-mylayer-cfg`` class to + the :term:`USER_CLASSES` variable:: + + USER_CLASSES:append = " meta-mylayer-cfg" + + This will add the class ``meta-mylayer-cfg`` to the list of classes to + globally inherit. Since the ``include`` command is conditional in + ``meta-mylayer-cfg.bbclass``, even though inherited the class will have no + effect until the feature ``mylayer-kernel`` is enabled through + :term:`DISTRO_FEATURES`. + +This technique can also be used for :ref:`Machine features +` by following the same steps. Though not mandatory, it is +recommended to put include files for :term:`DISTRO_FEATURES` in your layer's +``conf/distro/include`` and the ones for :term:`MACHINE_FEATURES` in your +layer's ``conf/machine/include``. + Managing Layers ===============