Recursive Expansion

Stay organized with collections Save and categorize content based on your preferences.

Do not use recursive expansion in product/board config makefiles. Recursive expansion is the use of a raw = instead of a := for variable assignment in makefiles. It causes variables that are set to the value of other variables to not evaluate those other variables until they themselves are evaluated. This is functionality that Starlark doesn't support.

Removing it largely depends on the specific scenario of how it's used. Most of the time it involves moving variable assignments to before where they are used. For example, replace:

MY_VAR_2 = foo
# Some stuff in between...
MY_VAR = $(MY_VAR_2)
MY_VAR_2 = bar
# $(MY_VAR) is bar here.

with:

MY_VAR_2 := foo
# Some stuff in between...
MY_VAR_2 := bar
MY_VAR := $(MY_VAR_2)
# $(MY_VAR) is bar here.

Appending to a variable with += uses recursive expansion if that variable hasn't been assigned to with simple expansion before. If you're not sure if the variable has been assigned to before, the += can be replaced with MY_VAR := $(strip $(MY_VAR) new_value).

Removing deferred expansion can also speed up evaluation of the Makefiles even before the conversion to Starlark is done. If variables were set to the result of expensive function calls, the function would only be called once with simple expansion but potentially many times with recursive expansion.