All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nguyen Minh Tien <zizuzacker@gmail.com>
To: bitbake-devel@lists.openembedded.org
Cc: zizuzacker@gmail.com
Subject: [PATCH 1/1] data_smart: fix operations lost when an override name contains a variable
Date: Sat, 25 Jul 2026 21:30:02 +0700	[thread overview]
Message-ID: <20260725143002.23596-2-zizuzacker@gmail.com> (raw)
In-Reply-To: <20260725143002.23596-1-zizuzacker@gmail.com>

An operation whose override name needs key expansion is silently dropped:

    RDEPENDS:${PN}:append:pn-foo-${MACHINE} = " bar"

renameVar() rebuilds the dependent override keys with a plain string
replace, so renaming RDEPENDS:${PN} leaves the append attached to
RDEPENDS:foo:append:pn-foo-${MACHINE}, which never matches an active
override. expandKeys() cannot fix that up afterwards either, as it works
from a list of keys collected before any renaming happened.

Expand the derived name before renaming it. Only do so once newkey is
itself expanded, otherwise expandKeys() has still to rename newkey and
handles the dependent keys along with it.

Add regression tests for both cases.

Fixes [YOCTO #14867]

Signed-off-by: Nguyen Minh Tien <zizuzacker@gmail.com>
---
 lib/bb/data_smart.py | 11 +++++++++--
 lib/bb/tests/data.py | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index 9961269a3..5738aff95 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -697,8 +697,15 @@ class DataSmart(MutableMapping):
             found = True
             self.overridedata[newkey] = []
             for (v, o) in self.overridedata[key]:
-                self.overridedata[newkey].append([v.replace(key, newkey), o])
-                self.renameVar(v, v.replace(key, newkey))
+                newv = v.replace(key, newkey)
+                # The derived name may still hold a variable reference which
+                # expandKeys() will never revisit, so expand it here. Only once
+                # newkey is expanded though, otherwise expandKeys() has still to
+                # rename newkey and handles the dependent keys along with it.
+                if '${' in newv and '${' not in newkey:
+                    newv = self.expand(newv)
+                self.overridedata[newkey].append([newv, o])
+                self.renameVar(v, newv)
 
         if not found:
             # No variable to rename so not worth the work in writing extra
diff --git a/lib/bb/tests/data.py b/lib/bb/tests/data.py
index fd690a9e2..5ef159eae 100644
--- a/lib/bb/tests/data.py
+++ b/lib/bb/tests/data.py
@@ -406,6 +406,31 @@ class TestOverrides(unittest.TestCase):
         bb.data.expandKeys(self.d)
         self.assertEqual(self.d.getVar("VERSION"), "2")
 
+    # Test an :append whose override name is only resolved by key expansion
+    def test_append_in_expanded_override(self):
+        self.d.setVar("MACHINE", "qemux86")
+        self.d.setVar("PN", "gizmo")
+        self.d.setVar("OVERRIDES", "gizmo:pn-gizmo-qemux86")
+        self.d.setVar("TEST:${PN}", "base")
+        self.d.setVar("TEST:${PN}:append:pn-gizmo-${MACHINE}", " appended")
+        bb.data.expandKeys(self.d)
+        self.assertEqual(self.d.getVar("TEST"), "base appended")
+
+    # Test renaming to a key which is itself not expanded yet, as native.bbclass
+    # does. The dependent override keys must be left for expandKeys() to rename.
+    def test_rename_to_unexpanded_key_with_override(self):
+        self.d.setVar("BPN", "gizmo")
+        self.d.setVar("PN", "gizmo-native")
+        self.d.setVar("OVERRIDES", "class-target")
+        self.d.setVar("TEST:${PN}-lib", "base")
+        self.d.setVar("TEST:${PN}-lib:class-target", "target")
+        with LogRecord() as logs:
+            self.d.renameVar("TEST:${PN}-lib", "TEST:${BPN}-lib-native")
+            bb.data.expandKeys(self.d)
+            self.assertFalse(logContains("renameVar with equivalent keys", logs))
+            self.assertFalse(logContains("replaces original key", logs))
+        self.assertEqual(self.d.getVar("TEST:gizmo-lib-native"), "target")
+
     def test_remove_with_override(self):
         self.d.setVar("TEST:bar", "testvalue2")
         self.d.setVar("TEST:some_val", "testvalue3 testvalue5")
-- 
2.34.1



      reply	other threads:[~2026-07-25 14:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-25 14:30 [PATCH 0/1] data_smart: fix key expansion in conditional overrides Nguyen Minh Tien
2026-07-25 14:30 ` Nguyen Minh Tien [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260725143002.23596-2-zizuzacker@gmail.com \
    --to=zizuzacker@gmail.com \
    --cc=bitbake-devel@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.