When looking up something in the Yocto project reference manual, I sometimes encounter ??= or ?= operators. Normally, a simple = is used in recipes instead.
What's the difference between ??= and a normal = assignment?
The operator seems to be used with config options like PACKAGECONFIG, but I couldn't find any explanation on what it does.
I found related questions, where the authors are confused by it as well.
For an example have a look at ICECC_DISABLED:
Disables or enables the icecc (Icecream) function. [...]
Setting this variable to “1” in your local.conf disables the function:
ICECC_DISABLED ??= "1"
The ??= and ?= are features of bitbake, so you have to look inside the bitbake reference manual. In simple terms, they allow to set "soft defaults". They are typically used in machine layers and other places that expect later configuration of a variable.
var ??= "x", it will be overridden by ?=, = and += assignmentsvar ?= "x", it will be overridden by = assignments. += depends on the parse order, see below.var = "x", it won't be overridden. += appends.# Typically, those would be spread among different layers:
var ??= "weak default"
var ?= "default"
var = "actually used"
# Result: var = "actually used"
If you'd simply var = "x" and var = "y" in two different places, the last one parsed would win. You're basically begging for race conditions. Thus, bitbake has weak defaults, when a recipe requires a variable to be set, but does want to enable the user to set a different value.
There are some caveats:
?= and += are order sensitive to each other. ?= only sets, if the variable is empty. For example, ?= "a", then += "b" appends to ab, but += "b" then ?= "a" stays as "b".?= assignments to the same variable exist, the first is used.+= overrides ??=. Use var:append = " y" instead:W ??= "x"
W += "y"
# Result: "y"
var ??= "x"
var:append = " y"
# Result: "x y"
PACKAGECONFIG is a popular example, because the recipe needs some config in any case. But if the user has a .bbappend for the recipe, the user config shall be used instead.