diff mbox series

[11/17] layerindexlib/cooker: Switch to Use layerdata data struture

Message ID 20261130152847.3472849-11-richard.purdie@linuxfoundation.org
State New
Headers show
Series [01/17] uihelper: Fix exception when TaskStarted event handler breaks | expand

Commit Message

Richard Purdie Nov. 30, 2026, 3:28 p.m. UTC
Update to use the new layerdata structure after the layer changes.

Update the test layers to match the new format.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/layerindexlib/cooker.py                   | 31 +++++++------------
 lib/layerindexlib/tests/cooker.py             | 15 ++++++++-
 .../tests/testdata/layer1/conf/layer.conf     | 13 ++------
 .../tests/testdata/layer2/conf/layer.conf     | 23 +++++---------
 .../tests/testdata/layer3/conf/layer.conf     | 18 +++--------
 .../tests/testdata/layer4/conf/layer.conf     | 23 ++++----------
 6 files changed, 47 insertions(+), 76 deletions(-)
diff mbox series

Patch

diff --git a/lib/layerindexlib/cooker.py b/lib/layerindexlib/cooker.py
index 82d77335f9a..0af92eec51b 100644
--- a/lib/layerindexlib/cooker.py
+++ b/lib/layerindexlib/cooker.py
@@ -93,9 +93,7 @@  class CookerPlugin(layerindexlib.plugin.IndexPlugin):
             # It's blank!  Nothing to process...
             return index
 
-        collections = d.getVar('BBFILE_COLLECTIONS')
-        layerconfs = d.varhistory.get_variable_items_files('BBFILE_COLLECTIONS')
-        bbfile_collections = {layer: os.path.dirname(os.path.dirname(path)) for layer, path in layerconfs.items()}
+        layerdata = d.getVar('layerdata', False) or {}
 
         (_, bb_branch, _, _) = self._get_bitbake_info()
 
@@ -104,13 +102,11 @@  class CookerPlugin(layerindexlib.plugin.IndexPlugin):
             index.branches[branchId] = layerindexlib.Branch(index, None)
             index.branches[branchId].define_data(branchId, branch, bb_branch)
 
-        for entry in collections.split():
-            layerpath = entry
-            if entry in bbfile_collections:
-                layerpath = bbfile_collections[entry]
+        for entry, layer in layerdata.items():
+            layerpath = layer.path
 
             layername = d.getVar('BBLAYERS_LAYERINDEX_NAME_%s' % entry) or os.path.basename(layerpath)
-            layerversion = d.getVar('LAYERVERSION_%s' % entry) or ""
+            layerversion = layer.version or ""
             layerurl = self._handle_git_remote(layerpath)
 
             layersubdir = ""
@@ -164,6 +160,7 @@  class CookerPlugin(layerindexlib.plugin.IndexPlugin):
             raise layerindexlib.plugin.LayerIndexPluginUrlError(self.type, url)
 
         d = self.layerindex.data
+        layerdata = d.getVar('layerdata', False) or {}
 
         params = self.layerindex._parse_params(up.params)
 
@@ -199,12 +196,7 @@  class CookerPlugin(layerindexlib.plugin.IndexPlugin):
                 branchName = index.layerBranches[layerBranchId].branch.name
                 collection = index.layerBranches[layerBranchId].collection
 
-                def add_dependency(layerDependencyId, index, deps, required):
-                    try:
-                        depDict = bb.utils.explode_dep_versions2(deps)
-                    except bb.utils.VersionStringException as vse:
-                        bb.fatal('Error parsing LAYERDEPENDS_%s: %s' % (collection, str(vse)))
-
+                def add_dependency(layerDependencyId, index, depDict, required):
                     for dep, oplist in list(depDict.items()):
                         # We need to search ourselves, so use the _ version...
                         depLayerBranch = index.find_collection(dep, branches=[branchName])
@@ -225,13 +217,12 @@  class CookerPlugin(layerindexlib.plugin.IndexPlugin):
 
                     return layerDependencyId
 
-                deps = d.getVar("LAYERDEPENDS_%s" % collection)
-                if deps:
-                    layerDependencyId = add_dependency(layerDependencyId, index, deps, True)
+                layer = layerdata.get(collection)
+                if layer and layer.depends:
+                    layerDependencyId = add_dependency(layerDependencyId, index, layer.depends, True)
 
-                deps = d.getVar("LAYERRECOMMENDS_%s" % collection)
-                if deps:
-                    layerDependencyId = add_dependency(layerDependencyId, index, deps, False)
+                if layer and layer.recommends:
+                    layerDependencyId = add_dependency(layerDependencyId, index, layer.recommends, False)
 
         # Need to load recipes here (requires cooker access)
         recipeId = 0
diff --git a/lib/layerindexlib/tests/cooker.py b/lib/layerindexlib/tests/cooker.py
index 5ddf89aa211..04c5483783e 100644
--- a/lib/layerindexlib/tests/cooker.py
+++ b/lib/layerindexlib/tests/cooker.py
@@ -5,6 +5,7 @@ 
 
 import os
 import bb
+import bb.cookerdata
 
 import layerindexlib
 from layerindexlib.tests.common import LayersTest
@@ -26,8 +27,20 @@  class LayerIndexCookerTest(LayersTest):
         self.d.setVar('BBPATH', new_bbpath)
 
         self.d = bb.parse.handle("%s/conf/bblayers.conf" % new_bbpath, self.d, True)
+        layerdata = {}
         for layer in self.d.getVar('BBLAYERS').split():
-            self.d = bb.parse.handle("%s/conf/layer.conf" % layer, self.d, True)
+            ld = bb.parse.handle("%s/conf/layer.conf" % layer, self.d.createCopy(), True)
+            layername = ld.getVar('LAYERNAME')
+            layerdata[layername] = bb.cookerdata.Layer(
+                path=layer,
+                version=ld.getVar('LAYERVERSION') or "1",
+                depends=bb.utils.explode_dep_versions2(ld.getVar('LAYERDEPENDS') or ""),
+                recommends=bb.utils.explode_dep_versions2(ld.getVar('LAYERRECOMMENDS') or ""),
+            )
+            indexname = ld.getVar('BBLAYERS_LAYERINDEX_NAME_%s' % layername)
+            if indexname:
+                self.d.setVar('BBLAYERS_LAYERINDEX_NAME_%s' % layername, indexname)
+        self.d.setVar('layerdata', layerdata)
 
         self.layerindex = layerindexlib.LayerIndex(self.d)
         self.layerindex.load_layerindex('cooker://', load=['layerDependencies'])
diff --git a/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf b/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf
index 966d5319596..dbabd91e6c5 100644
--- a/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf
+++ b/lib/layerindexlib/tests/testdata/layer1/conf/layer.conf
@@ -1,17 +1,10 @@ 
-# We have a conf and classes directory, add to BBPATH
-BBPATH .= ":${LAYERDIR}"
-# We have recipes-* directories, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb"
-
-BBFILE_COLLECTIONS += "core"
-BBFILE_PATTERN_core = "^${LAYERDIR}/"
-BBFILE_PRIORITY_core = "5"
+LAYERNAME = "core"
 
 LAYERSERIES_CORENAMES = "sumo"
 
 # This should only be incremented on significant changes that will
 # cause compatibility issues with other layers
-LAYERVERSION_core = "11"
-LAYERSERIES_COMPAT_core = "sumo"
+LAYERVERSION = "11"
+LAYERSERIES_COMPAT = "sumo"
 
 BBLAYERS_LAYERINDEX_NAME_core = "openembedded-core"
diff --git a/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf b/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf
index 7569d1c2172..cea7d19d950 100644
--- a/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf
+++ b/lib/layerindexlib/tests/testdata/layer2/conf/layer.conf
@@ -1,20 +1,13 @@ 
-# We have a conf and classes directory, add to BBPATH
-BBPATH .= ":${LAYERDIR}"
-
-# We have a packages directory, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb \
-            ${LAYERDIR}/recipes-*/*/*.bbappend"
-
-BBFILE_COLLECTIONS += "networking-layer"
-BBFILE_PATTERN_networking-layer := "^${LAYERDIR}/"
-BBFILE_PRIORITY_networking-layer = "5"
+LAYERNAME = "networking-layer"
 
 # This should only be incremented on significant changes that will
 # cause compatibility issues with other layers
-LAYERVERSION_networking-layer = "1"
+LAYERVERSION = "1"
+
+LAYERDEPENDS = "core"
+LAYERDEPENDS += "openembedded-layer"
+LAYERDEPENDS += "meta-python"
 
-LAYERDEPENDS_networking-layer = "core"
-LAYERDEPENDS_networking-layer += "openembedded-layer"
-LAYERDEPENDS_networking-layer += "meta-python"
+LAYERSERIES_COMPAT = "sumo"
 
-LAYERSERIES_COMPAT_networking-layer = "sumo"
+BBLAYERS_LAYERINDEX_NAME_networking-layer = "networking-layer"
diff --git a/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf b/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf
index 7089071faf6..af089a7ca11 100644
--- a/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf
+++ b/lib/layerindexlib/tests/testdata/layer3/conf/layer.conf
@@ -1,19 +1,11 @@ 
-# We might have a conf and classes directory, append to BBPATH
-BBPATH .= ":${LAYERDIR}"
-
-# We have recipes directories, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend"
-
-BBFILE_COLLECTIONS += "meta-python"
-BBFILE_PATTERN_meta-python := "^${LAYERDIR}/"
-BBFILE_PRIORITY_meta-python = "7"
+LAYERNAME = "meta-python"
 
 # This should only be incremented on significant changes that will
 # cause compatibility issues with other layers
-LAYERVERSION_meta-python = "1"
+LAYERVERSION = "1"
 
-LAYERDEPENDS_meta-python = "core openembedded-layer"
+LAYERDEPENDS = "core openembedded-layer"
 
-LAYERSERIES_COMPAT_meta-python = "sumo"
+LAYERSERIES_COMPAT = "sumo"
 
-LICENSE_PATH += "${LAYERDIR}/licenses"
+BBLAYERS_LAYERINDEX_NAME_meta-python = "meta-python"
diff --git a/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf b/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
index 6649ee02081..974ebac002f 100644
--- a/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
+++ b/lib/layerindexlib/tests/testdata/layer4/conf/layer.conf
@@ -1,22 +1,11 @@ 
-# We have a conf and classes directory, append to BBPATH
-BBPATH .= ":${LAYERDIR}"
-
-# We have a recipes directory, add to BBFILES
-BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"
-
-BBFILE_COLLECTIONS += "openembedded-layer"
-BBFILE_PATTERN_openembedded-layer := "^${LAYERDIR}/"
-
-# Define the priority for recipes (.bb files) from this layer,
-# choosing carefully how this layer interacts with all of the
-# other layers.
-
-BBFILE_PRIORITY_openembedded-layer = "6"
+LAYERNAME = "openembedded-layer"
 
 # This should only be incremented on significant changes that will
 # cause compatibility issues with other layers
-LAYERVERSION_openembedded-layer = "1"
+LAYERVERSION = "1"
+
+LAYERDEPENDS = "core"
 
-LAYERDEPENDS_openembedded-layer = "core"
+LAYERSERIES_COMPAT = "sumo"
 
-LAYERSERIES_COMPAT_openembedded-layer = "sumo"
+BBLAYERS_LAYERINDEX_NAME_openembedded-layer = "openembedded-layer"