diff mbox series

[master-next] cookerdata: merge pass-through variables set by several layers

Message ID 20261128211143.3894451-1-ricardo.salveti@oss.qualcomm.com
State New
Headers show
Series [master-next] cookerdata: merge pass-through variables set by several layers | expand

Commit Message

Ricardo Salveti Nov. 28, 2026, 9:11 p.m. UTC
Each layer.conf is parsed into its own copy of the pre-layer datastore
and its pass-through variables are then copied with setVar(), so when
several layers add to the same variable only the last layer in BBLAYERS
keeps its entries. __depends is copied the same way, so BBINCLUDED
lists only the last layer.conf and a memory resident bitbake misses
changes to the others.

Keep the pre-layer datastore unchanged, merge into a copy of it and
add the words each later layer adds; PREFERRED_PROVIDER_*,
PREFERRED_RPROVIDER_* and BBLAYERS_LAYERINDEX_NAME_* hold single
values, so the last layer still wins for those. Expand a variable only
once it is known to pass through, and skip layers that only set one of
its flags. Tested with +=, =+, :append, :remove and plain assignments
across two to four layers.

AI-Generated: Uses Claude Code (Claude Opus 5.5)
Signed-off-by: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
---
 lib/bb/cookerdata.py | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Richard Purdie Nov. 28, 2026, 10:45 p.m. UTC | #1
On Sat, 2026-11-28 at 21:11 +0000, Ricardo Salveti wrote:
> Each layer.conf is parsed into its own copy of the pre-layer datastore
> and its pass-through variables are then copied with setVar(), so when
> several layers add to the same variable only the last layer in BBLAYERS
> keeps its entries. __depends is copied the same way, so BBINCLUDED
> lists only the last layer.conf and a memory resident bitbake misses
> changes to the others.
> 
> Keep the pre-layer datastore unchanged, merge into a copy of it and
> add the words each later layer adds; PREFERRED_PROVIDER_*,
> PREFERRED_RPROVIDER_* and BBLAYERS_LAYERINDEX_NAME_* hold single
> values, so the last layer still wins for those. Expand a variable only
> once it is known to pass through, and skip layers that only set one of
> its flags. Tested with +=, =+, :append, :remove and plain assignments
> across two to four layers.
> 
> AI-Generated: Uses Claude Code (Claude Opus 5.5)
> Signed-off-by: Ricardo Salveti <ricardo.salveti@oss.qualcomm.com>
> ---
>  lib/bb/cookerdata.py | 23 +++++++++++++++++++++--
>  1 file changed, 21 insertions(+), 2 deletions(-)

Thanks for this, this code has changed a few times and some of the
details have got lost in those changes for other issues.

I'm going to try something a little different than your patch since I
want to use bb.parse.mark_dependency() and also handle append conflicts
slightly differently.

Can you see if the changes I've pushed work for you?

Thanks,

Richard
diff mbox series

Patch

diff --git a/lib/bb/cookerdata.py b/lib/bb/cookerdata.py
index f947040c6..d82702453 100644
--- a/lib/bb/cookerdata.py
+++ b/lib/bb/cookerdata.py
@@ -486,6 +486,10 @@  class CookerDataBuilder(object):
                     layer_filterfunc = ld.getVar("BB_LAYER_FILTER_FUNC")
                 datastores[layer] = ld
 
+            # Compare each layer against the untouched pre-layer data, merge into a copy
+            prelayer = data
+            data = data.createCopy()
+            passed = set()
             for layer in datastores:
                 ld = datastores[layer]
                 for var in ld:
@@ -499,7 +503,7 @@  class CookerDataBuilder(object):
                             bb.warn("%s now set automatically, the variable is being ignored but is set by layer %s" % (var, layer))
                             bb.warn(str(ld.getVar(var, expand=False)))
                         continue
-                    if var in data and (ld.getVar(var) == data.getVar(var)):
+                    if var in prelayer and ld.getVar(var) == prelayer.getVar(var):
                         continue
                     if var.startswith(layer_safevars):
                         pass
@@ -510,7 +514,22 @@  class CookerDataBuilder(object):
                     else:
                         bb.warn("Variable %s is set by %s and will be ignored" % (var, layer))
                         continue
-                    data.setVar(var, ld.getVar(var))
+                    value = ld.getVar(var)
+                    if value is None:
+                        continue
+                    if var == "__depends":
+                        deps = data.getVar(var, False) or []
+                        data.setVar(var, deps + [dep for dep in value if dep not in deps])
+                        continue
+                    if var in passed and isinstance(value, str) and not var.startswith(("PREFERRED_PROVIDER_", "PREFERRED_RPROVIDER_", "BBLAYERS_LAYERINDEX_NAME")):
+                        current = data.getVar(var, False) or ""
+                        known = (prelayer.getVar(var) or "").split() + current.split()
+                        added = [item for item in value.split() if item not in known]
+                        if added:
+                            data.setVar(var, current + " " + " ".join(added))
+                        continue
+                    passed.add(var)
+                    data.setVar(var, value)
 
             if not layerseries:
                 errors.append("No layer sets LAYERSERIES_CORENAMES")