diff mbox series

[06/16] core: Migrate to new layer format

Message ID 20261130152704.3471590-6-richard.purdie@linuxfoundation.org
State New
Headers show
Series [01/16] bitbake/base: Implement RECIPE_HOSTTOOLS | expand

Commit Message

Richard Purdie Nov. 30, 2026, 3:26 p.m. UTC
After bitbake "cooker: Change layer.conf handling to new approach", we need
to update our layer.conf files to the new format. To quote that change:

This is a fairly radical set of changes to the way layer.conf is handled and how it
works with layers. I tried to split this into more specific changes but bascially
I couldn't make that work in any reasonable way. It is not intended to be backward
compatible even if some bits of syntax are similar.

There were several historical issues:
  - layers can contain multiple 'collections'
  - priorities could depend on the file, collection and layer which
    interacted in ways people couldn't easily picture
  - layer.conf became a dumping ground for random variables
  - the current internal layer/collection 'names' are suboptimal

This patch therefore:
  - Drops the concept of 'collections'
  - Drops layer priorities
  - Drops file priorities
  - Requires LAYERNAME to be set
  - Auto constructs BBPATH based on layer dependencies
  - AUto constructs BBFILES based on layer dependencies
  - Auto constructs BBFILES_DYNAMIC based on a "dynamic-recipes" directory
  - Filter layer.conf variables
  - Adds support for layer specific variables in layervars.conf
  - Sets LAYERDIR_<layername> variables (and includes bitbake)
  - No longer supports layers within layers
    (multiple layers in a repo is still fine)

More details notes follow (with examples from OE):

"""
layer.conf has radically changed and is now parsed in isolation on top
of bblayers.conf. This means any changes made to variables in that file
don't pass to other files or the global state by default. ":append"
would only add to the value from bblayers. Overrides will not work as
they're not defined at this point.

layer.conf is now expected to set a LAYERNAME.

The layer names are going to change. Some examples:

"core" -> "oe-core"
"openembedded-layer" -> "meta-oe"
"networking-layer" -> meta-oe-networking"
"virtualization-layer" -> "meta-virtualization"

The idea is to have a consistent base prefix for combined repos so that
the repo can be identified from the name (e.g. in a list of
dependencies), and drop unneeded "-layer" suffix, make "core" clearer
from other "core" things. As such, we are expecting layers to move to
new names.

Note that any fragment references also then need to use the new layer
names.

The LAYERDEPENDS and LAYERRECOMMENDS variables remain as before.

LAYER* variables which traditionally had a collection name suffix, e.g.
"_core" now don't need to be suffixed with the layername, but can be.

The concepts of layer priorities, bbfile prorities and collections are
all removed. This means the variables BFILE_COLLECTIONS,
BBFILE_PRIORITY and BBFILE_PATTERN no longer do anything but trigger
warnings.

BBPATH and BBFILES no longer should be set by layer.conf. They are both
now set based upon the information from LAYERDEPENDS. If you depend on
a layer, you have the ability to change it. BBFILES will now just
include .bb and .bbappend files in any recipes* directories.

BBFILES_DYNAMIC is also no longer needed. Instead, bitbake will look
for a "dynamic-recipes" directory and apply any subdirectories
directories there based on layername, adding any files contained to
BBFILES internally dynamically.

Bitbake will set LAYERDIR_<layername> in the global namespace. In
addition, it will also set BITBAKEDIR to point at itself (OE-Core
needs that, hopefully nothing else does and it is really for internal
use to build PATH correctly).

BBLAYERS no longer controls much other that the layers to include.
There are two variables which are exceptions, LAYERSERIES_CORENAMES and
LAYER_PASSTHROUGH_VARS_PREFIXES. These two are only set by the first
layer included that sets them. For the layerseries, this is by
historical precedent, I did this for the latter for now to potentially
cover some weird use cases people may have. I am tempted to remove that
special casing and only allow one layer to set those variables.

There are some variables which can pass from layer.conf into the global
scope. There is a list of variable prefixes which are accepted in
LAYER_PASSTHROUGH_VARS_PREFIXES. These should be lists which work well
with +=.

This list is deliberately restrictive, I've worked with the sample
layers to remove as many of them that I can.

Layers do need some way of setting variables for their own recipes.
This is done with a new layervars.conf, which recipes in a given layer
will always have included (in .bb files but not .bbappend). Note that
layervars.conf is parsed on top of the base configuration, so much later
in parsing than layer.conf.

One pattern we've noticed is layers wanting to warn that the
configuration they provide is not enabled and to provide that config,
usually as a DISTRO_FEATURE. I've changed meta-virtiualization to use
fragments to enable the different configs (which can enable
DISTRO_FEATURES in turn).

That means we can add a LAYER_FRAGEMENTS_RECOMMEND_ANY variable which
is used to warn when fragments aren't selected  and the user can
override with LAYER_FRAGEMENTS_OPTED_OUT to hide the warnings if they
really don't want to select any.

Some things are better imeplemented with conf files and a "include_all"
directive in core. I've changed security flags and reproducible builds
to do that, we should be doing this anyway.

Some layers have been setting INHERIT in layer.conf. This is no longer
supported and should be done by configuration files/fragments instead. It
can be done in layervars.conf but will only apply to recipes in that layer
(and not bbapends).

There is a BB_LAYER_FILTER_FUNC variable which takes the name of function
which can make final changes to the datastore at the end of "layer" parsing
before the main parse. If your layer is intended to be shared at all and used
by others outside your own context, you *should not* be using this. It can
only be set once, by the first layer.conf found that sets it.

From an internals perspective, there is now a Layers object stored in
the  datastore as "layerdata". This is useful for some areas of the code
to be able to work with layers, such as the fragment code. It is considered
semi-internal API at this point. It does mean anyone iterating datastore
values needs to be careful about non-text return values but we already
have those.
"""

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 meta-selftest/conf/layer.conf                 | 14 ++-----
 meta-skeleton/conf/layer.conf                 | 21 ++--------
 meta/classes-recipe/testexport.bbclass        |  6 +--
 meta/classes-recipe/toolchain-scripts.bbclass |  2 +-
 meta/conf/bitbake.conf                        | 11 +++---
 meta/conf/layer.conf                          | 39 ++++++++++---------
 meta/conf/templates/default/local.conf.sample |  2 +-
 meta/lib/oeqa/selftest/cases/bblayers.py      |  8 ++--
 scripts/lib/devtool/ide_sdk.py                |  4 +-
 9 files changed, 44 insertions(+), 63 deletions(-)
diff mbox series

Patch

diff --git a/meta-selftest/conf/layer.conf b/meta-selftest/conf/layer.conf
index 40b6b6910ad..2aa8b9b3dca 100644
--- a/meta-selftest/conf/layer.conf
+++ b/meta-selftest/conf/layer.conf
@@ -1,16 +1,8 @@ 
-# We have a conf and classes directory, add to BBPATH
-BBPATH .= ":${LAYERDIR}"
 
-# We have recipes-* directories, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
-	${LAYERDIR}/recipes-*/*/*.bbappend"
-
-BBFILE_COLLECTIONS += "selftest"
-BBFILE_PATTERN_selftest = "^${LAYERDIR}/"
-BBFILE_PRIORITY_selftest = "5"
+LAYERNAME = "selftest"
 
 addpylib ${LAYERDIR}/lib oeqa
 
-LAYERSERIES_COMPAT_selftest = "blacksail"
+LAYERSERIES_COMPAT_selftest = "garburn"
 
-OE_FRAGMENTS_BUILTIN:append = " selftest-fragment:SELFTEST_BUILTIN_FRAGMENT_VARIABLE"
+OE_FRAGMENTS_BUILTIN += " selftest-fragment:SELFTEST_BUILTIN_FRAGMENT_VARIABLE"
diff --git a/meta-skeleton/conf/layer.conf b/meta-skeleton/conf/layer.conf
index 94909d51205..fdb2f01c27c 100644
--- a/meta-skeleton/conf/layer.conf
+++ b/meta-skeleton/conf/layer.conf
@@ -1,17 +1,4 @@ 
-# We have a conf and classes directory, add to BBPATH
-BBPATH .= ":${LAYERDIR}"
-
-# We have recipes-* directories, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
-
-BBFILE_COLLECTIONS += "skeleton"
-BBFILE_PATTERN_skeleton = "^${LAYERDIR}/"
-BBFILE_PRIORITY_skeleton = "1"
-
-# This should only be incremented on significant changes that will
-# cause compatibility issues with other layers
-LAYERVERSION_skeleton = "1"
-
-LAYERDEPENDS_skeleton = "core"
-
-LAYERSERIES_COMPAT_skeleton = "blacksail"
+LAYERNAME = "skeleton"
+LAYERVERSION = "1"
+LAYERDEPENDS = "oe-core"
+LAYERSERIES_COMPAT = "garburn"
diff --git a/meta/classes-recipe/testexport.bbclass b/meta/classes-recipe/testexport.bbclass
index b2b4a358c43..655f4267244 100644
--- a/meta/classes-recipe/testexport.bbclass
+++ b/meta/classes-recipe/testexport.bbclass
@@ -85,7 +85,7 @@  def copy_needed_files(d, tc):
     from oeqa.core.utils.test import getSuiteCasesFiles
 
     export_path = d.getVar('TEST_EXPORT_DIR')
-    bitbake_path = d.getVar('BITBAKEPATH')
+    bitbake_path = d.getVar('BITBAKEDIR')
     corebase_path = d.getVar('COREBASE')
     bblayers = d.getVar('BBLAYERS').split()
 
@@ -93,10 +93,10 @@  def copy_needed_files(d, tc):
     oe.path.remove(export_path)
     bb.utils.mkdirhier(os.path.join(export_path, 'lib', 'oeqa'))
 
-    # The source of files to copy are relative to 'BITBAKEPATH' and 'COREBASE'
+    # The source of files to copy are relative to 'BITBAKEDIR' and 'COREBASE'
     # directory. The destination is relative to 'TEST_EXPORT_DIR'.
     # bitbake and core files/dirs first.
-    bitbake_files_to_copy = [os.path.join('..', 'lib')]
+    bitbake_files_to_copy = ['lib']
     for f in bitbake_files_to_copy:
         src = os.path.join(bitbake_path, f)
         dst = os.path.join(export_path, 'bitbake', f.split('/', 1)[-1])
diff --git a/meta/classes-recipe/toolchain-scripts.bbclass b/meta/classes-recipe/toolchain-scripts.bbclass
index 7b10b76609e..7bb77a5a7c4 100644
--- a/meta/classes-recipe/toolchain-scripts.bbclass
+++ b/meta/classes-recipe/toolchain-scripts.bbclass
@@ -89,7 +89,7 @@  toolchain_create_sdk_env_script () {
 # Caller must ensure CONFIG_SITE is setup
 toolchain_create_tree_env_script () {
 	script=${B}/environment-setup-${REAL_MULTIMACH_TARGET_SYS}
-	bitbakedir=$(readlink -f ${BITBAKEPATH}/..)
+	bitbakedir=$(readlink -f ${BITBAKEDIR})
 	rm -f $script
 	touch $script
 	echo 'standalone_sysroot_target="${STAGING_DIR}/${MACHINE}"' >> $script
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 8ff14158d9a..4a28b619c12 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -1,3 +1,5 @@ 
+COREBASE := "${@os.path.realpath('${LAYERDIR_oe-core}/../')}"
+
 ##################################################################
 # Standard target filesystem paths.
 ##################################################################
@@ -515,8 +517,7 @@  EXTRA_IMAGEDEPENDS = ""
 # Toolchain info.
 ##################################################################
 
-PATH:prepend = "${COREBASE}/scripts:${STAGING_BINDIR_TOOLCHAIN}:${STAGING_BINDIR_CROSS}:${STAGING_DIR_NATIVE}${sbindir_native}:${STAGING_BINDIR_NATIVE}:${STAGING_DIR_NATIVE}${base_sbindir_native}:${STAGING_DIR_NATIVE}${base_bindir_native}:"
-export PATH
+export PATH = "${COREBASE}/scripts:${STAGING_BINDIR_TOOLCHAIN}:${STAGING_BINDIR_CROSS}:${STAGING_DIR_NATIVE}${sbindir_native}:${STAGING_BINDIR_NATIVE}:${STAGING_DIR_NATIVE}${base_sbindir_native}:${STAGING_DIR_NATIVE}${base_bindir_native}:${BITBAKEDIR}/bin:${RECIPE_HOSTTOOLS_DIR}:${HOSTTOOLS_DIR}"
 
 ##################################################################
 # Build utility info.
@@ -803,7 +804,7 @@  include conf/local.conf
 
 OE_FRAGMENTS_PREFIX ?= "conf/fragments"
 OE_FRAGMENTS_METADATA_VARS ?= "BB_CONF_FRAGMENT_SUMMARY BB_CONF_FRAGMENT_DESCRIPTION"
-OE_FRAGMENTS_BUILTIN ?= "machine:MACHINE distro:DISTRO"
+OE_FRAGMENTS_BUILTIN =+ "machine:MACHINE distro:DISTRO"
 addfragments ${OE_FRAGMENTS_PREFIX} OE_FRAGMENTS OE_FRAGMENTS_METADATA_VARS OE_FRAGMENTS_BUILTIN
 
 require ${@"conf/multiconfig/${BB_CURRENT_MC}.conf" if "${BB_CURRENT_MC}" != "" else ""}
@@ -902,8 +903,8 @@  DISTRO_FEATURES_NATIVESDK:mingw32 = "x11 ipv6"
 
 # Normally target distro features will not be applied to native builds:
 # Native distro features on this list will use the target feature value
-DISTRO_FEATURES_FILTER_NATIVE ?= "api-documentation debuginfod opengl wayland"
-DISTRO_FEATURES_FILTER_NATIVESDK ?= "api-documentation debuginfod opengl wayland"
+DISTRO_FEATURES_FILTER_NATIVE += "api-documentation debuginfod opengl wayland"
+DISTRO_FEATURES_FILTER_NATIVESDK += "api-documentation debuginfod opengl wayland"
 
 MACHINE_FEATURES_DEFAULTS = "rtc qemu-usermode"
 
diff --git a/meta/conf/layer.conf b/meta/conf/layer.conf
index 04bceadddee..53f77d165c2 100644
--- a/meta/conf/layer.conf
+++ b/meta/conf/layer.conf
@@ -1,23 +1,29 @@ 
-# We have a conf and classes directory, add to BBPATH
-BBPATH .= ":${LAYERDIR}"
-# We have recipes-* directories, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb"
+LAYERNAME = "oe-core"
 
-BBFILE_COLLECTIONS += "core"
-BBFILE_PATTERN_core = "^${LAYERDIR}/"
-BBFILE_PRIORITY_core = "5"
-
-LAYERSERIES_CORENAMES = "blacksail"
+LAYERSERIES_CORENAMES = "garburn"
 
 # This should only be incremented on significant changes that will
 # cause compatibility issues with other layers
-LAYERVERSION_core = "15"
-LAYERSERIES_COMPAT_core = "blacksail"
+LAYERVERSION = "15"
+LAYERSERIES_COMPAT = "garburn"
 
-BBLAYERS_LAYERINDEX_NAME_core = "openembedded-core"
+LAYER_PASSTHROUGH_VARS_PREFIXES = " \
+    BBMASK \
+    PREFERRED_RPROVIDER \
+    PREFERRED_PROVIDER \
+    OE_FRAGMENTS_BUILTIN \
+    NON_MULTILIB_RECIPES \
+    IMAGE_CLASSES \
+    SIGGEN_EXCLUDE_SAFE_RECIPE_DEPS \
+    SIGGEN_EXCLUDERECIPES_ABISAFE \
+    SSTATE_EXCLUDEDEPS_SYSROOT \
+    DUMMY_PACKAGE_ARCHS_TARGET \
+    DUMMY_PACKAGE_ARCHS_SDK \
+    DISTRO_FEATURES_FILTER_NATIVE \
+    DISTRO_FEATURES_FILTER_NATIVESDK \
+"
 
-# Set a variable to get to the top of the metadata location
-COREBASE = '${@os.path.normpath("${LAYERDIR}/../")}'
+BBLAYERS_LAYERINDEX_NAME_oe-core = "openembedded-core"
 
 # opkg-utils is for update-alternatives :(
 SIGGEN_EXCLUDERECIPES_ABISAFE += " \
@@ -135,11 +141,6 @@  SSTATE_EXCLUDEDEPS_SYSROOT += ".*->autoconf-archive-native"
 DUMMY_PACKAGE_ARCHS_SDK += "buildtools-dummy-${SDKPKGSUFFIX} sdk-provides-dummy-${SDKPKGSUFFIX}"
 DUMMY_PACKAGE_ARCHS_TARGET += "sdk-provides-dummy-target"
 
-# We need to keep bitbake tools in PATH
-# Avoid empty path entries
-BITBAKEPATH := "${@os.path.dirname(bb.utils.which(d.getVar('PATH'),'bitbake'))}"
-PATH := "${@'${BITBAKEPATH}:' if '${BITBAKEPATH}' != '' else ''}${RECIPE_HOSTTOOLS_DIR}:${HOSTTOOLS_DIR}"
-
 # Only OE-Core should set/change this
 BB_GLOBAL_PYMODULES = "os sys time"
 
diff --git a/meta/conf/templates/default/local.conf.sample b/meta/conf/templates/default/local.conf.sample
index 935699929c3..a4178edff11 100644
--- a/meta/conf/templates/default/local.conf.sample
+++ b/meta/conf/templates/default/local.conf.sample
@@ -213,7 +213,7 @@  BB_DISKMON_DIRS ??= "\
 # will then speed up the builds by not having to build things if they are present in the
 # cache. It assumes you can download something faster than you can build it which will
 # depend on your network.
-# OE_FRAGMENTS += "core/yocto/sstate-mirror-cdn"
+# OE_FRAGMENTS += "oe-core/yocto/sstate-mirror-cdn"
 
 #
 # Qemu configuration
diff --git a/meta/lib/oeqa/selftest/cases/bblayers.py b/meta/lib/oeqa/selftest/cases/bblayers.py
index 849afe36718..7ca82e0d5c0 100644
--- a/meta/lib/oeqa/selftest/cases/bblayers.py
+++ b/meta/lib/oeqa/selftest/cases/bblayers.py
@@ -21,9 +21,9 @@  class BitbakeLayers(OESelftestTestCase):
         bitbake("-c addto_recipe_sysroot python3-jsonschema-native")
 
         # Fetch variables used in multiple test cases
-        bb_vars = get_bb_vars(['COREBASE', 'BITBAKEPATH'])
+        bb_vars = get_bb_vars(['COREBASE', 'BITBAKEDIR'])
         cls.corebase = bb_vars['COREBASE']
-        cls.bitbakepath = bb_vars['BITBAKEPATH']
+        cls.bitbakedir = bb_vars['BITBAKEDIR']
         cls.jsonschema_staging_bindir = get_bb_var('STAGING_BINDIR', 'python3-jsonschema-native')
 
     def test_bitbakelayers_layerindexshowdepends(self):
@@ -145,7 +145,7 @@  class BitbakeLayers(OESelftestTestCase):
     def validate_json(self, json, jsonschema):
         python = os.path.join(self.jsonschema_staging_bindir, 'nativepython3')
         jsonvalidator = os.path.join(self.jsonschema_staging_bindir, 'jsonschema')
-        schemas_dir = os.path.join(self.bitbakepath, "..", "setup-schema")
+        schemas_dir = os.path.join(self.bitbakedir, "setup-schema")
         if not os.path.isabs(jsonschema):
             jsonschema = os.path.join(schemas_dir, jsonschema)
 
@@ -165,7 +165,7 @@  class BitbakeLayers(OESelftestTestCase):
     def test_validate_bitbake_setup_default_registry(self):
         jsonschema = "bitbake-setup.schema.json"
 
-        default_registry_path = os.path.join(self.bitbakepath, "..", "default-registry", "configurations")
+        default_registry_path = os.path.join(self.bitbakedir, "default-registry", "configurations")
 
         for root, _, files in os.walk(default_registry_path):
             for f in files:
diff --git a/scripts/lib/devtool/ide_sdk.py b/scripts/lib/devtool/ide_sdk.py
index 9faf041957e..5dc5199c24b 100755
--- a/scripts/lib/devtool/ide_sdk.py
+++ b/scripts/lib/devtool/ide_sdk.py
@@ -974,7 +974,7 @@  class RecipeModified:
         self.base_libdir = recipe_d.getVar('base_libdir')
         self.bblayers = recipe_d.getVar('BBLAYERS').split()
         self.bindir = recipe_d.getVar('bindir')
-        self.bitbakepath = recipe_d.getVar('BITBAKEPATH')
+        self.bitbakepath = recipe_d.getVar('BITBAKEDIR')
         self.bpn = recipe_d.getVar('BPN')
         self.cc = recipe_d.getVar('CC')
         self.cxx = recipe_d.getVar('CXX')
@@ -1656,7 +1656,7 @@  class RecipeModified:
         cmd_lines += ['import os',
                       'import sys',
                       'sys.path.insert(0, %r)' % os.path.realpath(
-                          os.path.join(self.bitbakepath, '..', 'lib')),
+                          os.path.join(self.bitbakepath, 'lib')),
                       'import bb.tinfoil',
                       'os.chdir(%r)' % self.topdir,
                       # A stale BBPATH from the caller's environment (e.g. a