1*4882a593Smuzhiyun.. SPDX-License-Identifier: CC-BY-2.5 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun==================== 4*4882a593SmuzhiyunSyntax and Operators 5*4882a593Smuzhiyun==================== 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun| 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunBitBake files have their own syntax. The syntax has similarities to 10*4882a593Smuzhiyunseveral other languages but also has some unique features. This section 11*4882a593Smuzhiyundescribes the available syntax and operators as well as provides 12*4882a593Smuzhiyunexamples. 13*4882a593Smuzhiyun 14*4882a593SmuzhiyunBasic Syntax 15*4882a593Smuzhiyun============ 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunThis section provides some basic syntax examples. 18*4882a593Smuzhiyun 19*4882a593SmuzhiyunBasic Variable Setting 20*4882a593Smuzhiyun---------------------- 21*4882a593Smuzhiyun 22*4882a593SmuzhiyunThe following example sets ``VARIABLE`` to "value". This assignment 23*4882a593Smuzhiyunoccurs immediately as the statement is parsed. It is a "hard" 24*4882a593Smuzhiyunassignment. :: 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun VARIABLE = "value" 27*4882a593Smuzhiyun 28*4882a593SmuzhiyunAs expected, if you include leading or 29*4882a593Smuzhiyuntrailing spaces as part of an assignment, the spaces are retained:: 30*4882a593Smuzhiyun 31*4882a593Smuzhiyun VARIABLE = " value" 32*4882a593Smuzhiyun VARIABLE = "value " 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunSetting ``VARIABLE`` to "" sets 35*4882a593Smuzhiyunit to an empty string, while setting the variable to " " sets it to a 36*4882a593Smuzhiyunblank space (i.e. these are not the same values). :: 37*4882a593Smuzhiyun 38*4882a593Smuzhiyun VARIABLE = "" 39*4882a593Smuzhiyun VARIABLE = " " 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunYou can use single quotes instead of double quotes when setting a 42*4882a593Smuzhiyunvariable's value. Doing so allows you to use values that contain the 43*4882a593Smuzhiyundouble quote character:: 44*4882a593Smuzhiyun 45*4882a593Smuzhiyun VARIABLE = 'I have a " in my value' 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun.. note:: 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun Unlike in Bourne shells, single quotes work identically to double 50*4882a593Smuzhiyun quotes in all other ways. They do not suppress variable expansions. 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunModifying Existing Variables 53*4882a593Smuzhiyun---------------------------- 54*4882a593Smuzhiyun 55*4882a593SmuzhiyunSometimes you need to modify existing variables. Following are some 56*4882a593Smuzhiyuncases where you might find you want to modify an existing variable: 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun- Customize a recipe that uses the variable. 59*4882a593Smuzhiyun 60*4882a593Smuzhiyun- Change a variable's default value used in a ``*.bbclass`` file. 61*4882a593Smuzhiyun 62*4882a593Smuzhiyun- Change the variable in a ``*.bbappend`` file to override the variable 63*4882a593Smuzhiyun in the original recipe. 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun- Change the variable in a configuration file so that the value 66*4882a593Smuzhiyun overrides an existing configuration. 67*4882a593Smuzhiyun 68*4882a593SmuzhiyunChanging a variable value can sometimes depend on how the value was 69*4882a593Smuzhiyunoriginally assigned and also on the desired intent of the change. In 70*4882a593Smuzhiyunparticular, when you append a value to a variable that has a default 71*4882a593Smuzhiyunvalue, the resulting value might not be what you expect. In this case, 72*4882a593Smuzhiyunthe value you provide might replace the value rather than append to the 73*4882a593Smuzhiyundefault value. 74*4882a593Smuzhiyun 75*4882a593SmuzhiyunIf after you have changed a variable's value and something unexplained 76*4882a593Smuzhiyunoccurs, you can use BitBake to check the actual value of the suspect 77*4882a593Smuzhiyunvariable. You can make these checks for both configuration and recipe 78*4882a593Smuzhiyunlevel changes: 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun- For configuration changes, use the following:: 81*4882a593Smuzhiyun 82*4882a593Smuzhiyun $ bitbake -e 83*4882a593Smuzhiyun 84*4882a593Smuzhiyun This 85*4882a593Smuzhiyun command displays variable values after the configuration files (i.e. 86*4882a593Smuzhiyun ``local.conf``, ``bblayers.conf``, ``bitbake.conf`` and so forth) 87*4882a593Smuzhiyun have been parsed. 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun .. note:: 90*4882a593Smuzhiyun 91*4882a593Smuzhiyun Variables that are exported to the environment are preceded by the 92*4882a593Smuzhiyun string "export" in the command's output. 93*4882a593Smuzhiyun 94*4882a593Smuzhiyun- To find changes to a given variable in a specific recipe, use the 95*4882a593Smuzhiyun following:: 96*4882a593Smuzhiyun 97*4882a593Smuzhiyun $ bitbake recipename -e | grep VARIABLENAME=\" 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun This command checks to see if the variable actually makes 100*4882a593Smuzhiyun it into a specific recipe. 101*4882a593Smuzhiyun 102*4882a593SmuzhiyunLine Joining 103*4882a593Smuzhiyun------------ 104*4882a593Smuzhiyun 105*4882a593SmuzhiyunOutside of :ref:`functions <bitbake-user-manual/bitbake-user-manual-metadata:functions>`, 106*4882a593SmuzhiyunBitBake joins any line ending in 107*4882a593Smuzhiyuna backslash character ("\\") with the following line before parsing 108*4882a593Smuzhiyunstatements. The most common use for the "\\" character is to split 109*4882a593Smuzhiyunvariable assignments over multiple lines, as in the following example:: 110*4882a593Smuzhiyun 111*4882a593Smuzhiyun FOO = "bar \ 112*4882a593Smuzhiyun baz \ 113*4882a593Smuzhiyun qaz" 114*4882a593Smuzhiyun 115*4882a593SmuzhiyunBoth the "\\" character and the newline 116*4882a593Smuzhiyuncharacter that follow it are removed when joining lines. Thus, no 117*4882a593Smuzhiyunnewline characters end up in the value of ``FOO``. 118*4882a593Smuzhiyun 119*4882a593SmuzhiyunConsider this additional example where the two assignments both assign 120*4882a593Smuzhiyun"barbaz" to ``FOO``:: 121*4882a593Smuzhiyun 122*4882a593Smuzhiyun FOO = "barbaz" 123*4882a593Smuzhiyun FOO = "bar\ 124*4882a593Smuzhiyun baz" 125*4882a593Smuzhiyun 126*4882a593Smuzhiyun.. note:: 127*4882a593Smuzhiyun 128*4882a593Smuzhiyun BitBake does not interpret escape sequences like "\\n" in variable 129*4882a593Smuzhiyun values. For these to have an effect, the value must be passed to some 130*4882a593Smuzhiyun utility that interprets escape sequences, such as 131*4882a593Smuzhiyun ``printf`` or ``echo -n``. 132*4882a593Smuzhiyun 133*4882a593SmuzhiyunVariable Expansion 134*4882a593Smuzhiyun------------------ 135*4882a593Smuzhiyun 136*4882a593SmuzhiyunVariables can reference the contents of other variables using a syntax 137*4882a593Smuzhiyunthat is similar to variable expansion in Bourne shells. The following 138*4882a593Smuzhiyunassignments result in A containing "aval" and B evaluating to 139*4882a593Smuzhiyun"preavalpost". :: 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun A = "aval" 142*4882a593Smuzhiyun B = "pre${A}post" 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun.. note:: 145*4882a593Smuzhiyun 146*4882a593Smuzhiyun Unlike in Bourne shells, the curly braces are mandatory: Only ``${FOO}`` and not 147*4882a593Smuzhiyun ``$FOO`` is recognized as an expansion of ``FOO``. 148*4882a593Smuzhiyun 149*4882a593SmuzhiyunThe "=" operator does not immediately expand variable references in the 150*4882a593Smuzhiyunright-hand side. Instead, expansion is deferred until the variable 151*4882a593Smuzhiyunassigned to is actually used. The result depends on the current values 152*4882a593Smuzhiyunof the referenced variables. The following example should clarify this 153*4882a593Smuzhiyunbehavior:: 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun A = "${B} baz" 156*4882a593Smuzhiyun B = "${C} bar" 157*4882a593Smuzhiyun C = "foo" 158*4882a593Smuzhiyun *At this point, ${A} equals "foo bar baz"* 159*4882a593Smuzhiyun C = "qux" 160*4882a593Smuzhiyun *At this point, ${A} equals "qux bar baz"* 161*4882a593Smuzhiyun B = "norf" 162*4882a593Smuzhiyun *At this point, ${A} equals "norf baz"* 163*4882a593Smuzhiyun 164*4882a593SmuzhiyunContrast this behavior with the 165*4882a593Smuzhiyun:ref:`bitbake-user-manual/bitbake-user-manual-metadata:immediate variable 166*4882a593Smuzhiyunexpansion (:=)` operator. 167*4882a593Smuzhiyun 168*4882a593SmuzhiyunIf the variable expansion syntax is used on a variable that does not 169*4882a593Smuzhiyunexist, the string is kept as is. For example, given the following 170*4882a593Smuzhiyunassignment, ``BAR`` expands to the literal string "${FOO}" as long as 171*4882a593Smuzhiyun``FOO`` does not exist. :: 172*4882a593Smuzhiyun 173*4882a593Smuzhiyun BAR = "${FOO}" 174*4882a593Smuzhiyun 175*4882a593SmuzhiyunSetting a default value (?=) 176*4882a593Smuzhiyun---------------------------- 177*4882a593Smuzhiyun 178*4882a593SmuzhiyunYou can use the "?=" operator to achieve a "softer" assignment for a 179*4882a593Smuzhiyunvariable. This type of assignment allows you to define a variable if it 180*4882a593Smuzhiyunis undefined when the statement is parsed, but to leave the value alone 181*4882a593Smuzhiyunif the variable has a value. Here is an example:: 182*4882a593Smuzhiyun 183*4882a593Smuzhiyun A ?= "aval" 184*4882a593Smuzhiyun 185*4882a593SmuzhiyunIf ``A`` is 186*4882a593Smuzhiyunset at the time this statement is parsed, the variable retains its 187*4882a593Smuzhiyunvalue. However, if ``A`` is not set, the variable is set to "aval". 188*4882a593Smuzhiyun 189*4882a593Smuzhiyun.. note:: 190*4882a593Smuzhiyun 191*4882a593Smuzhiyun This assignment is immediate. Consequently, if multiple "?=" 192*4882a593Smuzhiyun assignments to a single variable exist, the first of those ends up 193*4882a593Smuzhiyun getting used. 194*4882a593Smuzhiyun 195*4882a593SmuzhiyunSetting a weak default value (??=) 196*4882a593Smuzhiyun---------------------------------- 197*4882a593Smuzhiyun 198*4882a593SmuzhiyunThe weak default value of a variable is the value which that variable 199*4882a593Smuzhiyunwill expand to if no value has been assigned to it via any of the other 200*4882a593Smuzhiyunassignment operators. The "??=" operator takes effect immediately, replacing 201*4882a593Smuzhiyunany previously defined weak default value. Here is an example:: 202*4882a593Smuzhiyun 203*4882a593Smuzhiyun W ??= "x" 204*4882a593Smuzhiyun A := "${W}" # Immediate variable expansion 205*4882a593Smuzhiyun W ??= "y" 206*4882a593Smuzhiyun B := "${W}" # Immediate variable expansion 207*4882a593Smuzhiyun W ??= "z" 208*4882a593Smuzhiyun C = "${W}" 209*4882a593Smuzhiyun W ?= "i" 210*4882a593Smuzhiyun 211*4882a593SmuzhiyunAfter parsing we will have:: 212*4882a593Smuzhiyun 213*4882a593Smuzhiyun A = "x" 214*4882a593Smuzhiyun B = "y" 215*4882a593Smuzhiyun C = "i" 216*4882a593Smuzhiyun W = "i" 217*4882a593Smuzhiyun 218*4882a593SmuzhiyunAppending and prepending non-override style will not substitute the weak 219*4882a593Smuzhiyundefault value, which means that after parsing:: 220*4882a593Smuzhiyun 221*4882a593Smuzhiyun W ??= "x" 222*4882a593Smuzhiyun W += "y" 223*4882a593Smuzhiyun 224*4882a593Smuzhiyunwe will have:: 225*4882a593Smuzhiyun 226*4882a593Smuzhiyun W = " y" 227*4882a593Smuzhiyun 228*4882a593SmuzhiyunOn the other hand, override-style appends/prepends/removes are applied after 229*4882a593Smuzhiyunany active weak default value has been substituted:: 230*4882a593Smuzhiyun 231*4882a593Smuzhiyun W ??= "x" 232*4882a593Smuzhiyun W:append = "y" 233*4882a593Smuzhiyun 234*4882a593SmuzhiyunAfter parsing we will have:: 235*4882a593Smuzhiyun 236*4882a593Smuzhiyun W = "xy" 237*4882a593Smuzhiyun 238*4882a593SmuzhiyunImmediate variable expansion (:=) 239*4882a593Smuzhiyun--------------------------------- 240*4882a593Smuzhiyun 241*4882a593SmuzhiyunThe ":=" operator results in a variable's contents being expanded 242*4882a593Smuzhiyunimmediately, rather than when the variable is actually used:: 243*4882a593Smuzhiyun 244*4882a593Smuzhiyun T = "123" 245*4882a593Smuzhiyun A := "test ${T}" 246*4882a593Smuzhiyun T = "456" 247*4882a593Smuzhiyun B := "${T} ${C}" 248*4882a593Smuzhiyun C = "cval" 249*4882a593Smuzhiyun C := "${C}append" 250*4882a593Smuzhiyun 251*4882a593SmuzhiyunIn this example, ``A`` contains "test 123", even though the final value 252*4882a593Smuzhiyunof :term:`T` is "456". The variable :term:`B` will end up containing "456 253*4882a593Smuzhiyuncvalappend". This is because references to undefined variables are 254*4882a593Smuzhiyunpreserved as is during (immediate)expansion. This is in contrast to GNU 255*4882a593SmuzhiyunMake, where undefined variables expand to nothing. The variable ``C`` 256*4882a593Smuzhiyuncontains "cvalappend" since ``${C}`` immediately expands to "cval". 257*4882a593Smuzhiyun 258*4882a593Smuzhiyun.. _appending-and-prepending: 259*4882a593Smuzhiyun 260*4882a593SmuzhiyunAppending (+=) and prepending (=+) With Spaces 261*4882a593Smuzhiyun---------------------------------------------- 262*4882a593Smuzhiyun 263*4882a593SmuzhiyunAppending and prepending values is common and can be accomplished using 264*4882a593Smuzhiyunthe "+=" and "=+" operators. These operators insert a space between the 265*4882a593Smuzhiyuncurrent value and prepended or appended value. 266*4882a593Smuzhiyun 267*4882a593SmuzhiyunThese operators take immediate effect during parsing. Here are some 268*4882a593Smuzhiyunexamples:: 269*4882a593Smuzhiyun 270*4882a593Smuzhiyun B = "bval" 271*4882a593Smuzhiyun B += "additionaldata" 272*4882a593Smuzhiyun C = "cval" 273*4882a593Smuzhiyun C =+ "test" 274*4882a593Smuzhiyun 275*4882a593SmuzhiyunThe variable :term:`B` contains "bval additionaldata" and ``C`` contains "test 276*4882a593Smuzhiyuncval". 277*4882a593Smuzhiyun 278*4882a593Smuzhiyun.. _appending-and-prepending-without-spaces: 279*4882a593Smuzhiyun 280*4882a593SmuzhiyunAppending (.=) and Prepending (=.) Without Spaces 281*4882a593Smuzhiyun------------------------------------------------- 282*4882a593Smuzhiyun 283*4882a593SmuzhiyunIf you want to append or prepend values without an inserted space, use 284*4882a593Smuzhiyunthe ".=" and "=." operators. 285*4882a593Smuzhiyun 286*4882a593SmuzhiyunThese operators take immediate effect during parsing. Here are some 287*4882a593Smuzhiyunexamples:: 288*4882a593Smuzhiyun 289*4882a593Smuzhiyun B = "bval" 290*4882a593Smuzhiyun B .= "additionaldata" 291*4882a593Smuzhiyun C = "cval" 292*4882a593Smuzhiyun C =. "test" 293*4882a593Smuzhiyun 294*4882a593SmuzhiyunThe variable :term:`B` contains "bvaladditionaldata" and ``C`` contains 295*4882a593Smuzhiyun"testcval". 296*4882a593Smuzhiyun 297*4882a593SmuzhiyunAppending and Prepending (Override Style Syntax) 298*4882a593Smuzhiyun------------------------------------------------ 299*4882a593Smuzhiyun 300*4882a593SmuzhiyunYou can also append and prepend a variable's value using an override 301*4882a593Smuzhiyunstyle syntax. When you use this syntax, no spaces are inserted. 302*4882a593Smuzhiyun 303*4882a593SmuzhiyunThese operators differ from the ":=", ".=", "=.", "+=", and "=+" 304*4882a593Smuzhiyunoperators in that their effects are applied at variable expansion time 305*4882a593Smuzhiyunrather than being immediately applied. Here are some examples:: 306*4882a593Smuzhiyun 307*4882a593Smuzhiyun B = "bval" 308*4882a593Smuzhiyun B:append = " additional data" 309*4882a593Smuzhiyun C = "cval" 310*4882a593Smuzhiyun C:prepend = "additional data " 311*4882a593Smuzhiyun D = "dval" 312*4882a593Smuzhiyun D:append = "additional data" 313*4882a593Smuzhiyun 314*4882a593SmuzhiyunThe variable :term:`B` 315*4882a593Smuzhiyunbecomes "bval additional data" and ``C`` becomes "additional data cval". 316*4882a593SmuzhiyunThe variable ``D`` becomes "dvaladditional data". 317*4882a593Smuzhiyun 318*4882a593Smuzhiyun.. note:: 319*4882a593Smuzhiyun 320*4882a593Smuzhiyun You must control all spacing when you use the override syntax. 321*4882a593Smuzhiyun 322*4882a593SmuzhiyunIt is also possible to append and prepend to shell functions and 323*4882a593SmuzhiyunBitBake-style Python functions. See the ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:shell functions`" and ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:bitbake-style python functions`" 324*4882a593Smuzhiyunsections for examples. 325*4882a593Smuzhiyun 326*4882a593Smuzhiyun.. _removing-override-style-syntax: 327*4882a593Smuzhiyun 328*4882a593SmuzhiyunRemoval (Override Style Syntax) 329*4882a593Smuzhiyun------------------------------- 330*4882a593Smuzhiyun 331*4882a593SmuzhiyunYou can remove values from lists using the removal override style 332*4882a593Smuzhiyunsyntax. Specifying a value for removal causes all occurrences of that 333*4882a593Smuzhiyunvalue to be removed from the variable. 334*4882a593Smuzhiyun 335*4882a593SmuzhiyunWhen you use this syntax, BitBake expects one or more strings. 336*4882a593SmuzhiyunSurrounding spaces and spacing are preserved. Here is an example:: 337*4882a593Smuzhiyun 338*4882a593Smuzhiyun FOO = "123 456 789 123456 123 456 123 456" 339*4882a593Smuzhiyun FOO:remove = "123" 340*4882a593Smuzhiyun FOO:remove = "456" 341*4882a593Smuzhiyun FOO2 = " abc def ghi abcdef abc def abc def def" 342*4882a593Smuzhiyun FOO2:remove = "\ 343*4882a593Smuzhiyun def \ 344*4882a593Smuzhiyun abc \ 345*4882a593Smuzhiyun ghi \ 346*4882a593Smuzhiyun " 347*4882a593Smuzhiyun 348*4882a593SmuzhiyunThe variable ``FOO`` becomes 349*4882a593Smuzhiyun" 789 123456 " and ``FOO2`` becomes " abcdef ". 350*4882a593Smuzhiyun 351*4882a593SmuzhiyunLike ":append" and ":prepend", ":remove" is applied at variable 352*4882a593Smuzhiyunexpansion time. 353*4882a593Smuzhiyun 354*4882a593SmuzhiyunOverride Style Operation Advantages 355*4882a593Smuzhiyun----------------------------------- 356*4882a593Smuzhiyun 357*4882a593SmuzhiyunAn advantage of the override style operations ":append", ":prepend", and 358*4882a593Smuzhiyun":remove" as compared to the "+=" and "=+" operators is that the 359*4882a593Smuzhiyunoverride style operators provide guaranteed operations. For example, 360*4882a593Smuzhiyunconsider a class ``foo.bbclass`` that needs to add the value "val" to 361*4882a593Smuzhiyunthe variable ``FOO``, and a recipe that uses ``foo.bbclass`` as follows:: 362*4882a593Smuzhiyun 363*4882a593Smuzhiyun inherit foo 364*4882a593Smuzhiyun FOO = "initial" 365*4882a593Smuzhiyun 366*4882a593SmuzhiyunIf ``foo.bbclass`` uses the "+=" operator, 367*4882a593Smuzhiyunas follows, then the final value of ``FOO`` will be "initial", which is 368*4882a593Smuzhiyunnot what is desired:: 369*4882a593Smuzhiyun 370*4882a593Smuzhiyun FOO += "val" 371*4882a593Smuzhiyun 372*4882a593SmuzhiyunIf, on the other hand, ``foo.bbclass`` 373*4882a593Smuzhiyunuses the ":append" operator, then the final value of ``FOO`` will be 374*4882a593Smuzhiyun"initial val", as intended:: 375*4882a593Smuzhiyun 376*4882a593Smuzhiyun FOO:append = " val" 377*4882a593Smuzhiyun 378*4882a593Smuzhiyun.. note:: 379*4882a593Smuzhiyun 380*4882a593Smuzhiyun It is never necessary to use "+=" together with ":append". The following 381*4882a593Smuzhiyun sequence of assignments appends "barbaz" to FOO:: 382*4882a593Smuzhiyun 383*4882a593Smuzhiyun FOO:append = "bar" 384*4882a593Smuzhiyun FOO:append = "baz" 385*4882a593Smuzhiyun 386*4882a593Smuzhiyun 387*4882a593Smuzhiyun The only effect of changing the second assignment in the previous 388*4882a593Smuzhiyun example to use "+=" would be to add a space before "baz" in the 389*4882a593Smuzhiyun appended value (due to how the "+=" operator works). 390*4882a593Smuzhiyun 391*4882a593SmuzhiyunAnother advantage of the override style operations is that you can 392*4882a593Smuzhiyuncombine them with other overrides as described in the 393*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-metadata:conditional syntax (overrides)`" section. 394*4882a593Smuzhiyun 395*4882a593SmuzhiyunVariable Flag Syntax 396*4882a593Smuzhiyun-------------------- 397*4882a593Smuzhiyun 398*4882a593SmuzhiyunVariable flags are BitBake's implementation of variable properties or 399*4882a593Smuzhiyunattributes. It is a way of tagging extra information onto a variable. 400*4882a593SmuzhiyunYou can find more out about variable flags in general in the 401*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section. 402*4882a593Smuzhiyun 403*4882a593SmuzhiyunYou can define, append, and prepend values to variable flags. All the 404*4882a593Smuzhiyunstandard syntax operations previously mentioned work for variable flags 405*4882a593Smuzhiyunexcept for override style syntax (i.e. ":prepend", ":append", and 406*4882a593Smuzhiyun":remove"). 407*4882a593Smuzhiyun 408*4882a593SmuzhiyunHere are some examples showing how to set variable flags:: 409*4882a593Smuzhiyun 410*4882a593Smuzhiyun FOO[a] = "abc" 411*4882a593Smuzhiyun FOO[b] = "123" 412*4882a593Smuzhiyun FOO[a] += "456" 413*4882a593Smuzhiyun 414*4882a593SmuzhiyunThe variable ``FOO`` has two flags: 415*4882a593Smuzhiyun``[a]`` and ``[b]``. The flags are immediately set to "abc" and "123", 416*4882a593Smuzhiyunrespectively. The ``[a]`` flag becomes "abc 456". 417*4882a593Smuzhiyun 418*4882a593SmuzhiyunNo need exists to pre-define variable flags. You can simply start using 419*4882a593Smuzhiyunthem. One extremely common application is to attach some brief 420*4882a593Smuzhiyundocumentation to a BitBake variable as follows:: 421*4882a593Smuzhiyun 422*4882a593Smuzhiyun CACHE[doc] = "The directory holding the cache of the metadata." 423*4882a593Smuzhiyun 424*4882a593SmuzhiyunInline Python Variable Expansion 425*4882a593Smuzhiyun-------------------------------- 426*4882a593Smuzhiyun 427*4882a593SmuzhiyunYou can use inline Python variable expansion to set variables. Here is 428*4882a593Smuzhiyunan example:: 429*4882a593Smuzhiyun 430*4882a593Smuzhiyun DATE = "${@time.strftime('%Y%m%d',time.gmtime())}" 431*4882a593Smuzhiyun 432*4882a593SmuzhiyunThis example results in the ``DATE`` variable being set to the current date. 433*4882a593Smuzhiyun 434*4882a593SmuzhiyunProbably the most common use of this feature is to extract the value of 435*4882a593Smuzhiyunvariables from BitBake's internal data dictionary, ``d``. The following 436*4882a593Smuzhiyunlines select the values of a package name and its version number, 437*4882a593Smuzhiyunrespectively:: 438*4882a593Smuzhiyun 439*4882a593Smuzhiyun PN = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}" 440*4882a593Smuzhiyun PV = "${@bb.parse.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}" 441*4882a593Smuzhiyun 442*4882a593Smuzhiyun.. note:: 443*4882a593Smuzhiyun 444*4882a593Smuzhiyun Inline Python expressions work just like variable expansions insofar as the 445*4882a593Smuzhiyun "=" and ":=" operators are concerned. Given the following assignment, foo() 446*4882a593Smuzhiyun is called each time FOO is expanded:: 447*4882a593Smuzhiyun 448*4882a593Smuzhiyun FOO = "${@foo()}" 449*4882a593Smuzhiyun 450*4882a593Smuzhiyun Contrast this with the following immediate assignment, where foo() is only 451*4882a593Smuzhiyun called once, while the assignment is parsed:: 452*4882a593Smuzhiyun 453*4882a593Smuzhiyun FOO := "${@foo()}" 454*4882a593Smuzhiyun 455*4882a593SmuzhiyunFor a different way to set variables with Python code during parsing, 456*4882a593Smuzhiyunsee the 457*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-metadata:anonymous python functions`" section. 458*4882a593Smuzhiyun 459*4882a593SmuzhiyunUnsetting variables 460*4882a593Smuzhiyun------------------- 461*4882a593Smuzhiyun 462*4882a593SmuzhiyunIt is possible to completely remove a variable or a variable flag from 463*4882a593SmuzhiyunBitBake's internal data dictionary by using the "unset" keyword. Here is 464*4882a593Smuzhiyunan example:: 465*4882a593Smuzhiyun 466*4882a593Smuzhiyun unset DATE 467*4882a593Smuzhiyun unset do_fetch[noexec] 468*4882a593Smuzhiyun 469*4882a593SmuzhiyunThese two statements remove the ``DATE`` and the ``do_fetch[noexec]`` flag. 470*4882a593Smuzhiyun 471*4882a593SmuzhiyunProviding Pathnames 472*4882a593Smuzhiyun------------------- 473*4882a593Smuzhiyun 474*4882a593SmuzhiyunWhen specifying pathnames for use with BitBake, do not use the tilde 475*4882a593Smuzhiyun("~") character as a shortcut for your home directory. Doing so might 476*4882a593Smuzhiyuncause BitBake to not recognize the path since BitBake does not expand 477*4882a593Smuzhiyunthis character in the same way a shell would. 478*4882a593Smuzhiyun 479*4882a593SmuzhiyunInstead, provide a fuller path as the following example illustrates:: 480*4882a593Smuzhiyun 481*4882a593Smuzhiyun BBLAYERS ?= " \ 482*4882a593Smuzhiyun /home/scott-lenovo/LayerA \ 483*4882a593Smuzhiyun " 484*4882a593Smuzhiyun 485*4882a593SmuzhiyunExporting Variables to the Environment 486*4882a593Smuzhiyun====================================== 487*4882a593Smuzhiyun 488*4882a593SmuzhiyunYou can export variables to the environment of running tasks by using 489*4882a593Smuzhiyunthe ``export`` keyword. For example, in the following example, the 490*4882a593Smuzhiyun``do_foo`` task prints "value from the environment" when run:: 491*4882a593Smuzhiyun 492*4882a593Smuzhiyun export ENV_VARIABLE 493*4882a593Smuzhiyun ENV_VARIABLE = "value from the environment" 494*4882a593Smuzhiyun 495*4882a593Smuzhiyun do_foo() { 496*4882a593Smuzhiyun bbplain "$ENV_VARIABLE" 497*4882a593Smuzhiyun } 498*4882a593Smuzhiyun 499*4882a593Smuzhiyun.. note:: 500*4882a593Smuzhiyun 501*4882a593Smuzhiyun BitBake does not expand ``$ENV_VARIABLE`` in this case because it lacks the 502*4882a593Smuzhiyun obligatory ``{}`` . Rather, ``$ENV_VARIABLE`` is expanded by the shell. 503*4882a593Smuzhiyun 504*4882a593SmuzhiyunIt does not matter whether ``export ENV_VARIABLE`` appears before or 505*4882a593Smuzhiyunafter assignments to ``ENV_VARIABLE``. 506*4882a593Smuzhiyun 507*4882a593SmuzhiyunIt is also possible to combine ``export`` with setting a value for the 508*4882a593Smuzhiyunvariable. Here is an example:: 509*4882a593Smuzhiyun 510*4882a593Smuzhiyun export ENV_VARIABLE = "variable-value" 511*4882a593Smuzhiyun 512*4882a593SmuzhiyunIn the output of ``bitbake -e``, variables that are exported to the 513*4882a593Smuzhiyunenvironment are preceded by "export". 514*4882a593Smuzhiyun 515*4882a593SmuzhiyunAmong the variables commonly exported to the environment are ``CC`` and 516*4882a593Smuzhiyun``CFLAGS``, which are picked up by many build systems. 517*4882a593Smuzhiyun 518*4882a593SmuzhiyunConditional Syntax (Overrides) 519*4882a593Smuzhiyun============================== 520*4882a593Smuzhiyun 521*4882a593SmuzhiyunBitBake uses :term:`OVERRIDES` to control what 522*4882a593Smuzhiyunvariables are overridden after BitBake parses recipes and configuration 523*4882a593Smuzhiyunfiles. This section describes how you can use :term:`OVERRIDES` as 524*4882a593Smuzhiyunconditional metadata, talks about key expansion in relationship to 525*4882a593Smuzhiyun:term:`OVERRIDES`, and provides some examples to help with understanding. 526*4882a593Smuzhiyun 527*4882a593SmuzhiyunConditional Metadata 528*4882a593Smuzhiyun-------------------- 529*4882a593Smuzhiyun 530*4882a593SmuzhiyunYou can use :term:`OVERRIDES` to conditionally select a specific version of 531*4882a593Smuzhiyuna variable and to conditionally append or prepend the value of a 532*4882a593Smuzhiyunvariable. 533*4882a593Smuzhiyun 534*4882a593Smuzhiyun.. note:: 535*4882a593Smuzhiyun 536*4882a593Smuzhiyun Overrides can only use lower-case characters, digits and dashes. 537*4882a593Smuzhiyun In particular, colons are not permitted in override names as they are used to 538*4882a593Smuzhiyun separate overrides from each other and from the variable name. 539*4882a593Smuzhiyun 540*4882a593Smuzhiyun- *Selecting a Variable:* The :term:`OVERRIDES` variable is a 541*4882a593Smuzhiyun colon-character-separated list that contains items for which you want 542*4882a593Smuzhiyun to satisfy conditions. Thus, if you have a variable that is 543*4882a593Smuzhiyun conditional on "arm", and "arm" is in :term:`OVERRIDES`, then the 544*4882a593Smuzhiyun "arm"-specific version of the variable is used rather than the 545*4882a593Smuzhiyun non-conditional version. Here is an example:: 546*4882a593Smuzhiyun 547*4882a593Smuzhiyun OVERRIDES = "architecture:os:machine" 548*4882a593Smuzhiyun TEST = "default" 549*4882a593Smuzhiyun TEST:os = "osspecific" 550*4882a593Smuzhiyun TEST:nooverride = "othercondvalue" 551*4882a593Smuzhiyun 552*4882a593Smuzhiyun In this example, the :term:`OVERRIDES` 553*4882a593Smuzhiyun variable lists three overrides: "architecture", "os", and "machine". 554*4882a593Smuzhiyun The variable ``TEST`` by itself has a default value of "default". You 555*4882a593Smuzhiyun select the os-specific version of the ``TEST`` variable by appending 556*4882a593Smuzhiyun the "os" override to the variable (i.e. ``TEST:os``). 557*4882a593Smuzhiyun 558*4882a593Smuzhiyun To better understand this, consider a practical example that assumes 559*4882a593Smuzhiyun an OpenEmbedded metadata-based Linux kernel recipe file. The 560*4882a593Smuzhiyun following lines from the recipe file first set the kernel branch 561*4882a593Smuzhiyun variable ``KBRANCH`` to a default value, then conditionally override 562*4882a593Smuzhiyun that value based on the architecture of the build:: 563*4882a593Smuzhiyun 564*4882a593Smuzhiyun KBRANCH = "standard/base" 565*4882a593Smuzhiyun KBRANCH:qemuarm = "standard/arm-versatile-926ejs" 566*4882a593Smuzhiyun KBRANCH:qemumips = "standard/mti-malta32" 567*4882a593Smuzhiyun KBRANCH:qemuppc = "standard/qemuppc" 568*4882a593Smuzhiyun KBRANCH:qemux86 = "standard/common-pc/base" 569*4882a593Smuzhiyun KBRANCH:qemux86-64 = "standard/common-pc-64/base" 570*4882a593Smuzhiyun KBRANCH:qemumips64 = "standard/mti-malta64" 571*4882a593Smuzhiyun 572*4882a593Smuzhiyun- *Appending and Prepending:* BitBake also supports append and prepend 573*4882a593Smuzhiyun operations to variable values based on whether a specific item is 574*4882a593Smuzhiyun listed in :term:`OVERRIDES`. Here is an example:: 575*4882a593Smuzhiyun 576*4882a593Smuzhiyun DEPENDS = "glibc ncurses" 577*4882a593Smuzhiyun OVERRIDES = "machine:local" 578*4882a593Smuzhiyun DEPENDS:append:machine = "libmad" 579*4882a593Smuzhiyun 580*4882a593Smuzhiyun In this example, :term:`DEPENDS` becomes "glibc ncurses libmad". 581*4882a593Smuzhiyun 582*4882a593Smuzhiyun Again, using an OpenEmbedded metadata-based kernel recipe file as an 583*4882a593Smuzhiyun example, the following lines will conditionally append to the 584*4882a593Smuzhiyun ``KERNEL_FEATURES`` variable based on the architecture:: 585*4882a593Smuzhiyun 586*4882a593Smuzhiyun KERNEL_FEATURES:append = " ${KERNEL_EXTRA_FEATURES}" 587*4882a593Smuzhiyun KERNEL_FEATURES:append:qemux86=" cfg/sound.scc cfg/paravirt_kvm.scc" 588*4882a593Smuzhiyun KERNEL_FEATURES:append:qemux86-64=" cfg/sound.scc cfg/paravirt_kvm.scc" 589*4882a593Smuzhiyun 590*4882a593Smuzhiyun- *Setting a Variable for a Single Task:* BitBake supports setting a 591*4882a593Smuzhiyun variable just for the duration of a single task. Here is an example:: 592*4882a593Smuzhiyun 593*4882a593Smuzhiyun FOO:task-configure = "val 1" 594*4882a593Smuzhiyun FOO:task-compile = "val 2" 595*4882a593Smuzhiyun 596*4882a593Smuzhiyun In the 597*4882a593Smuzhiyun previous example, ``FOO`` has the value "val 1" while the 598*4882a593Smuzhiyun ``do_configure`` task is executed, and the value "val 2" while the 599*4882a593Smuzhiyun ``do_compile`` task is executed. 600*4882a593Smuzhiyun 601*4882a593Smuzhiyun Internally, this is implemented by prepending the task (e.g. 602*4882a593Smuzhiyun "task-compile:") to the value of 603*4882a593Smuzhiyun :term:`OVERRIDES` for the local datastore of the 604*4882a593Smuzhiyun ``do_compile`` task. 605*4882a593Smuzhiyun 606*4882a593Smuzhiyun You can also use this syntax with other combinations (e.g. 607*4882a593Smuzhiyun "``:prepend``") as shown in the following example:: 608*4882a593Smuzhiyun 609*4882a593Smuzhiyun EXTRA_OEMAKE:prepend:task-compile = "${PARALLEL_MAKE} " 610*4882a593Smuzhiyun 611*4882a593Smuzhiyun.. note:: 612*4882a593Smuzhiyun 613*4882a593Smuzhiyun Before BitBake 1.52 (Honister 3.4), the syntax for :term:`OVERRIDES` 614*4882a593Smuzhiyun used ``_`` instead of ``:``, so you will still find a lot of documentation 615*4882a593Smuzhiyun using ``_append``, ``_prepend``, and ``_remove``, for example. 616*4882a593Smuzhiyun 617*4882a593Smuzhiyun For details, see the 618*4882a593Smuzhiyun :yocto_docs:`Overrides Syntax Changes </migration-guides/migration-3.4.html#override-syntax-changes>` 619*4882a593Smuzhiyun section in the Yocto Project manual migration notes. 620*4882a593Smuzhiyun 621*4882a593SmuzhiyunKey Expansion 622*4882a593Smuzhiyun------------- 623*4882a593Smuzhiyun 624*4882a593SmuzhiyunKey expansion happens when the BitBake datastore is finalized. To better 625*4882a593Smuzhiyununderstand this, consider the following example:: 626*4882a593Smuzhiyun 627*4882a593Smuzhiyun A${B} = "X" 628*4882a593Smuzhiyun B = "2" 629*4882a593Smuzhiyun A2 = "Y" 630*4882a593Smuzhiyun 631*4882a593SmuzhiyunIn this case, after all the parsing is complete, BitBake expands 632*4882a593Smuzhiyun``${B}`` into "2". This expansion causes ``A2``, which was set to "Y" 633*4882a593Smuzhiyunbefore the expansion, to become "X". 634*4882a593Smuzhiyun 635*4882a593Smuzhiyun.. _variable-interaction-worked-examples: 636*4882a593Smuzhiyun 637*4882a593SmuzhiyunExamples 638*4882a593Smuzhiyun-------- 639*4882a593Smuzhiyun 640*4882a593SmuzhiyunDespite the previous explanations that show the different forms of 641*4882a593Smuzhiyunvariable definitions, it can be hard to work out exactly what happens 642*4882a593Smuzhiyunwhen variable operators, conditional overrides, and unconditional 643*4882a593Smuzhiyunoverrides are combined. This section presents some common scenarios 644*4882a593Smuzhiyunalong with explanations for variable interactions that typically confuse 645*4882a593Smuzhiyunusers. 646*4882a593Smuzhiyun 647*4882a593SmuzhiyunThere is often confusion concerning the order in which overrides and 648*4882a593Smuzhiyunvarious "append" operators take effect. Recall that an append or prepend 649*4882a593Smuzhiyunoperation using ":append" and ":prepend" does not result in an immediate 650*4882a593Smuzhiyunassignment as would "+=", ".=", "=+", or "=.". Consider the following 651*4882a593Smuzhiyunexample:: 652*4882a593Smuzhiyun 653*4882a593Smuzhiyun OVERRIDES = "foo" 654*4882a593Smuzhiyun A = "Z" 655*4882a593Smuzhiyun A:foo:append = "X" 656*4882a593Smuzhiyun 657*4882a593SmuzhiyunFor this case, 658*4882a593Smuzhiyun``A`` is unconditionally set to "Z" and "X" is unconditionally and 659*4882a593Smuzhiyunimmediately appended to the variable ``A:foo``. Because overrides have 660*4882a593Smuzhiyunnot been applied yet, ``A:foo`` is set to "X" due to the append and 661*4882a593Smuzhiyun``A`` simply equals "Z". 662*4882a593Smuzhiyun 663*4882a593SmuzhiyunApplying overrides, however, changes things. Since "foo" is listed in 664*4882a593Smuzhiyun:term:`OVERRIDES`, the conditional variable ``A`` is replaced with the "foo" 665*4882a593Smuzhiyunversion, which is equal to "X". So effectively, ``A:foo`` replaces 666*4882a593Smuzhiyun``A``. 667*4882a593Smuzhiyun 668*4882a593SmuzhiyunThis next example changes the order of the override and the append:: 669*4882a593Smuzhiyun 670*4882a593Smuzhiyun OVERRIDES = "foo" 671*4882a593Smuzhiyun A = "Z" 672*4882a593Smuzhiyun A:append:foo = "X" 673*4882a593Smuzhiyun 674*4882a593SmuzhiyunFor this case, before 675*4882a593Smuzhiyunoverrides are handled, ``A`` is set to "Z" and ``A:append:foo`` is set 676*4882a593Smuzhiyunto "X". Once the override for "foo" is applied, however, ``A`` gets 677*4882a593Smuzhiyunappended with "X". Consequently, ``A`` becomes "ZX". Notice that spaces 678*4882a593Smuzhiyunare not appended. 679*4882a593Smuzhiyun 680*4882a593SmuzhiyunThis next example has the order of the appends and overrides reversed 681*4882a593Smuzhiyunback as in the first example:: 682*4882a593Smuzhiyun 683*4882a593Smuzhiyun OVERRIDES = "foo" 684*4882a593Smuzhiyun A = "Y" 685*4882a593Smuzhiyun A:foo:append = "Z" 686*4882a593Smuzhiyun A:foo:append = "X" 687*4882a593Smuzhiyun 688*4882a593SmuzhiyunFor this case, before any overrides are resolved, 689*4882a593Smuzhiyun``A`` is set to "Y" using an immediate assignment. After this immediate 690*4882a593Smuzhiyunassignment, ``A:foo`` is set to "Z", and then further appended with "X" 691*4882a593Smuzhiyunleaving the variable set to "ZX". Finally, applying the override for 692*4882a593Smuzhiyun"foo" results in the conditional variable ``A`` becoming "ZX" (i.e. 693*4882a593Smuzhiyun``A`` is replaced with ``A:foo``). 694*4882a593Smuzhiyun 695*4882a593SmuzhiyunThis final example mixes in some varying operators:: 696*4882a593Smuzhiyun 697*4882a593Smuzhiyun A = "1" 698*4882a593Smuzhiyun A:append = "2" 699*4882a593Smuzhiyun A:append = "3" 700*4882a593Smuzhiyun A += "4" 701*4882a593Smuzhiyun A .= "5" 702*4882a593Smuzhiyun 703*4882a593SmuzhiyunFor this case, the type of append 704*4882a593Smuzhiyunoperators are affecting the order of assignments as BitBake passes 705*4882a593Smuzhiyunthrough the code multiple times. Initially, ``A`` is set to "1 45" 706*4882a593Smuzhiyunbecause of the three statements that use immediate operators. After 707*4882a593Smuzhiyunthese assignments are made, BitBake applies the ":append" operations. 708*4882a593SmuzhiyunThose operations result in ``A`` becoming "1 4523". 709*4882a593Smuzhiyun 710*4882a593SmuzhiyunSharing Functionality 711*4882a593Smuzhiyun===================== 712*4882a593Smuzhiyun 713*4882a593SmuzhiyunBitBake allows for metadata sharing through include files (``.inc``) and 714*4882a593Smuzhiyunclass files (``.bbclass``). For example, suppose you have a piece of 715*4882a593Smuzhiyuncommon functionality such as a task definition that you want to share 716*4882a593Smuzhiyunbetween more than one recipe. In this case, creating a ``.bbclass`` file 717*4882a593Smuzhiyunthat contains the common functionality and then using the ``inherit`` 718*4882a593Smuzhiyundirective in your recipes to inherit the class would be a common way to 719*4882a593Smuzhiyunshare the task. 720*4882a593Smuzhiyun 721*4882a593SmuzhiyunThis section presents the mechanisms BitBake provides to allow you to 722*4882a593Smuzhiyunshare functionality between recipes. Specifically, the mechanisms 723*4882a593Smuzhiyuninclude ``include``, ``inherit``, :term:`INHERIT`, and ``require`` 724*4882a593Smuzhiyundirectives. 725*4882a593Smuzhiyun 726*4882a593SmuzhiyunLocating Include and Class Files 727*4882a593Smuzhiyun-------------------------------- 728*4882a593Smuzhiyun 729*4882a593SmuzhiyunBitBake uses the :term:`BBPATH` variable to locate 730*4882a593Smuzhiyunneeded include and class files. Additionally, BitBake searches the 731*4882a593Smuzhiyuncurrent directory for ``include`` and ``require`` directives. 732*4882a593Smuzhiyun 733*4882a593Smuzhiyun.. note:: 734*4882a593Smuzhiyun 735*4882a593Smuzhiyun The BBPATH variable is analogous to the environment variable PATH . 736*4882a593Smuzhiyun 737*4882a593SmuzhiyunIn order for include and class files to be found by BitBake, they need 738*4882a593Smuzhiyunto be located in a "classes" subdirectory that can be found in 739*4882a593Smuzhiyun:term:`BBPATH`. 740*4882a593Smuzhiyun 741*4882a593Smuzhiyun``inherit`` Directive 742*4882a593Smuzhiyun--------------------- 743*4882a593Smuzhiyun 744*4882a593SmuzhiyunWhen writing a recipe or class file, you can use the ``inherit`` 745*4882a593Smuzhiyundirective to inherit the functionality of a class (``.bbclass``). 746*4882a593SmuzhiyunBitBake only supports this directive when used within recipe and class 747*4882a593Smuzhiyunfiles (i.e. ``.bb`` and ``.bbclass``). 748*4882a593Smuzhiyun 749*4882a593SmuzhiyunThe ``inherit`` directive is a rudimentary means of specifying 750*4882a593Smuzhiyunfunctionality contained in class files that your recipes require. For 751*4882a593Smuzhiyunexample, you can easily abstract out the tasks involved in building a 752*4882a593Smuzhiyunpackage that uses Autoconf and Automake and put those tasks into a class 753*4882a593Smuzhiyunfile and then have your recipe inherit that class file. 754*4882a593Smuzhiyun 755*4882a593SmuzhiyunAs an example, your recipes could use the following directive to inherit 756*4882a593Smuzhiyunan ``autotools.bbclass`` file. The class file would contain common 757*4882a593Smuzhiyunfunctionality for using Autotools that could be shared across recipes:: 758*4882a593Smuzhiyun 759*4882a593Smuzhiyun inherit autotools 760*4882a593Smuzhiyun 761*4882a593SmuzhiyunIn this case, BitBake would search for the directory 762*4882a593Smuzhiyun``classes/autotools.bbclass`` in :term:`BBPATH`. 763*4882a593Smuzhiyun 764*4882a593Smuzhiyun.. note:: 765*4882a593Smuzhiyun 766*4882a593Smuzhiyun You can override any values and functions of the inherited class 767*4882a593Smuzhiyun within your recipe by doing so after the "inherit" statement. 768*4882a593Smuzhiyun 769*4882a593SmuzhiyunIf you want to use the directive to inherit multiple classes, separate 770*4882a593Smuzhiyunthem with spaces. The following example shows how to inherit both the 771*4882a593Smuzhiyun``buildhistory`` and ``rm_work`` classes:: 772*4882a593Smuzhiyun 773*4882a593Smuzhiyun inherit buildhistory rm_work 774*4882a593Smuzhiyun 775*4882a593SmuzhiyunAn advantage with the inherit directive as compared to both the 776*4882a593Smuzhiyun:ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>` and :ref:`require <bitbake-user-manual/bitbake-user-manual-metadata:\`\`require\`\` directive>` 777*4882a593Smuzhiyundirectives is that you can inherit class files conditionally. You can 778*4882a593Smuzhiyunaccomplish this by using a variable expression after the ``inherit`` 779*4882a593Smuzhiyunstatement. Here is an example:: 780*4882a593Smuzhiyun 781*4882a593Smuzhiyun inherit ${VARNAME} 782*4882a593Smuzhiyun 783*4882a593SmuzhiyunIf ``VARNAME`` is 784*4882a593Smuzhiyungoing to be set, it needs to be set before the ``inherit`` statement is 785*4882a593Smuzhiyunparsed. One way to achieve a conditional inherit in this case is to use 786*4882a593Smuzhiyunoverrides:: 787*4882a593Smuzhiyun 788*4882a593Smuzhiyun VARIABLE = "" 789*4882a593Smuzhiyun VARIABLE:someoverride = "myclass" 790*4882a593Smuzhiyun 791*4882a593SmuzhiyunAnother method is by using anonymous Python. Here is an example:: 792*4882a593Smuzhiyun 793*4882a593Smuzhiyun python () { 794*4882a593Smuzhiyun if condition == value: 795*4882a593Smuzhiyun d.setVar('VARIABLE', 'myclass') 796*4882a593Smuzhiyun else: 797*4882a593Smuzhiyun d.setVar('VARIABLE', '') 798*4882a593Smuzhiyun } 799*4882a593Smuzhiyun 800*4882a593SmuzhiyunAlternatively, you could use an in-line Python expression in the 801*4882a593Smuzhiyunfollowing form:: 802*4882a593Smuzhiyun 803*4882a593Smuzhiyun inherit ${@'classname' if condition else ''} 804*4882a593Smuzhiyun inherit ${@functionname(params)} 805*4882a593Smuzhiyun 806*4882a593SmuzhiyunIn all cases, if the expression evaluates to an 807*4882a593Smuzhiyunempty string, the statement does not trigger a syntax error because it 808*4882a593Smuzhiyunbecomes a no-op. 809*4882a593Smuzhiyun 810*4882a593Smuzhiyun``include`` Directive 811*4882a593Smuzhiyun--------------------- 812*4882a593Smuzhiyun 813*4882a593SmuzhiyunBitBake understands the ``include`` directive. This directive causes 814*4882a593SmuzhiyunBitBake to parse whatever file you specify, and to insert that file at 815*4882a593Smuzhiyunthat location. The directive is much like its equivalent in Make except 816*4882a593Smuzhiyunthat if the path specified on the include line is a relative path, 817*4882a593SmuzhiyunBitBake locates the first file it can find within :term:`BBPATH`. 818*4882a593Smuzhiyun 819*4882a593SmuzhiyunThe include directive is a more generic method of including 820*4882a593Smuzhiyunfunctionality as compared to the :ref:`inherit <bitbake-user-manual/bitbake-user-manual-metadata:\`\`inherit\`\` directive>` 821*4882a593Smuzhiyundirective, which is restricted to class (i.e. ``.bbclass``) files. The 822*4882a593Smuzhiyuninclude directive is applicable for any other kind of shared or 823*4882a593Smuzhiyunencapsulated functionality or configuration that does not suit a 824*4882a593Smuzhiyun``.bbclass`` file. 825*4882a593Smuzhiyun 826*4882a593SmuzhiyunAs an example, suppose you needed a recipe to include some self-test 827*4882a593Smuzhiyundefinitions:: 828*4882a593Smuzhiyun 829*4882a593Smuzhiyun include test_defs.inc 830*4882a593Smuzhiyun 831*4882a593Smuzhiyun.. note:: 832*4882a593Smuzhiyun 833*4882a593Smuzhiyun The include directive does not produce an error when the file cannot be 834*4882a593Smuzhiyun found. Consequently, it is recommended that if the file you are including is 835*4882a593Smuzhiyun expected to exist, you should use :ref:`require <require-inclusion>` instead 836*4882a593Smuzhiyun of include . Doing so makes sure that an error is produced if the file cannot 837*4882a593Smuzhiyun be found. 838*4882a593Smuzhiyun 839*4882a593Smuzhiyun.. _require-inclusion: 840*4882a593Smuzhiyun 841*4882a593Smuzhiyun``require`` Directive 842*4882a593Smuzhiyun--------------------- 843*4882a593Smuzhiyun 844*4882a593SmuzhiyunBitBake understands the ``require`` directive. This directive behaves 845*4882a593Smuzhiyunjust like the ``include`` directive with the exception that BitBake 846*4882a593Smuzhiyunraises a parsing error if the file to be included cannot be found. Thus, 847*4882a593Smuzhiyunany file you require is inserted into the file that is being parsed at 848*4882a593Smuzhiyunthe location of the directive. 849*4882a593Smuzhiyun 850*4882a593SmuzhiyunThe require directive, like the include directive previously described, 851*4882a593Smuzhiyunis a more generic method of including functionality as compared to the 852*4882a593Smuzhiyun:ref:`inherit <bitbake-user-manual/bitbake-user-manual-metadata:\`\`inherit\`\` directive>` directive, which is restricted to class 853*4882a593Smuzhiyun(i.e. ``.bbclass``) files. The require directive is applicable for any 854*4882a593Smuzhiyunother kind of shared or encapsulated functionality or configuration that 855*4882a593Smuzhiyundoes not suit a ``.bbclass`` file. 856*4882a593Smuzhiyun 857*4882a593SmuzhiyunSimilar to how BitBake handles :ref:`include <bitbake-user-manual/bitbake-user-manual-metadata:\`\`include\`\` directive>`, if 858*4882a593Smuzhiyunthe path specified on the require line is a relative path, BitBake 859*4882a593Smuzhiyunlocates the first file it can find within :term:`BBPATH`. 860*4882a593Smuzhiyun 861*4882a593SmuzhiyunAs an example, suppose you have two versions of a recipe (e.g. 862*4882a593Smuzhiyun``foo_1.2.2.bb`` and ``foo_2.0.0.bb``) where each version contains some 863*4882a593Smuzhiyunidentical functionality that could be shared. You could create an 864*4882a593Smuzhiyuninclude file named ``foo.inc`` that contains the common definitions 865*4882a593Smuzhiyunneeded to build "foo". You need to be sure ``foo.inc`` is located in the 866*4882a593Smuzhiyunsame directory as your two recipe files as well. Once these conditions 867*4882a593Smuzhiyunare set up, you can share the functionality using a ``require`` 868*4882a593Smuzhiyundirective from within each recipe:: 869*4882a593Smuzhiyun 870*4882a593Smuzhiyun require foo.inc 871*4882a593Smuzhiyun 872*4882a593Smuzhiyun``INHERIT`` Configuration Directive 873*4882a593Smuzhiyun----------------------------------- 874*4882a593Smuzhiyun 875*4882a593SmuzhiyunWhen creating a configuration file (``.conf``), you can use the 876*4882a593Smuzhiyun:term:`INHERIT` configuration directive to inherit a 877*4882a593Smuzhiyunclass. BitBake only supports this directive when used within a 878*4882a593Smuzhiyunconfiguration file. 879*4882a593Smuzhiyun 880*4882a593SmuzhiyunAs an example, suppose you needed to inherit a class file called 881*4882a593Smuzhiyun``abc.bbclass`` from a configuration file as follows:: 882*4882a593Smuzhiyun 883*4882a593Smuzhiyun INHERIT += "abc" 884*4882a593Smuzhiyun 885*4882a593SmuzhiyunThis configuration directive causes the named class to be inherited at 886*4882a593Smuzhiyunthe point of the directive during parsing. As with the ``inherit`` 887*4882a593Smuzhiyundirective, the ``.bbclass`` file must be located in a "classes" 888*4882a593Smuzhiyunsubdirectory in one of the directories specified in :term:`BBPATH`. 889*4882a593Smuzhiyun 890*4882a593Smuzhiyun.. note:: 891*4882a593Smuzhiyun 892*4882a593Smuzhiyun Because .conf files are parsed first during BitBake's execution, using 893*4882a593Smuzhiyun INHERIT to inherit a class effectively inherits the class globally (i.e. for 894*4882a593Smuzhiyun all recipes). 895*4882a593Smuzhiyun 896*4882a593SmuzhiyunIf you want to use the directive to inherit multiple classes, you can 897*4882a593Smuzhiyunprovide them on the same line in the ``local.conf`` file. Use spaces to 898*4882a593Smuzhiyunseparate the classes. The following example shows how to inherit both 899*4882a593Smuzhiyunthe ``autotools`` and ``pkgconfig`` classes:: 900*4882a593Smuzhiyun 901*4882a593Smuzhiyun INHERIT += "autotools pkgconfig" 902*4882a593Smuzhiyun 903*4882a593SmuzhiyunFunctions 904*4882a593Smuzhiyun========= 905*4882a593Smuzhiyun 906*4882a593SmuzhiyunAs with most languages, functions are the building blocks that are used 907*4882a593Smuzhiyunto build up operations into tasks. BitBake supports these types of 908*4882a593Smuzhiyunfunctions: 909*4882a593Smuzhiyun 910*4882a593Smuzhiyun- *Shell Functions:* Functions written in shell script and executed 911*4882a593Smuzhiyun either directly as functions, tasks, or both. They can also be called 912*4882a593Smuzhiyun by other shell functions. 913*4882a593Smuzhiyun 914*4882a593Smuzhiyun- *BitBake-Style Python Functions:* Functions written in Python and 915*4882a593Smuzhiyun executed by BitBake or other Python functions using 916*4882a593Smuzhiyun ``bb.build.exec_func()``. 917*4882a593Smuzhiyun 918*4882a593Smuzhiyun- *Python Functions:* Functions written in Python and executed by 919*4882a593Smuzhiyun Python. 920*4882a593Smuzhiyun 921*4882a593Smuzhiyun- *Anonymous Python Functions:* Python functions executed automatically 922*4882a593Smuzhiyun during parsing. 923*4882a593Smuzhiyun 924*4882a593SmuzhiyunRegardless of the type of function, you can only define them in class 925*4882a593Smuzhiyun(``.bbclass``) and recipe (``.bb`` or ``.inc``) files. 926*4882a593Smuzhiyun 927*4882a593SmuzhiyunShell Functions 928*4882a593Smuzhiyun--------------- 929*4882a593Smuzhiyun 930*4882a593SmuzhiyunFunctions written in shell script are executed either directly as 931*4882a593Smuzhiyunfunctions, tasks, or both. They can also be called by other shell 932*4882a593Smuzhiyunfunctions. Here is an example shell function definition:: 933*4882a593Smuzhiyun 934*4882a593Smuzhiyun some_function () { 935*4882a593Smuzhiyun echo "Hello World" 936*4882a593Smuzhiyun } 937*4882a593Smuzhiyun 938*4882a593SmuzhiyunWhen you create these types of functions in 939*4882a593Smuzhiyunyour recipe or class files, you need to follow the shell programming 940*4882a593Smuzhiyunrules. The scripts are executed by ``/bin/sh``, which may not be a bash 941*4882a593Smuzhiyunshell but might be something such as ``dash``. You should not use 942*4882a593SmuzhiyunBash-specific script (bashisms). 943*4882a593Smuzhiyun 944*4882a593SmuzhiyunOverrides and override-style operators like ``:append`` and ``:prepend`` 945*4882a593Smuzhiyuncan also be applied to shell functions. Most commonly, this application 946*4882a593Smuzhiyunwould be used in a ``.bbappend`` file to modify functions in the main 947*4882a593Smuzhiyunrecipe. It can also be used to modify functions inherited from classes. 948*4882a593Smuzhiyun 949*4882a593SmuzhiyunAs an example, consider the following:: 950*4882a593Smuzhiyun 951*4882a593Smuzhiyun do_foo() { 952*4882a593Smuzhiyun bbplain first 953*4882a593Smuzhiyun fn 954*4882a593Smuzhiyun } 955*4882a593Smuzhiyun 956*4882a593Smuzhiyun fn:prepend() { 957*4882a593Smuzhiyun bbplain second 958*4882a593Smuzhiyun } 959*4882a593Smuzhiyun 960*4882a593Smuzhiyun fn() { 961*4882a593Smuzhiyun bbplain third 962*4882a593Smuzhiyun } 963*4882a593Smuzhiyun 964*4882a593Smuzhiyun do_foo:append() { 965*4882a593Smuzhiyun bbplain fourth 966*4882a593Smuzhiyun } 967*4882a593Smuzhiyun 968*4882a593SmuzhiyunRunning ``do_foo`` prints the following:: 969*4882a593Smuzhiyun 970*4882a593Smuzhiyun recipename do_foo: first 971*4882a593Smuzhiyun recipename do_foo: second 972*4882a593Smuzhiyun recipename do_foo: third 973*4882a593Smuzhiyun recipename do_foo: fourth 974*4882a593Smuzhiyun 975*4882a593Smuzhiyun.. note:: 976*4882a593Smuzhiyun 977*4882a593Smuzhiyun Overrides and override-style operators can be applied to any shell 978*4882a593Smuzhiyun function, not just :ref:`tasks <bitbake-user-manual/bitbake-user-manual-metadata:tasks>`. 979*4882a593Smuzhiyun 980*4882a593SmuzhiyunYou can use the ``bitbake -e recipename`` command to view the final 981*4882a593Smuzhiyunassembled function after all overrides have been applied. 982*4882a593Smuzhiyun 983*4882a593SmuzhiyunBitBake-Style Python Functions 984*4882a593Smuzhiyun------------------------------ 985*4882a593Smuzhiyun 986*4882a593SmuzhiyunThese functions are written in Python and executed by BitBake or other 987*4882a593SmuzhiyunPython functions using ``bb.build.exec_func()``. 988*4882a593Smuzhiyun 989*4882a593SmuzhiyunAn example BitBake function is:: 990*4882a593Smuzhiyun 991*4882a593Smuzhiyun python some_python_function () { 992*4882a593Smuzhiyun d.setVar("TEXT", "Hello World") 993*4882a593Smuzhiyun print d.getVar("TEXT") 994*4882a593Smuzhiyun } 995*4882a593Smuzhiyun 996*4882a593SmuzhiyunBecause the 997*4882a593SmuzhiyunPython "bb" and "os" modules are already imported, you do not need to 998*4882a593Smuzhiyunimport these modules. Also in these types of functions, the datastore 999*4882a593Smuzhiyun("d") is a global variable and is always automatically available. 1000*4882a593Smuzhiyun 1001*4882a593Smuzhiyun.. note:: 1002*4882a593Smuzhiyun 1003*4882a593Smuzhiyun Variable expressions (e.g. ``${X}`` ) are no longer expanded within Python 1004*4882a593Smuzhiyun functions. This behavior is intentional in order to allow you to freely set 1005*4882a593Smuzhiyun variable values to expandable expressions without having them expanded 1006*4882a593Smuzhiyun prematurely. If you do wish to expand a variable within a Python function, 1007*4882a593Smuzhiyun use ``d.getVar("X")`` . Or, for more complicated expressions, use ``d.expand()``. 1008*4882a593Smuzhiyun 1009*4882a593SmuzhiyunSimilar to shell functions, you can also apply overrides and 1010*4882a593Smuzhiyunoverride-style operators to BitBake-style Python functions. 1011*4882a593Smuzhiyun 1012*4882a593SmuzhiyunAs an example, consider the following:: 1013*4882a593Smuzhiyun 1014*4882a593Smuzhiyun python do_foo:prepend() { 1015*4882a593Smuzhiyun bb.plain("first") 1016*4882a593Smuzhiyun } 1017*4882a593Smuzhiyun 1018*4882a593Smuzhiyun python do_foo() { 1019*4882a593Smuzhiyun bb.plain("second") 1020*4882a593Smuzhiyun } 1021*4882a593Smuzhiyun 1022*4882a593Smuzhiyun python do_foo:append() { 1023*4882a593Smuzhiyun bb.plain("third") 1024*4882a593Smuzhiyun } 1025*4882a593Smuzhiyun 1026*4882a593SmuzhiyunRunning ``do_foo`` prints the following:: 1027*4882a593Smuzhiyun 1028*4882a593Smuzhiyun recipename do_foo: first 1029*4882a593Smuzhiyun recipename do_foo: second 1030*4882a593Smuzhiyun recipename do_foo: third 1031*4882a593Smuzhiyun 1032*4882a593SmuzhiyunYou can use the ``bitbake -e recipename`` command to view 1033*4882a593Smuzhiyunthe final assembled function after all overrides have been applied. 1034*4882a593Smuzhiyun 1035*4882a593SmuzhiyunPython Functions 1036*4882a593Smuzhiyun---------------- 1037*4882a593Smuzhiyun 1038*4882a593SmuzhiyunThese functions are written in Python and are executed by other Python 1039*4882a593Smuzhiyuncode. Examples of Python functions are utility functions that you intend 1040*4882a593Smuzhiyunto call from in-line Python or from within other Python functions. Here 1041*4882a593Smuzhiyunis an example:: 1042*4882a593Smuzhiyun 1043*4882a593Smuzhiyun def get_depends(d): 1044*4882a593Smuzhiyun if d.getVar('SOMECONDITION'): 1045*4882a593Smuzhiyun return "dependencywithcond" 1046*4882a593Smuzhiyun else: 1047*4882a593Smuzhiyun return "dependency" 1048*4882a593Smuzhiyun 1049*4882a593Smuzhiyun SOMECONDITION = "1" 1050*4882a593Smuzhiyun DEPENDS = "${@get_depends(d)}" 1051*4882a593Smuzhiyun 1052*4882a593SmuzhiyunThis would result in :term:`DEPENDS` containing ``dependencywithcond``. 1053*4882a593Smuzhiyun 1054*4882a593SmuzhiyunHere are some things to know about Python functions: 1055*4882a593Smuzhiyun 1056*4882a593Smuzhiyun- Python functions can take parameters. 1057*4882a593Smuzhiyun 1058*4882a593Smuzhiyun- The BitBake datastore is not automatically available. Consequently, 1059*4882a593Smuzhiyun you must pass it in as a parameter to the function. 1060*4882a593Smuzhiyun 1061*4882a593Smuzhiyun- The "bb" and "os" Python modules are automatically available. You do 1062*4882a593Smuzhiyun not need to import them. 1063*4882a593Smuzhiyun 1064*4882a593SmuzhiyunBitBake-Style Python Functions Versus Python Functions 1065*4882a593Smuzhiyun------------------------------------------------------ 1066*4882a593Smuzhiyun 1067*4882a593SmuzhiyunFollowing are some important differences between BitBake-style Python 1068*4882a593Smuzhiyunfunctions and regular Python functions defined with "def": 1069*4882a593Smuzhiyun 1070*4882a593Smuzhiyun- Only BitBake-style Python functions can be :ref:`tasks <bitbake-user-manual/bitbake-user-manual-metadata:tasks>`. 1071*4882a593Smuzhiyun 1072*4882a593Smuzhiyun- Overrides and override-style operators can only be applied to 1073*4882a593Smuzhiyun BitBake-style Python functions. 1074*4882a593Smuzhiyun 1075*4882a593Smuzhiyun- Only regular Python functions can take arguments and return values. 1076*4882a593Smuzhiyun 1077*4882a593Smuzhiyun- :ref:`Variable flags <bitbake-user-manual/bitbake-user-manual-metadata:variable flags>` such as 1078*4882a593Smuzhiyun ``[dirs]``, ``[cleandirs]``, and ``[lockfiles]`` can be used on BitBake-style 1079*4882a593Smuzhiyun Python functions, but not on regular Python functions. 1080*4882a593Smuzhiyun 1081*4882a593Smuzhiyun- BitBake-style Python functions generate a separate 1082*4882a593Smuzhiyun ``${``\ :term:`T`\ ``}/run.``\ function-name\ ``.``\ pid 1083*4882a593Smuzhiyun script that is executed to run the function, and also generate a log 1084*4882a593Smuzhiyun file in ``${T}/log.``\ function-name\ ``.``\ pid if they are executed 1085*4882a593Smuzhiyun as tasks. 1086*4882a593Smuzhiyun 1087*4882a593Smuzhiyun Regular Python functions execute "inline" and do not generate any 1088*4882a593Smuzhiyun files in ``${T}``. 1089*4882a593Smuzhiyun 1090*4882a593Smuzhiyun- Regular Python functions are called with the usual Python syntax. 1091*4882a593Smuzhiyun BitBake-style Python functions are usually tasks and are called 1092*4882a593Smuzhiyun directly by BitBake, but can also be called manually from Python code 1093*4882a593Smuzhiyun by using the ``bb.build.exec_func()`` function. Here is an example:: 1094*4882a593Smuzhiyun 1095*4882a593Smuzhiyun bb.build.exec_func("my_bitbake_style_function", d) 1096*4882a593Smuzhiyun 1097*4882a593Smuzhiyun .. note:: 1098*4882a593Smuzhiyun 1099*4882a593Smuzhiyun ``bb.build.exec_func()`` can also be used to run shell functions from Python 1100*4882a593Smuzhiyun code. If you want to run a shell function before a Python function within 1101*4882a593Smuzhiyun the same task, then you can use a parent helper Python function that 1102*4882a593Smuzhiyun starts by running the shell function with ``bb.build.exec_func()`` and then 1103*4882a593Smuzhiyun runs the Python code. 1104*4882a593Smuzhiyun 1105*4882a593Smuzhiyun To detect errors from functions executed with 1106*4882a593Smuzhiyun ``bb.build.exec_func()``, you can catch the ``bb.build.FuncFailed`` 1107*4882a593Smuzhiyun exception. 1108*4882a593Smuzhiyun 1109*4882a593Smuzhiyun .. note:: 1110*4882a593Smuzhiyun 1111*4882a593Smuzhiyun Functions in metadata (recipes and classes) should not themselves raise 1112*4882a593Smuzhiyun ``bb.build.FuncFailed``. Rather, ``bb.build.FuncFailed`` should be viewed as a 1113*4882a593Smuzhiyun general indicator that the called function failed by raising an 1114*4882a593Smuzhiyun exception. For example, an exception raised by ``bb.fatal()`` will be caught 1115*4882a593Smuzhiyun inside ``bb.build.exec_func()``, and a ``bb.build.FuncFailed`` will be raised in 1116*4882a593Smuzhiyun response. 1117*4882a593Smuzhiyun 1118*4882a593SmuzhiyunDue to their simplicity, you should prefer regular Python functions over 1119*4882a593SmuzhiyunBitBake-style Python functions unless you need a feature specific to 1120*4882a593SmuzhiyunBitBake-style Python functions. Regular Python functions in metadata are 1121*4882a593Smuzhiyuna more recent invention than BitBake-style Python functions, and older 1122*4882a593Smuzhiyuncode tends to use ``bb.build.exec_func()`` more often. 1123*4882a593Smuzhiyun 1124*4882a593SmuzhiyunAnonymous Python Functions 1125*4882a593Smuzhiyun-------------------------- 1126*4882a593Smuzhiyun 1127*4882a593SmuzhiyunSometimes it is useful to set variables or perform other operations 1128*4882a593Smuzhiyunprogrammatically during parsing. To do this, you can define special 1129*4882a593SmuzhiyunPython functions, called anonymous Python functions, that run at the end 1130*4882a593Smuzhiyunof parsing. For example, the following conditionally sets a variable 1131*4882a593Smuzhiyunbased on the value of another variable:: 1132*4882a593Smuzhiyun 1133*4882a593Smuzhiyun python () { 1134*4882a593Smuzhiyun if d.getVar('SOMEVAR') == 'value': 1135*4882a593Smuzhiyun d.setVar('ANOTHERVAR', 'value2') 1136*4882a593Smuzhiyun } 1137*4882a593Smuzhiyun 1138*4882a593SmuzhiyunAn equivalent way to mark a function as an anonymous function is to give it 1139*4882a593Smuzhiyunthe name "__anonymous", rather than no name. 1140*4882a593Smuzhiyun 1141*4882a593SmuzhiyunAnonymous Python functions always run at the end of parsing, regardless 1142*4882a593Smuzhiyunof where they are defined. If a recipe contains many anonymous 1143*4882a593Smuzhiyunfunctions, they run in the same order as they are defined within the 1144*4882a593Smuzhiyunrecipe. As an example, consider the following snippet:: 1145*4882a593Smuzhiyun 1146*4882a593Smuzhiyun python () { 1147*4882a593Smuzhiyun d.setVar('FOO', 'foo 2') 1148*4882a593Smuzhiyun } 1149*4882a593Smuzhiyun 1150*4882a593Smuzhiyun FOO = "foo 1" 1151*4882a593Smuzhiyun 1152*4882a593Smuzhiyun python () { 1153*4882a593Smuzhiyun d.appendVar('BAR',' bar 2') 1154*4882a593Smuzhiyun } 1155*4882a593Smuzhiyun 1156*4882a593Smuzhiyun BAR = "bar 1" 1157*4882a593Smuzhiyun 1158*4882a593SmuzhiyunThe previous example is conceptually 1159*4882a593Smuzhiyunequivalent to the following snippet:: 1160*4882a593Smuzhiyun 1161*4882a593Smuzhiyun FOO = "foo 1" 1162*4882a593Smuzhiyun BAR = "bar 1" 1163*4882a593Smuzhiyun FOO = "foo 2" 1164*4882a593Smuzhiyun BAR += "bar 2" 1165*4882a593Smuzhiyun 1166*4882a593Smuzhiyun``FOO`` ends up with the value "foo 2", and 1167*4882a593Smuzhiyun``BAR`` with the value "bar 1 bar 2". Just as in the second snippet, the 1168*4882a593Smuzhiyunvalues set for the variables within the anonymous functions become 1169*4882a593Smuzhiyunavailable to tasks, which always run after parsing. 1170*4882a593Smuzhiyun 1171*4882a593SmuzhiyunOverrides and override-style operators such as "``:append``" are applied 1172*4882a593Smuzhiyunbefore anonymous functions run. In the following example, ``FOO`` ends 1173*4882a593Smuzhiyunup with the value "foo from anonymous":: 1174*4882a593Smuzhiyun 1175*4882a593Smuzhiyun FOO = "foo" 1176*4882a593Smuzhiyun FOO:append = " from outside" 1177*4882a593Smuzhiyun 1178*4882a593Smuzhiyun python () { 1179*4882a593Smuzhiyun d.setVar("FOO", "foo from anonymous") 1180*4882a593Smuzhiyun } 1181*4882a593Smuzhiyun 1182*4882a593SmuzhiyunFor methods 1183*4882a593Smuzhiyunyou can use with anonymous Python functions, see the 1184*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-metadata:functions you can call from within python`" 1185*4882a593Smuzhiyunsection. For a different method to run Python code during parsing, see 1186*4882a593Smuzhiyunthe ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:inline python variable expansion`" section. 1187*4882a593Smuzhiyun 1188*4882a593SmuzhiyunFlexible Inheritance for Class Functions 1189*4882a593Smuzhiyun---------------------------------------- 1190*4882a593Smuzhiyun 1191*4882a593SmuzhiyunThrough coding techniques and the use of ``EXPORT_FUNCTIONS``, BitBake 1192*4882a593Smuzhiyunsupports exporting a function from a class such that the class function 1193*4882a593Smuzhiyunappears as the default implementation of the function, but can still be 1194*4882a593Smuzhiyuncalled if a recipe inheriting the class needs to define its own version 1195*4882a593Smuzhiyunof the function. 1196*4882a593Smuzhiyun 1197*4882a593SmuzhiyunTo understand the benefits of this feature, consider the basic scenario 1198*4882a593Smuzhiyunwhere a class defines a task function and your recipe inherits the 1199*4882a593Smuzhiyunclass. In this basic scenario, your recipe inherits the task function as 1200*4882a593Smuzhiyundefined in the class. If desired, your recipe can add to the start and 1201*4882a593Smuzhiyunend of the function by using the ":prepend" or ":append" operations 1202*4882a593Smuzhiyunrespectively, or it can redefine the function completely. However, if it 1203*4882a593Smuzhiyunredefines the function, there is no means for it to call the class 1204*4882a593Smuzhiyunversion of the function. ``EXPORT_FUNCTIONS`` provides a mechanism that 1205*4882a593Smuzhiyunenables the recipe's version of the function to call the original 1206*4882a593Smuzhiyunversion of the function. 1207*4882a593Smuzhiyun 1208*4882a593SmuzhiyunTo make use of this technique, you need the following things in place: 1209*4882a593Smuzhiyun 1210*4882a593Smuzhiyun- The class needs to define the function as follows:: 1211*4882a593Smuzhiyun 1212*4882a593Smuzhiyun classname_functionname 1213*4882a593Smuzhiyun 1214*4882a593Smuzhiyun For example, if you have a class file 1215*4882a593Smuzhiyun ``bar.bbclass`` and a function named ``do_foo``, the class must 1216*4882a593Smuzhiyun define the function as follows:: 1217*4882a593Smuzhiyun 1218*4882a593Smuzhiyun bar_do_foo 1219*4882a593Smuzhiyun 1220*4882a593Smuzhiyun- The class needs to contain the ``EXPORT_FUNCTIONS`` statement as 1221*4882a593Smuzhiyun follows:: 1222*4882a593Smuzhiyun 1223*4882a593Smuzhiyun EXPORT_FUNCTIONS functionname 1224*4882a593Smuzhiyun 1225*4882a593Smuzhiyun For example, continuing with 1226*4882a593Smuzhiyun the same example, the statement in the ``bar.bbclass`` would be as 1227*4882a593Smuzhiyun follows:: 1228*4882a593Smuzhiyun 1229*4882a593Smuzhiyun EXPORT_FUNCTIONS do_foo 1230*4882a593Smuzhiyun 1231*4882a593Smuzhiyun- You need to call the function appropriately from within your recipe. 1232*4882a593Smuzhiyun Continuing with the same example, if your recipe needs to call the 1233*4882a593Smuzhiyun class version of the function, it should call ``bar_do_foo``. 1234*4882a593Smuzhiyun Assuming ``do_foo`` was a shell function and ``EXPORT_FUNCTIONS`` was 1235*4882a593Smuzhiyun used as above, the recipe's function could conditionally call the 1236*4882a593Smuzhiyun class version of the function as follows:: 1237*4882a593Smuzhiyun 1238*4882a593Smuzhiyun do_foo() { 1239*4882a593Smuzhiyun if [ somecondition ] ; then 1240*4882a593Smuzhiyun bar_do_foo 1241*4882a593Smuzhiyun else 1242*4882a593Smuzhiyun # Do something else 1243*4882a593Smuzhiyun fi 1244*4882a593Smuzhiyun } 1245*4882a593Smuzhiyun 1246*4882a593Smuzhiyun To call your modified version of the function as defined in your recipe, 1247*4882a593Smuzhiyun call it as ``do_foo``. 1248*4882a593Smuzhiyun 1249*4882a593SmuzhiyunWith these conditions met, your single recipe can freely choose between 1250*4882a593Smuzhiyunthe original function as defined in the class file and the modified 1251*4882a593Smuzhiyunfunction in your recipe. If you do not set up these conditions, you are 1252*4882a593Smuzhiyunlimited to using one function or the other. 1253*4882a593Smuzhiyun 1254*4882a593SmuzhiyunTasks 1255*4882a593Smuzhiyun===== 1256*4882a593Smuzhiyun 1257*4882a593SmuzhiyunTasks are BitBake execution units that make up the steps that BitBake 1258*4882a593Smuzhiyuncan run for a given recipe. Tasks are only supported in recipes and 1259*4882a593Smuzhiyunclasses (i.e. in ``.bb`` files and files included or inherited from 1260*4882a593Smuzhiyun``.bb`` files). By convention, tasks have names that start with "do\_". 1261*4882a593Smuzhiyun 1262*4882a593SmuzhiyunPromoting a Function to a Task 1263*4882a593Smuzhiyun------------------------------ 1264*4882a593Smuzhiyun 1265*4882a593SmuzhiyunTasks are either :ref:`shell functions <bitbake-user-manual/bitbake-user-manual-metadata:shell functions>` or 1266*4882a593Smuzhiyun:ref:`BitBake-style Python functions <bitbake-user-manual/bitbake-user-manual-metadata:bitbake-style python functions>` 1267*4882a593Smuzhiyunthat have been promoted to tasks by using the ``addtask`` command. The 1268*4882a593Smuzhiyun``addtask`` command can also optionally describe dependencies between 1269*4882a593Smuzhiyunthe task and other tasks. Here is an example that shows how to define a 1270*4882a593Smuzhiyuntask and declare some dependencies:: 1271*4882a593Smuzhiyun 1272*4882a593Smuzhiyun python do_printdate () { 1273*4882a593Smuzhiyun import time 1274*4882a593Smuzhiyun print time.strftime('%Y%m%d', time.gmtime()) 1275*4882a593Smuzhiyun } 1276*4882a593Smuzhiyun addtask printdate after do_fetch before do_build 1277*4882a593Smuzhiyun 1278*4882a593SmuzhiyunThe first argument to ``addtask`` is the name 1279*4882a593Smuzhiyunof the function to promote to a task. If the name does not start with 1280*4882a593Smuzhiyun"do\_", "do\_" is implicitly added, which enforces the convention that all 1281*4882a593Smuzhiyuntask names start with "do\_". 1282*4882a593Smuzhiyun 1283*4882a593SmuzhiyunIn the previous example, the ``do_printdate`` task becomes a dependency 1284*4882a593Smuzhiyunof the ``do_build`` task, which is the default task (i.e. the task run 1285*4882a593Smuzhiyunby the ``bitbake`` command unless another task is specified explicitly). 1286*4882a593SmuzhiyunAdditionally, the ``do_printdate`` task becomes dependent upon the 1287*4882a593Smuzhiyun``do_fetch`` task. Running the ``do_build`` task results in the 1288*4882a593Smuzhiyun``do_printdate`` task running first. 1289*4882a593Smuzhiyun 1290*4882a593Smuzhiyun.. note:: 1291*4882a593Smuzhiyun 1292*4882a593Smuzhiyun If you try out the previous example, you might see that the 1293*4882a593Smuzhiyun ``do_printdate`` 1294*4882a593Smuzhiyun task is only run the first time you build the recipe with the 1295*4882a593Smuzhiyun ``bitbake`` 1296*4882a593Smuzhiyun command. This is because BitBake considers the task "up-to-date" 1297*4882a593Smuzhiyun after that initial run. If you want to force the task to always be 1298*4882a593Smuzhiyun rerun for experimentation purposes, you can make BitBake always 1299*4882a593Smuzhiyun consider the task "out-of-date" by using the 1300*4882a593Smuzhiyun :ref:`[nostamp] <bitbake-user-manual/bitbake-user-manual-metadata:Variable Flags>` 1301*4882a593Smuzhiyun variable flag, as follows:: 1302*4882a593Smuzhiyun 1303*4882a593Smuzhiyun do_printdate[nostamp] = "1" 1304*4882a593Smuzhiyun 1305*4882a593Smuzhiyun You can also explicitly run the task and provide the 1306*4882a593Smuzhiyun -f option as follows:: 1307*4882a593Smuzhiyun 1308*4882a593Smuzhiyun $ bitbake recipe -c printdate -f 1309*4882a593Smuzhiyun 1310*4882a593Smuzhiyun When manually selecting a task to run with the bitbake ``recipe 1311*4882a593Smuzhiyun -c task`` command, you can omit the "do\_" prefix as part of the task 1312*4882a593Smuzhiyun name. 1313*4882a593Smuzhiyun 1314*4882a593SmuzhiyunYou might wonder about the practical effects of using ``addtask`` 1315*4882a593Smuzhiyunwithout specifying any dependencies as is done in the following example:: 1316*4882a593Smuzhiyun 1317*4882a593Smuzhiyun addtask printdate 1318*4882a593Smuzhiyun 1319*4882a593SmuzhiyunIn this example, assuming dependencies have not been 1320*4882a593Smuzhiyunadded through some other means, the only way to run the task is by 1321*4882a593Smuzhiyunexplicitly selecting it with ``bitbake`` recipe ``-c printdate``. You 1322*4882a593Smuzhiyuncan use the ``do_listtasks`` task to list all tasks defined in a recipe 1323*4882a593Smuzhiyunas shown in the following example:: 1324*4882a593Smuzhiyun 1325*4882a593Smuzhiyun $ bitbake recipe -c listtasks 1326*4882a593Smuzhiyun 1327*4882a593SmuzhiyunFor more information on task dependencies, see the 1328*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-execution:dependencies`" section. 1329*4882a593Smuzhiyun 1330*4882a593SmuzhiyunSee the ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:variable flags`" section for information 1331*4882a593Smuzhiyunon variable flags you can use with tasks. 1332*4882a593Smuzhiyun 1333*4882a593Smuzhiyun.. note:: 1334*4882a593Smuzhiyun 1335*4882a593Smuzhiyun While it's infrequent, it's possible to define multiple tasks as 1336*4882a593Smuzhiyun dependencies when calling ``addtask``. For example, here's a snippet 1337*4882a593Smuzhiyun from the OpenEmbedded class file ``package_tar.bbclass``:: 1338*4882a593Smuzhiyun 1339*4882a593Smuzhiyun addtask package_write_tar before do_build after do_packagedata do_package 1340*4882a593Smuzhiyun 1341*4882a593Smuzhiyun Note how the ``package_write_tar`` task has to wait until both of 1342*4882a593Smuzhiyun ``do_packagedata`` and ``do_package`` complete. 1343*4882a593Smuzhiyun 1344*4882a593SmuzhiyunDeleting a Task 1345*4882a593Smuzhiyun--------------- 1346*4882a593Smuzhiyun 1347*4882a593SmuzhiyunAs well as being able to add tasks, you can delete them. Simply use the 1348*4882a593Smuzhiyun``deltask`` command to delete a task. For example, to delete the example 1349*4882a593Smuzhiyuntask used in the previous sections, you would use:: 1350*4882a593Smuzhiyun 1351*4882a593Smuzhiyun deltask printdate 1352*4882a593Smuzhiyun 1353*4882a593SmuzhiyunIf you delete a task using the ``deltask`` command and the task has 1354*4882a593Smuzhiyundependencies, the dependencies are not reconnected. For example, suppose 1355*4882a593Smuzhiyunyou have three tasks named ``do_a``, ``do_b``, and ``do_c``. 1356*4882a593SmuzhiyunFurthermore, ``do_c`` is dependent on ``do_b``, which in turn is 1357*4882a593Smuzhiyundependent on ``do_a``. Given this scenario, if you use ``deltask`` to 1358*4882a593Smuzhiyundelete ``do_b``, the implicit dependency relationship between ``do_c`` 1359*4882a593Smuzhiyunand ``do_a`` through ``do_b`` no longer exists, and ``do_c`` 1360*4882a593Smuzhiyundependencies are not updated to include ``do_a``. Thus, ``do_c`` is free 1361*4882a593Smuzhiyunto run before ``do_a``. 1362*4882a593Smuzhiyun 1363*4882a593SmuzhiyunIf you want dependencies such as these to remain intact, use the 1364*4882a593Smuzhiyun``[noexec]`` varflag to disable the task instead of using the 1365*4882a593Smuzhiyun``deltask`` command to delete it:: 1366*4882a593Smuzhiyun 1367*4882a593Smuzhiyun do_b[noexec] = "1" 1368*4882a593Smuzhiyun 1369*4882a593SmuzhiyunPassing Information Into the Build Task Environment 1370*4882a593Smuzhiyun--------------------------------------------------- 1371*4882a593Smuzhiyun 1372*4882a593SmuzhiyunWhen running a task, BitBake tightly controls the shell execution 1373*4882a593Smuzhiyunenvironment of the build tasks to make sure unwanted contamination from 1374*4882a593Smuzhiyunthe build machine cannot influence the build. 1375*4882a593Smuzhiyun 1376*4882a593Smuzhiyun.. note:: 1377*4882a593Smuzhiyun 1378*4882a593Smuzhiyun By default, BitBake cleans the environment to include only those 1379*4882a593Smuzhiyun things exported or listed in its passthrough list to ensure that the 1380*4882a593Smuzhiyun build environment is reproducible and consistent. You can prevent this 1381*4882a593Smuzhiyun "cleaning" by setting the :term:`BB_PRESERVE_ENV` variable. 1382*4882a593Smuzhiyun 1383*4882a593SmuzhiyunConsequently, if you do want something to get passed into the build task 1384*4882a593Smuzhiyunenvironment, you must take these two steps: 1385*4882a593Smuzhiyun 1386*4882a593Smuzhiyun#. Tell BitBake to load what you want from the environment into the 1387*4882a593Smuzhiyun datastore. You can do so through the 1388*4882a593Smuzhiyun :term:`BB_ENV_PASSTHROUGH` and 1389*4882a593Smuzhiyun :term:`BB_ENV_PASSTHROUGH_ADDITIONS` variables. For 1390*4882a593Smuzhiyun example, assume you want to prevent the build system from accessing 1391*4882a593Smuzhiyun your ``$HOME/.ccache`` directory. The following command adds the 1392*4882a593Smuzhiyun the environment variable ``CCACHE_DIR`` to BitBake's passthrough 1393*4882a593Smuzhiyun list to allow that variable into the datastore:: 1394*4882a593Smuzhiyun 1395*4882a593Smuzhiyun export BB_ENV_PASSTHROUGH_ADDITIONS="$BB_ENV_PASSTHROUGH_ADDITIONS CCACHE_DIR" 1396*4882a593Smuzhiyun 1397*4882a593Smuzhiyun#. Tell BitBake to export what you have loaded into the datastore to the 1398*4882a593Smuzhiyun task environment of every running task. Loading something from the 1399*4882a593Smuzhiyun environment into the datastore (previous step) only makes it 1400*4882a593Smuzhiyun available in the datastore. To export it to the task environment of 1401*4882a593Smuzhiyun every running task, use a command similar to the following in your 1402*4882a593Smuzhiyun local configuration file ``local.conf`` or your distribution 1403*4882a593Smuzhiyun configuration file:: 1404*4882a593Smuzhiyun 1405*4882a593Smuzhiyun export CCACHE_DIR 1406*4882a593Smuzhiyun 1407*4882a593Smuzhiyun .. note:: 1408*4882a593Smuzhiyun 1409*4882a593Smuzhiyun A side effect of the previous steps is that BitBake records the 1410*4882a593Smuzhiyun variable as a dependency of the build process in things like the 1411*4882a593Smuzhiyun setscene checksums. If doing so results in unnecessary rebuilds of 1412*4882a593Smuzhiyun tasks, you can also flag the variable so that the setscene code 1413*4882a593Smuzhiyun ignores the dependency when it creates checksums. 1414*4882a593Smuzhiyun 1415*4882a593SmuzhiyunSometimes, it is useful to be able to obtain information from the 1416*4882a593Smuzhiyunoriginal execution environment. BitBake saves a copy of the original 1417*4882a593Smuzhiyunenvironment into a special variable named :term:`BB_ORIGENV`. 1418*4882a593Smuzhiyun 1419*4882a593SmuzhiyunThe :term:`BB_ORIGENV` variable returns a datastore object that can be 1420*4882a593Smuzhiyunqueried using the standard datastore operators such as 1421*4882a593Smuzhiyun``getVar(, False)``. The datastore object is useful, for example, to 1422*4882a593Smuzhiyunfind the original ``DISPLAY`` variable. Here is an example:: 1423*4882a593Smuzhiyun 1424*4882a593Smuzhiyun origenv = d.getVar("BB_ORIGENV", False) 1425*4882a593Smuzhiyun bar = origenv.getVar("BAR", False) 1426*4882a593Smuzhiyun 1427*4882a593SmuzhiyunThe previous example returns ``BAR`` from the original execution 1428*4882a593Smuzhiyunenvironment. 1429*4882a593Smuzhiyun 1430*4882a593SmuzhiyunVariable Flags 1431*4882a593Smuzhiyun============== 1432*4882a593Smuzhiyun 1433*4882a593SmuzhiyunVariable flags (varflags) help control a task's functionality and 1434*4882a593Smuzhiyundependencies. BitBake reads and writes varflags to the datastore using 1435*4882a593Smuzhiyunthe following command forms:: 1436*4882a593Smuzhiyun 1437*4882a593Smuzhiyun variable = d.getVarFlags("variable") 1438*4882a593Smuzhiyun self.d.setVarFlags("FOO", {"func": True}) 1439*4882a593Smuzhiyun 1440*4882a593SmuzhiyunWhen working with varflags, the same syntax, with the exception of 1441*4882a593Smuzhiyunoverrides, applies. In other words, you can set, append, and prepend 1442*4882a593Smuzhiyunvarflags just like variables. See the 1443*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-metadata:variable flag syntax`" section for details. 1444*4882a593Smuzhiyun 1445*4882a593SmuzhiyunBitBake has a defined set of varflags available for recipes and classes. 1446*4882a593SmuzhiyunTasks support a number of these flags which control various 1447*4882a593Smuzhiyunfunctionality of the task: 1448*4882a593Smuzhiyun 1449*4882a593Smuzhiyun- ``[cleandirs]``: Empty directories that should be created before 1450*4882a593Smuzhiyun the task runs. Directories that already exist are removed and 1451*4882a593Smuzhiyun recreated to empty them. 1452*4882a593Smuzhiyun 1453*4882a593Smuzhiyun- ``[depends]``: Controls inter-task dependencies. See the 1454*4882a593Smuzhiyun :term:`DEPENDS` variable and the 1455*4882a593Smuzhiyun ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:inter-task 1456*4882a593Smuzhiyun dependencies`" section for more information. 1457*4882a593Smuzhiyun 1458*4882a593Smuzhiyun- ``[deptask]``: Controls task build-time dependencies. See the 1459*4882a593Smuzhiyun :term:`DEPENDS` variable and the ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:build dependencies`" section for more information. 1460*4882a593Smuzhiyun 1461*4882a593Smuzhiyun- ``[dirs]``: Directories that should be created before the task 1462*4882a593Smuzhiyun runs. Directories that already exist are left as is. The last 1463*4882a593Smuzhiyun directory listed is used as the current working directory for the 1464*4882a593Smuzhiyun task. 1465*4882a593Smuzhiyun 1466*4882a593Smuzhiyun- ``[lockfiles]``: Specifies one or more lockfiles to lock while the 1467*4882a593Smuzhiyun task executes. Only one task may hold a lockfile, and any task that 1468*4882a593Smuzhiyun attempts to lock an already locked file will block until the lock is 1469*4882a593Smuzhiyun released. You can use this variable flag to accomplish mutual 1470*4882a593Smuzhiyun exclusion. 1471*4882a593Smuzhiyun 1472*4882a593Smuzhiyun- ``[noexec]``: When set to "1", marks the task as being empty, with 1473*4882a593Smuzhiyun no execution required. You can use the ``[noexec]`` flag to set up 1474*4882a593Smuzhiyun tasks as dependency placeholders, or to disable tasks defined 1475*4882a593Smuzhiyun elsewhere that are not needed in a particular recipe. 1476*4882a593Smuzhiyun 1477*4882a593Smuzhiyun- ``[nostamp]``: When set to "1", tells BitBake to not generate a 1478*4882a593Smuzhiyun stamp file for a task, which implies the task should always be 1479*4882a593Smuzhiyun executed. 1480*4882a593Smuzhiyun 1481*4882a593Smuzhiyun .. caution:: 1482*4882a593Smuzhiyun 1483*4882a593Smuzhiyun Any task that depends (possibly indirectly) on a ``[nostamp]`` task will 1484*4882a593Smuzhiyun always be executed as well. This can cause unnecessary rebuilding if you 1485*4882a593Smuzhiyun are not careful. 1486*4882a593Smuzhiyun 1487*4882a593Smuzhiyun- ``[number_threads]``: Limits tasks to a specific number of 1488*4882a593Smuzhiyun simultaneous threads during execution. This varflag is useful when 1489*4882a593Smuzhiyun your build host has a large number of cores but certain tasks need to 1490*4882a593Smuzhiyun be rate-limited due to various kinds of resource constraints (e.g. to 1491*4882a593Smuzhiyun avoid network throttling). ``number_threads`` works similarly to the 1492*4882a593Smuzhiyun :term:`BB_NUMBER_THREADS` variable but is task-specific. 1493*4882a593Smuzhiyun 1494*4882a593Smuzhiyun Set the value globally. For example, the following makes sure the 1495*4882a593Smuzhiyun ``do_fetch`` task uses no more than two simultaneous execution 1496*4882a593Smuzhiyun threads: do_fetch[number_threads] = "2" 1497*4882a593Smuzhiyun 1498*4882a593Smuzhiyun .. warning:: 1499*4882a593Smuzhiyun 1500*4882a593Smuzhiyun - Setting the varflag in individual recipes rather than globally 1501*4882a593Smuzhiyun can result in unpredictable behavior. 1502*4882a593Smuzhiyun 1503*4882a593Smuzhiyun - Setting the varflag to a value greater than the value used in 1504*4882a593Smuzhiyun the :term:`BB_NUMBER_THREADS` variable causes ``number_threads`` to 1505*4882a593Smuzhiyun have no effect. 1506*4882a593Smuzhiyun 1507*4882a593Smuzhiyun- ``[postfuncs]``: List of functions to call after the completion of 1508*4882a593Smuzhiyun the task. 1509*4882a593Smuzhiyun 1510*4882a593Smuzhiyun- ``[prefuncs]``: List of functions to call before the task executes. 1511*4882a593Smuzhiyun 1512*4882a593Smuzhiyun- ``[rdepends]``: Controls inter-task runtime dependencies. See the 1513*4882a593Smuzhiyun :term:`RDEPENDS` variable, the 1514*4882a593Smuzhiyun :term:`RRECOMMENDS` variable, and the 1515*4882a593Smuzhiyun ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:inter-task dependencies`" section for 1516*4882a593Smuzhiyun more information. 1517*4882a593Smuzhiyun 1518*4882a593Smuzhiyun- ``[rdeptask]``: Controls task runtime dependencies. See the 1519*4882a593Smuzhiyun :term:`RDEPENDS` variable, the 1520*4882a593Smuzhiyun :term:`RRECOMMENDS` variable, and the 1521*4882a593Smuzhiyun ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:runtime dependencies`" section for more 1522*4882a593Smuzhiyun information. 1523*4882a593Smuzhiyun 1524*4882a593Smuzhiyun- ``[recideptask]``: When set in conjunction with ``recrdeptask``, 1525*4882a593Smuzhiyun specifies a task that should be inspected for additional 1526*4882a593Smuzhiyun dependencies. 1527*4882a593Smuzhiyun 1528*4882a593Smuzhiyun- ``[recrdeptask]``: Controls task recursive runtime dependencies. 1529*4882a593Smuzhiyun See the :term:`RDEPENDS` variable, the 1530*4882a593Smuzhiyun :term:`RRECOMMENDS` variable, and the 1531*4882a593Smuzhiyun ":ref:`bitbake-user-manual/bitbake-user-manual-metadata:recursive dependencies`" section for 1532*4882a593Smuzhiyun more information. 1533*4882a593Smuzhiyun 1534*4882a593Smuzhiyun- ``[stamp-extra-info]``: Extra stamp information to append to the 1535*4882a593Smuzhiyun task's stamp. As an example, OpenEmbedded uses this flag to allow 1536*4882a593Smuzhiyun machine-specific tasks. 1537*4882a593Smuzhiyun 1538*4882a593Smuzhiyun- ``[umask]``: The umask to run the task under. 1539*4882a593Smuzhiyun 1540*4882a593SmuzhiyunSeveral varflags are useful for controlling how signatures are 1541*4882a593Smuzhiyuncalculated for variables. For more information on this process, see the 1542*4882a593Smuzhiyun":ref:`bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)`" section. 1543*4882a593Smuzhiyun 1544*4882a593Smuzhiyun- ``[vardeps]``: Specifies a space-separated list of additional 1545*4882a593Smuzhiyun variables to add to a variable's dependencies for the purposes of 1546*4882a593Smuzhiyun calculating its signature. Adding variables to this list is useful, 1547*4882a593Smuzhiyun for example, when a function refers to a variable in a manner that 1548*4882a593Smuzhiyun does not allow BitBake to automatically determine that the variable 1549*4882a593Smuzhiyun is referred to. 1550*4882a593Smuzhiyun 1551*4882a593Smuzhiyun- ``[vardepsexclude]``: Specifies a space-separated list of variables 1552*4882a593Smuzhiyun that should be excluded from a variable's dependencies for the 1553*4882a593Smuzhiyun purposes of calculating its signature. 1554*4882a593Smuzhiyun 1555*4882a593Smuzhiyun- ``[vardepvalue]``: If set, instructs BitBake to ignore the actual 1556*4882a593Smuzhiyun value of the variable and instead use the specified value when 1557*4882a593Smuzhiyun calculating the variable's signature. 1558*4882a593Smuzhiyun 1559*4882a593Smuzhiyun- ``[vardepvalueexclude]``: Specifies a pipe-separated list of 1560*4882a593Smuzhiyun strings to exclude from the variable's value when calculating the 1561*4882a593Smuzhiyun variable's signature. 1562*4882a593Smuzhiyun 1563*4882a593SmuzhiyunEvents 1564*4882a593Smuzhiyun====== 1565*4882a593Smuzhiyun 1566*4882a593SmuzhiyunBitBake allows installation of event handlers within recipe and class 1567*4882a593Smuzhiyunfiles. Events are triggered at certain points during operation, such as 1568*4882a593Smuzhiyunthe beginning of operation against a given recipe (i.e. ``*.bb``), the 1569*4882a593Smuzhiyunstart of a given task, a task failure, a task success, and so forth. The 1570*4882a593Smuzhiyunintent is to make it easy to do things like email notification on build 1571*4882a593Smuzhiyunfailures. 1572*4882a593Smuzhiyun 1573*4882a593SmuzhiyunFollowing is an example event handler that prints the name of the event 1574*4882a593Smuzhiyunand the content of the :term:`FILE` variable:: 1575*4882a593Smuzhiyun 1576*4882a593Smuzhiyun addhandler myclass_eventhandler 1577*4882a593Smuzhiyun python myclass_eventhandler() { 1578*4882a593Smuzhiyun from bb.event import getName 1579*4882a593Smuzhiyun print("The name of the Event is %s" % getName(e)) 1580*4882a593Smuzhiyun print("The file we run for is %s" % d.getVar('FILE')) 1581*4882a593Smuzhiyun } 1582*4882a593Smuzhiyun myclass_eventhandler[eventmask] = "bb.event.BuildStarted 1583*4882a593Smuzhiyun bb.event.BuildCompleted" 1584*4882a593Smuzhiyun 1585*4882a593SmuzhiyunIn the previous example, an eventmask has been 1586*4882a593Smuzhiyunset so that the handler only sees the "BuildStarted" and 1587*4882a593Smuzhiyun"BuildCompleted" events. This event handler gets called every time an 1588*4882a593Smuzhiyunevent matching the eventmask is triggered. A global variable "e" is 1589*4882a593Smuzhiyundefined, which represents the current event. With the ``getName(e)`` 1590*4882a593Smuzhiyunmethod, you can get the name of the triggered event. The global 1591*4882a593Smuzhiyundatastore is available as "d". In legacy code, you might see "e.data" 1592*4882a593Smuzhiyunused to get the datastore. However, realize that "e.data" is deprecated 1593*4882a593Smuzhiyunand you should use "d" going forward. 1594*4882a593Smuzhiyun 1595*4882a593SmuzhiyunThe context of the datastore is appropriate to the event in question. 1596*4882a593SmuzhiyunFor example, "BuildStarted" and "BuildCompleted" events run before any 1597*4882a593Smuzhiyuntasks are executed so would be in the global configuration datastore 1598*4882a593Smuzhiyunnamespace. No recipe-specific metadata exists in that namespace. The 1599*4882a593Smuzhiyun"BuildStarted" and "BuildCompleted" events also run in the main 1600*4882a593Smuzhiyuncooker/server process rather than any worker context. Thus, any changes 1601*4882a593Smuzhiyunmade to the datastore would be seen by other cooker/server events within 1602*4882a593Smuzhiyunthe current build but not seen outside of that build or in any worker 1603*4882a593Smuzhiyuncontext. Task events run in the actual tasks in question consequently 1604*4882a593Smuzhiyunhave recipe-specific and task-specific contents. These events run in the 1605*4882a593Smuzhiyunworker context and are discarded at the end of task execution. 1606*4882a593Smuzhiyun 1607*4882a593SmuzhiyunDuring a standard build, the following common events might occur. The 1608*4882a593Smuzhiyunfollowing events are the most common kinds of events that most metadata 1609*4882a593Smuzhiyunmight have an interest in viewing: 1610*4882a593Smuzhiyun 1611*4882a593Smuzhiyun- ``bb.event.ConfigParsed()``: Fired when the base configuration; which 1612*4882a593Smuzhiyun consists of ``bitbake.conf``, ``base.bbclass`` and any global 1613*4882a593Smuzhiyun :term:`INHERIT` statements; has been parsed. You can see multiple such 1614*4882a593Smuzhiyun events when each of the workers parse the base configuration or if 1615*4882a593Smuzhiyun the server changes configuration and reparses. Any given datastore 1616*4882a593Smuzhiyun only has one such event executed against it, however. If 1617*4882a593Smuzhiyun :term:`BB_INVALIDCONF` is set in the datastore by the event 1618*4882a593Smuzhiyun handler, the configuration is reparsed and a new event triggered, 1619*4882a593Smuzhiyun allowing the metadata to update configuration. 1620*4882a593Smuzhiyun 1621*4882a593Smuzhiyun- ``bb.event.HeartbeatEvent()``: Fires at regular time intervals of one 1622*4882a593Smuzhiyun second. You can configure the interval time using the 1623*4882a593Smuzhiyun ``BB_HEARTBEAT_EVENT`` variable. The event's "time" attribute is the 1624*4882a593Smuzhiyun ``time.time()`` value when the event is triggered. This event is 1625*4882a593Smuzhiyun useful for activities such as system state monitoring. 1626*4882a593Smuzhiyun 1627*4882a593Smuzhiyun- ``bb.event.ParseStarted()``: Fired when BitBake is about to start 1628*4882a593Smuzhiyun parsing recipes. This event's "total" attribute represents the number 1629*4882a593Smuzhiyun of recipes BitBake plans to parse. 1630*4882a593Smuzhiyun 1631*4882a593Smuzhiyun- ``bb.event.ParseProgress()``: Fired as parsing progresses. This 1632*4882a593Smuzhiyun event's "current" attribute is the number of recipes parsed as well 1633*4882a593Smuzhiyun as the "total" attribute. 1634*4882a593Smuzhiyun 1635*4882a593Smuzhiyun- ``bb.event.ParseCompleted()``: Fired when parsing is complete. This 1636*4882a593Smuzhiyun event's "cached", "parsed", "skipped", "virtuals", "masked", and 1637*4882a593Smuzhiyun "errors" attributes provide statistics for the parsing results. 1638*4882a593Smuzhiyun 1639*4882a593Smuzhiyun- ``bb.event.BuildStarted()``: Fired when a new build starts. BitBake 1640*4882a593Smuzhiyun fires multiple "BuildStarted" events (one per configuration) when 1641*4882a593Smuzhiyun multiple configuration (multiconfig) is enabled. 1642*4882a593Smuzhiyun 1643*4882a593Smuzhiyun- ``bb.build.TaskStarted()``: Fired when a task starts. This event's 1644*4882a593Smuzhiyun "taskfile" attribute points to the recipe from which the task 1645*4882a593Smuzhiyun originates. The "taskname" attribute, which is the task's name, 1646*4882a593Smuzhiyun includes the ``do_`` prefix, and the "logfile" attribute point to 1647*4882a593Smuzhiyun where the task's output is stored. Finally, the "time" attribute is 1648*4882a593Smuzhiyun the task's execution start time. 1649*4882a593Smuzhiyun 1650*4882a593Smuzhiyun- ``bb.build.TaskInvalid()``: Fired if BitBake tries to execute a task 1651*4882a593Smuzhiyun that does not exist. 1652*4882a593Smuzhiyun 1653*4882a593Smuzhiyun- ``bb.build.TaskFailedSilent()``: Fired for setscene tasks that fail 1654*4882a593Smuzhiyun and should not be presented to the user verbosely. 1655*4882a593Smuzhiyun 1656*4882a593Smuzhiyun- ``bb.build.TaskFailed()``: Fired for normal tasks that fail. 1657*4882a593Smuzhiyun 1658*4882a593Smuzhiyun- ``bb.build.TaskSucceeded()``: Fired when a task successfully 1659*4882a593Smuzhiyun completes. 1660*4882a593Smuzhiyun 1661*4882a593Smuzhiyun- ``bb.event.BuildCompleted()``: Fired when a build finishes. 1662*4882a593Smuzhiyun 1663*4882a593Smuzhiyun- ``bb.cooker.CookerExit()``: Fired when the BitBake server/cooker 1664*4882a593Smuzhiyun shuts down. This event is usually only seen by the UIs as a sign they 1665*4882a593Smuzhiyun should also shutdown. 1666*4882a593Smuzhiyun 1667*4882a593SmuzhiyunThis next list of example events occur based on specific requests to the 1668*4882a593Smuzhiyunserver. These events are often used to communicate larger pieces of 1669*4882a593Smuzhiyuninformation from the BitBake server to other parts of BitBake such as 1670*4882a593Smuzhiyunuser interfaces: 1671*4882a593Smuzhiyun 1672*4882a593Smuzhiyun- ``bb.event.TreeDataPreparationStarted()`` 1673*4882a593Smuzhiyun- ``bb.event.TreeDataPreparationProgress()`` 1674*4882a593Smuzhiyun- ``bb.event.TreeDataPreparationCompleted()`` 1675*4882a593Smuzhiyun- ``bb.event.DepTreeGenerated()`` 1676*4882a593Smuzhiyun- ``bb.event.CoreBaseFilesFound()`` 1677*4882a593Smuzhiyun- ``bb.event.ConfigFilePathFound()`` 1678*4882a593Smuzhiyun- ``bb.event.FilesMatchingFound()`` 1679*4882a593Smuzhiyun- ``bb.event.ConfigFilesFound()`` 1680*4882a593Smuzhiyun- ``bb.event.TargetsTreeGenerated()`` 1681*4882a593Smuzhiyun 1682*4882a593Smuzhiyun.. _variants-class-extension-mechanism: 1683*4882a593Smuzhiyun 1684*4882a593SmuzhiyunVariants --- Class Extension Mechanism 1685*4882a593Smuzhiyun====================================== 1686*4882a593Smuzhiyun 1687*4882a593SmuzhiyunBitBake supports multiple incarnations of a recipe file via the 1688*4882a593Smuzhiyun:term:`BBCLASSEXTEND` variable. 1689*4882a593Smuzhiyun 1690*4882a593SmuzhiyunThe :term:`BBCLASSEXTEND` variable is a space separated list of classes used 1691*4882a593Smuzhiyunto "extend" the recipe for each variant. Here is an example that results in a 1692*4882a593Smuzhiyunsecond incarnation of the current recipe being available. This second 1693*4882a593Smuzhiyunincarnation will have the "native" class inherited. :: 1694*4882a593Smuzhiyun 1695*4882a593Smuzhiyun BBCLASSEXTEND = "native" 1696*4882a593Smuzhiyun 1697*4882a593Smuzhiyun.. note:: 1698*4882a593Smuzhiyun 1699*4882a593Smuzhiyun The mechanism for this class extension is extremely specific to the 1700*4882a593Smuzhiyun implementation. Usually, the recipe's :term:`PROVIDES` , :term:`PN` , and 1701*4882a593Smuzhiyun :term:`DEPENDS` variables would need to be modified by the extension 1702*4882a593Smuzhiyun class. For specific examples, see the OE-Core native , nativesdk , and 1703*4882a593Smuzhiyun multilib classes. 1704*4882a593Smuzhiyun 1705*4882a593SmuzhiyunDependencies 1706*4882a593Smuzhiyun============ 1707*4882a593Smuzhiyun 1708*4882a593SmuzhiyunTo allow for efficient parallel processing, BitBake handles dependencies 1709*4882a593Smuzhiyunat the task level. Dependencies can exist both between tasks within a 1710*4882a593Smuzhiyunsingle recipe and between tasks in different recipes. Following are 1711*4882a593Smuzhiyunexamples of each: 1712*4882a593Smuzhiyun 1713*4882a593Smuzhiyun- For tasks within a single recipe, a recipe's ``do_configure`` task 1714*4882a593Smuzhiyun might need to complete before its ``do_compile`` task can run. 1715*4882a593Smuzhiyun 1716*4882a593Smuzhiyun- For tasks in different recipes, one recipe's ``do_configure`` task 1717*4882a593Smuzhiyun might require another recipe's ``do_populate_sysroot`` task to finish 1718*4882a593Smuzhiyun first such that the libraries and headers provided by the other 1719*4882a593Smuzhiyun recipe are available. 1720*4882a593Smuzhiyun 1721*4882a593SmuzhiyunThis section describes several ways to declare dependencies. Remember, 1722*4882a593Smuzhiyuneven though dependencies are declared in different ways, they are all 1723*4882a593Smuzhiyunsimply dependencies between tasks. 1724*4882a593Smuzhiyun 1725*4882a593Smuzhiyun.. _dependencies-internal-to-the-bb-file: 1726*4882a593Smuzhiyun 1727*4882a593SmuzhiyunDependencies Internal to the ``.bb`` File 1728*4882a593Smuzhiyun----------------------------------------- 1729*4882a593Smuzhiyun 1730*4882a593SmuzhiyunBitBake uses the ``addtask`` directive to manage dependencies that are 1731*4882a593Smuzhiyuninternal to a given recipe file. You can use the ``addtask`` directive 1732*4882a593Smuzhiyunto indicate when a task is dependent on other tasks or when other tasks 1733*4882a593Smuzhiyundepend on that recipe. Here is an example:: 1734*4882a593Smuzhiyun 1735*4882a593Smuzhiyun addtask printdate after do_fetch before do_build 1736*4882a593Smuzhiyun 1737*4882a593SmuzhiyunIn this example, the ``do_printdate`` task 1738*4882a593Smuzhiyundepends on the completion of the ``do_fetch`` task, and the ``do_build`` 1739*4882a593Smuzhiyuntask depends on the completion of the ``do_printdate`` task. 1740*4882a593Smuzhiyun 1741*4882a593Smuzhiyun.. note:: 1742*4882a593Smuzhiyun 1743*4882a593Smuzhiyun For a task to run, it must be a direct or indirect dependency of some 1744*4882a593Smuzhiyun other task that is scheduled to run. 1745*4882a593Smuzhiyun 1746*4882a593Smuzhiyun For illustration, here are some examples: 1747*4882a593Smuzhiyun 1748*4882a593Smuzhiyun - The directive ``addtask mytask before do_configure`` causes 1749*4882a593Smuzhiyun ``do_mytask`` to run before ``do_configure`` runs. Be aware that 1750*4882a593Smuzhiyun ``do_mytask`` still only runs if its :ref:`input 1751*4882a593Smuzhiyun checksum <bitbake-user-manual/bitbake-user-manual-execution:checksums (signatures)>` has changed since the last time it was 1752*4882a593Smuzhiyun run. Changes to the input checksum of ``do_mytask`` also 1753*4882a593Smuzhiyun indirectly cause ``do_configure`` to run. 1754*4882a593Smuzhiyun 1755*4882a593Smuzhiyun - The directive ``addtask mytask after do_configure`` by itself 1756*4882a593Smuzhiyun never causes ``do_mytask`` to run. ``do_mytask`` can still be run 1757*4882a593Smuzhiyun manually as follows:: 1758*4882a593Smuzhiyun 1759*4882a593Smuzhiyun $ bitbake recipe -c mytask 1760*4882a593Smuzhiyun 1761*4882a593Smuzhiyun Declaring ``do_mytask`` as a dependency of some other task that is 1762*4882a593Smuzhiyun scheduled to run also causes it to run. Regardless, the task runs after 1763*4882a593Smuzhiyun ``do_configure``. 1764*4882a593Smuzhiyun 1765*4882a593SmuzhiyunBuild Dependencies 1766*4882a593Smuzhiyun------------------ 1767*4882a593Smuzhiyun 1768*4882a593SmuzhiyunBitBake uses the :term:`DEPENDS` variable to manage 1769*4882a593Smuzhiyunbuild time dependencies. The ``[deptask]`` varflag for tasks signifies 1770*4882a593Smuzhiyunthe task of each item listed in :term:`DEPENDS` that must complete before 1771*4882a593Smuzhiyunthat task can be executed. Here is an example:: 1772*4882a593Smuzhiyun 1773*4882a593Smuzhiyun do_configure[deptask] = "do_populate_sysroot" 1774*4882a593Smuzhiyun 1775*4882a593SmuzhiyunIn this example, the ``do_populate_sysroot`` task 1776*4882a593Smuzhiyunof each item in :term:`DEPENDS` must complete before ``do_configure`` can 1777*4882a593Smuzhiyunexecute. 1778*4882a593Smuzhiyun 1779*4882a593SmuzhiyunRuntime Dependencies 1780*4882a593Smuzhiyun-------------------- 1781*4882a593Smuzhiyun 1782*4882a593SmuzhiyunBitBake uses the :term:`PACKAGES`, :term:`RDEPENDS`, and :term:`RRECOMMENDS` 1783*4882a593Smuzhiyunvariables to manage runtime dependencies. 1784*4882a593Smuzhiyun 1785*4882a593SmuzhiyunThe :term:`PACKAGES` variable lists runtime packages. Each of those packages 1786*4882a593Smuzhiyuncan have :term:`RDEPENDS` and :term:`RRECOMMENDS` runtime dependencies. The 1787*4882a593Smuzhiyun``[rdeptask]`` flag for tasks is used to signify the task of each item 1788*4882a593Smuzhiyunruntime dependency which must have completed before that task can be 1789*4882a593Smuzhiyunexecuted. :: 1790*4882a593Smuzhiyun 1791*4882a593Smuzhiyun do_package_qa[rdeptask] = "do_packagedata" 1792*4882a593Smuzhiyun 1793*4882a593SmuzhiyunIn the previous 1794*4882a593Smuzhiyunexample, the ``do_packagedata`` task of each item in :term:`RDEPENDS` must 1795*4882a593Smuzhiyunhave completed before ``do_package_qa`` can execute. 1796*4882a593SmuzhiyunAlthough :term:`RDEPENDS` contains entries from the 1797*4882a593Smuzhiyunruntime dependency namespace, BitBake knows how to map them back 1798*4882a593Smuzhiyunto the build-time dependency namespace, in which the tasks are defined. 1799*4882a593Smuzhiyun 1800*4882a593SmuzhiyunRecursive Dependencies 1801*4882a593Smuzhiyun---------------------- 1802*4882a593Smuzhiyun 1803*4882a593SmuzhiyunBitBake uses the ``[recrdeptask]`` flag to manage recursive task 1804*4882a593Smuzhiyundependencies. BitBake looks through the build-time and runtime 1805*4882a593Smuzhiyundependencies of the current recipe, looks through the task's inter-task 1806*4882a593Smuzhiyundependencies, and then adds dependencies for the listed task. Once 1807*4882a593SmuzhiyunBitBake has accomplished this, it recursively works through the 1808*4882a593Smuzhiyundependencies of those tasks. Iterative passes continue until all 1809*4882a593Smuzhiyundependencies are discovered and added. 1810*4882a593Smuzhiyun 1811*4882a593SmuzhiyunThe ``[recrdeptask]`` flag is most commonly used in high-level recipes 1812*4882a593Smuzhiyunthat need to wait for some task to finish "globally". For example, 1813*4882a593Smuzhiyun``image.bbclass`` has the following:: 1814*4882a593Smuzhiyun 1815*4882a593Smuzhiyun do_rootfs[recrdeptask] += "do_packagedata" 1816*4882a593Smuzhiyun 1817*4882a593SmuzhiyunThis statement says that the ``do_packagedata`` task of 1818*4882a593Smuzhiyunthe current recipe and all recipes reachable (by way of dependencies) 1819*4882a593Smuzhiyunfrom the image recipe must run before the ``do_rootfs`` task can run. 1820*4882a593Smuzhiyun 1821*4882a593SmuzhiyunBitBake allows a task to recursively depend on itself by 1822*4882a593Smuzhiyunreferencing itself in the task list:: 1823*4882a593Smuzhiyun 1824*4882a593Smuzhiyun do_a[recrdeptask] = "do_a do_b" 1825*4882a593Smuzhiyun 1826*4882a593SmuzhiyunIn the same way as before, this means that the ``do_a`` 1827*4882a593Smuzhiyunand ``do_b`` tasks of the current recipe and all 1828*4882a593Smuzhiyunrecipes reachable (by way of dependencies) from the recipe 1829*4882a593Smuzhiyunmust run before the ``do_a`` task can run. In this 1830*4882a593Smuzhiyuncase BitBake will ignore the current recipe's ``do_a`` 1831*4882a593Smuzhiyuntask circular dependency on itself. 1832*4882a593Smuzhiyun 1833*4882a593SmuzhiyunInter-Task Dependencies 1834*4882a593Smuzhiyun----------------------- 1835*4882a593Smuzhiyun 1836*4882a593SmuzhiyunBitBake uses the ``[depends]`` flag in a more generic form to manage 1837*4882a593Smuzhiyuninter-task dependencies. This more generic form allows for 1838*4882a593Smuzhiyuninter-dependency checks for specific tasks rather than checks for the 1839*4882a593Smuzhiyundata in :term:`DEPENDS`. Here is an example:: 1840*4882a593Smuzhiyun 1841*4882a593Smuzhiyun do_patch[depends] = "quilt-native:do_populate_sysroot" 1842*4882a593Smuzhiyun 1843*4882a593SmuzhiyunIn this example, the ``do_populate_sysroot`` task of the target ``quilt-native`` 1844*4882a593Smuzhiyunmust have completed before the ``do_patch`` task can execute. 1845*4882a593Smuzhiyun 1846*4882a593SmuzhiyunThe ``[rdepends]`` flag works in a similar way but takes targets in the 1847*4882a593Smuzhiyunruntime namespace instead of the build-time dependency namespace. 1848*4882a593Smuzhiyun 1849*4882a593SmuzhiyunFunctions You Can Call From Within Python 1850*4882a593Smuzhiyun========================================= 1851*4882a593Smuzhiyun 1852*4882a593SmuzhiyunBitBake provides many functions you can call from within Python 1853*4882a593Smuzhiyunfunctions. This section lists the most commonly used functions, and 1854*4882a593Smuzhiyunmentions where to find others. 1855*4882a593Smuzhiyun 1856*4882a593SmuzhiyunFunctions for Accessing Datastore Variables 1857*4882a593Smuzhiyun------------------------------------------- 1858*4882a593Smuzhiyun 1859*4882a593SmuzhiyunIt is often necessary to access variables in the BitBake datastore using 1860*4882a593SmuzhiyunPython functions. The BitBake datastore has an API that allows you this 1861*4882a593Smuzhiyunaccess. Here is a list of available operations: 1862*4882a593Smuzhiyun 1863*4882a593Smuzhiyun.. list-table:: 1864*4882a593Smuzhiyun :widths: auto 1865*4882a593Smuzhiyun :header-rows: 1 1866*4882a593Smuzhiyun 1867*4882a593Smuzhiyun * - *Operation* 1868*4882a593Smuzhiyun - *Description* 1869*4882a593Smuzhiyun * - ``d.getVar("X", expand)`` 1870*4882a593Smuzhiyun - Returns the value of variable "X". Using "expand=True" expands the 1871*4882a593Smuzhiyun value. Returns "None" if the variable "X" does not exist. 1872*4882a593Smuzhiyun * - ``d.setVar("X", "value")`` 1873*4882a593Smuzhiyun - Sets the variable "X" to "value" 1874*4882a593Smuzhiyun * - ``d.appendVar("X", "value")`` 1875*4882a593Smuzhiyun - Adds "value" to the end of the variable "X". Acts like ``d.setVar("X", 1876*4882a593Smuzhiyun "value")`` if the variable "X" does not exist. 1877*4882a593Smuzhiyun * - ``d.prependVar("X", "value")`` 1878*4882a593Smuzhiyun - Adds "value" to the start of the variable "X". Acts like 1879*4882a593Smuzhiyun ``d.setVar("X","value")`` if the variable "X" does not exist. 1880*4882a593Smuzhiyun * - ``d.delVar("X")`` 1881*4882a593Smuzhiyun - Deletes the variable "X" from the datastore. Does nothing if the variable 1882*4882a593Smuzhiyun "X" does not exist. 1883*4882a593Smuzhiyun * - ``d.renameVar("X", "Y")`` 1884*4882a593Smuzhiyun - Renames the variable "X" to "Y". Does nothing if the variable "X" does 1885*4882a593Smuzhiyun not exist. 1886*4882a593Smuzhiyun * - ``d.getVarFlag("X", flag, expand)`` 1887*4882a593Smuzhiyun - Returns the value of variable "X". Using "expand=True" expands the 1888*4882a593Smuzhiyun value. Returns "None" if either the variable "X" or the named flag does 1889*4882a593Smuzhiyun not exist. 1890*4882a593Smuzhiyun * - ``d.setVarFlag("X", flag, "value")`` 1891*4882a593Smuzhiyun - Sets the named flag for variable "X" to "value". 1892*4882a593Smuzhiyun * - ``d.appendVarFlag("X", flag, "value")`` 1893*4882a593Smuzhiyun - Appends "value" to the named flag on the variable "X". Acts like 1894*4882a593Smuzhiyun ``d.setVarFlag("X", flag, "value")`` if the named flag does not exist. 1895*4882a593Smuzhiyun * - ``d.prependVarFlag("X", flag, "value")`` 1896*4882a593Smuzhiyun - Prepends "value" to the named flag on the variable "X". Acts like 1897*4882a593Smuzhiyun ``d.setVarFlag("X", flag, "value")`` if the named flag does not exist. 1898*4882a593Smuzhiyun * - ``d.delVarFlag("X", flag)`` 1899*4882a593Smuzhiyun - Deletes the named flag on the variable "X" from the datastore. 1900*4882a593Smuzhiyun * - ``d.setVarFlags("X", flagsdict)`` 1901*4882a593Smuzhiyun - Sets the flags specified in the ``flagsdict()`` 1902*4882a593Smuzhiyun parameter. ``setVarFlags`` does not clear previous flags. Think of this 1903*4882a593Smuzhiyun operation as ``addVarFlags``. 1904*4882a593Smuzhiyun * - ``d.getVarFlags("X")`` 1905*4882a593Smuzhiyun - Returns a ``flagsdict`` of the flags for the variable "X". Returns "None" 1906*4882a593Smuzhiyun if the variable "X" does not exist. 1907*4882a593Smuzhiyun * - ``d.delVarFlags("X")`` 1908*4882a593Smuzhiyun - Deletes all the flags for the variable "X". Does nothing if the variable 1909*4882a593Smuzhiyun "X" does not exist. 1910*4882a593Smuzhiyun * - ``d.expand(expression)`` 1911*4882a593Smuzhiyun - Expands variable references in the specified string 1912*4882a593Smuzhiyun expression. References to variables that do not exist are left as is. For 1913*4882a593Smuzhiyun example, ``d.expand("foo ${X}")`` expands to the literal string "foo 1914*4882a593Smuzhiyun ${X}" if the variable "X" does not exist. 1915*4882a593Smuzhiyun 1916*4882a593SmuzhiyunOther Functions 1917*4882a593Smuzhiyun--------------- 1918*4882a593Smuzhiyun 1919*4882a593SmuzhiyunYou can find many other functions that can be called from Python by 1920*4882a593Smuzhiyunlooking at the source code of the ``bb`` module, which is in 1921*4882a593Smuzhiyun``bitbake/lib/bb``. For example, ``bitbake/lib/bb/utils.py`` includes 1922*4882a593Smuzhiyunthe commonly used functions ``bb.utils.contains()`` and 1923*4882a593Smuzhiyun``bb.utils.mkdirhier()``, which come with docstrings. 1924*4882a593Smuzhiyun 1925*4882a593SmuzhiyunTask Checksums and Setscene 1926*4882a593Smuzhiyun=========================== 1927*4882a593Smuzhiyun 1928*4882a593SmuzhiyunBitBake uses checksums (or signatures) along with the setscene to 1929*4882a593Smuzhiyundetermine if a task needs to be run. This section describes the process. 1930*4882a593SmuzhiyunTo help understand how BitBake does this, the section assumes an 1931*4882a593SmuzhiyunOpenEmbedded metadata-based example. 1932*4882a593Smuzhiyun 1933*4882a593SmuzhiyunThese checksums are stored in :term:`STAMP`. You can 1934*4882a593Smuzhiyunexamine the checksums using the following BitBake command:: 1935*4882a593Smuzhiyun 1936*4882a593Smuzhiyun $ bitbake-dumpsigs 1937*4882a593Smuzhiyun 1938*4882a593SmuzhiyunThis command returns the signature data in a readable 1939*4882a593Smuzhiyunformat that allows you to examine the inputs used when the OpenEmbedded 1940*4882a593Smuzhiyunbuild system generates signatures. For example, using 1941*4882a593Smuzhiyun``bitbake-dumpsigs`` allows you to examine the ``do_compile`` task's 1942*4882a593Smuzhiyun"sigdata" for a C application (e.g. ``bash``). Running the command also 1943*4882a593Smuzhiyunreveals that the "CC" variable is part of the inputs that are hashed. 1944*4882a593SmuzhiyunAny changes to this variable would invalidate the stamp and cause the 1945*4882a593Smuzhiyun``do_compile`` task to run. 1946*4882a593Smuzhiyun 1947*4882a593SmuzhiyunThe following list describes related variables: 1948*4882a593Smuzhiyun 1949*4882a593Smuzhiyun- :term:`BB_HASHCHECK_FUNCTION`: 1950*4882a593Smuzhiyun Specifies the name of the function to call during the "setscene" part 1951*4882a593Smuzhiyun of the task's execution in order to validate the list of task hashes. 1952*4882a593Smuzhiyun 1953*4882a593Smuzhiyun- :term:`BB_SETSCENE_DEPVALID`: 1954*4882a593Smuzhiyun Specifies a function BitBake calls that determines whether BitBake 1955*4882a593Smuzhiyun requires a setscene dependency to be met. 1956*4882a593Smuzhiyun 1957*4882a593Smuzhiyun- :term:`BB_TASKHASH`: Within an executing task, 1958*4882a593Smuzhiyun this variable holds the hash of the task as returned by the currently 1959*4882a593Smuzhiyun enabled signature generator. 1960*4882a593Smuzhiyun 1961*4882a593Smuzhiyun- :term:`STAMP`: The base path to create stamp files. 1962*4882a593Smuzhiyun 1963*4882a593Smuzhiyun- :term:`STAMPCLEAN`: Again, the base path to 1964*4882a593Smuzhiyun create stamp files but can use wildcards for matching a range of 1965*4882a593Smuzhiyun files for clean operations. 1966*4882a593Smuzhiyun 1967*4882a593SmuzhiyunWildcard Support in Variables 1968*4882a593Smuzhiyun============================= 1969*4882a593Smuzhiyun 1970*4882a593SmuzhiyunSupport for wildcard use in variables varies depending on the context in 1971*4882a593Smuzhiyunwhich it is used. For example, some variables and filenames allow 1972*4882a593Smuzhiyunlimited use of wildcards through the "``%``" and "``*``" characters. 1973*4882a593SmuzhiyunOther variables or names support Python's 1974*4882a593Smuzhiyun`glob <https://docs.python.org/3/library/glob.html>`_ syntax, 1975*4882a593Smuzhiyun`fnmatch <https://docs.python.org/3/library/fnmatch.html#module-fnmatch>`_ 1976*4882a593Smuzhiyunsyntax, or 1977*4882a593Smuzhiyun`Regular Expression (re) <https://docs.python.org/3/library/re.html>`_ 1978*4882a593Smuzhiyunsyntax. 1979*4882a593Smuzhiyun 1980*4882a593SmuzhiyunFor variables that have wildcard suport, the documentation describes 1981*4882a593Smuzhiyunwhich form of wildcard, its use, and its limitations. 1982