Bug 11905

Summary: expandKeys() doesn't expand in definition order
Product: [Build System, Metadata & Runtime] BitBake Reporter: Haris Okanovic <haris.okanovic>
Component: bitbakeAssignee: Richard Purdie <richard.purdie>
Status: RESOLVED NOTABUG QA Contact:
Severity: normal    
Priority: Undecided CC: poky.bs.watcher, poky.watcher
Version: unspecified   
Target Milestone: ---   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: No (bug/feature does not impact docs)

Description Haris Okanovic 2017-08-07 22:14:20 UTC
Consider the following bb snippet:

VAR_foo = "base"
AAA = "foo"
BBB = "${AAA}"
VAR_${BBB} = "wrong"
VAR_${AAA} = "right"

VAR_foo expands to "wrong", which is very unintuitive.

The problem happens in lib.bb.data.expandKeys() which expands variables alphabetically instead of definition order. It first renames VAR_${AAA} --> VAR_foo == "right" then renames VAR_${BBB} --> VAR_foo --> "wrong", instead of the other way around.

You can reproduce this in OpenEmbedded by simply copying the 5-line bb snippet above into any recipe X, and run `bitbake -e X | grep '^VAR_foo='` .
Comment 1 Richard Purdie 2017-08-16 14:55:08 UTC
Key expansion happens at a very specific time in the metadata when expandKeys is called. We don't dynamically expand keys. We also don't store the order of variable declaration as it makes very little sense to given the complexities of the overrides that are possible.

I'd therefore argue that the current behaviour is correct and the only way bitbake can reasonably behave. Its clear and deterministic.

I appreciate its not always 100% intuitive but I really can't see any other way the code can work, sorry.