Bug 11905 - expandKeys() doesn't expand in definition order
Summary: expandKeys() doesn't expand in definition order
Status: RESOLVED NOTABUG
Alias: None
Product: BitBake
Classification: Build System, Metadata & Runtime
Component: bitbake (show other bugs)
Version: unspecified
Hardware: x86 Multiple
: Undecided normal
Target Milestone: ---
Assignee: Richard Purdie
QA Contact:
URL:
Whiteboard:
Depends on:
Blocks:
 
Reported: 2017-08-07 22:14 UTC by Haris Okanovic
Modified: 2017-08-16 14:55 UTC (History)
2 users (show)

See Also:
OS type for building Yocto: ---
Type of Regression: ---
Verified:
Documentation change: No (bug/feature does not impact docs)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.