Using Conditional Syntax (Overrides) in BitBake
Asked Answered
H

1

7

Reading a book on Yocto. Got to the following page, which says:

BitBake provides a very easy-to-use way to write conditional metadata. It is done by a mechanism called overrides.

The OVERRIDES variable contains values separated by colons (:), and each value is an item we want to satisfy conditions. So, if we have a variable that is conditional on arm, and arm is in OVERRIDES, then the version of the variable that is specific to arm is used rather than the non-conditional version, as shown:

OVERRIDES = "architecture:os:machine"
TEST = "defaultvalue"
TEST_os = "osspecificvalue"
TEST_other = "othercondvalue"

In this example, TEST will be osspecificvalue due to the condition of os being in OVERRIDES.

I'm unclear from this explanation how did TEST become equal to osspecificvalue. Would someone be able to explain it?

Hermosillo answered 8/5, 2018 at 3:50 Comment(3)
in OVERRIDES there is os and no other. TEST variable is overrided by TEST_os value.Daub
@Daub I can't understand the format of the OVERRIDES variable. What are the architecture and machine values? How doe they affect os value?Hermosillo
it's just an example with random values. For real example, you can just see default values with bitbake -e <recipe> | grep ^OVERRIDES=. You can also read definition in mega manual, I found it clearer than bitbake manual.Daub
B
4

NOTE: I have kept the text of this answer unchanged for historical purposes. However, as of Yocto version 3.4, underscores (_) are no longer used to refer to an override, but rather a colon (:) is used. See the migration notes for details.

Bitbake implements it's own dictionary data structure based on Python's MutableMapping in lib/bb/data_smart.py. The goal is to create a dictionary with more flexibility in that each value in the "key,value" pair can be overridden based on specific identifiers.

If you look at how the variables in this dictionary are set, you will see that the datastore allows "overrides" of variables based on a list of override identifiers. These identifiers are expected to be appended with an underscore, like in your example of "TEST_os".

In the case you are referencing, "other" identifier is not in the list of OVERRIDES, so this "smart dictionary" does not override the value of TEST with "othercondvalue". However, because the "os" identifier is in the list of OVERRIDES, the value of TEST is indeed overridden with the value "osspecificvalue".

I would highly recommend reading through the DataSmart class as this is a very simplified explanation, but hopefully it helps.

Also, see the BitBake manual entry for OVERRIDES for more information.

Bludgeon answered 18/5, 2018 at 18:23 Comment(5)
What would be the value of TEST if OVERRIDES = "architecture:os:machine:other"? And another separate question, does OVERRIDES influence all variables; for example if I have a variable MYVAR_other; is it influenced by OVERRIDES?Swordcraft
@Swordcraft The value in that case would be "othercondvalue". Second, OVERRIDES influences all variables in the datastore. So, if you can use d.getvar() to get the variable, then it is influenced by OVERRIDES, even if you created the variable (MYVAR).Bludgeon
+1 This post provides a reasonably good explanation of the OVERRIDES mechanism, but the last line, "Also, see the BitBake manual entry for OVERRIDES for more information." is not the solution, it is the problem. The excessive inadequacy of the BitBake User Manual technical writing is what necessitates the OP in the first place.Marmawke
The link to the Bitbake manual is dead.Circulate
@AaronWright link fixed.Bludgeon

© 2022 - 2024 — McMap. All rights reserved.