Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" |
| 2 | "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> |
| 3 | |
| 4 | <chapter id="bitbake-user-manual-metadata"> |
| 5 | <title>Syntax and Operators</title> |
| 6 | |
| 7 | <para> |
| 8 | Bitbake files have their own syntax. |
| 9 | The syntax has similarities to several |
| 10 | other languages but also has some unique features. |
| 11 | This section describes the available syntax and operators |
| 12 | as well as provides examples. |
| 13 | </para> |
| 14 | |
| 15 | <section id='basic-syntax'> |
| 16 | <title>Basic Syntax</title> |
| 17 | |
| 18 | <para> |
| 19 | This section provides some basic syntax examples. |
| 20 | </para> |
| 21 | |
| 22 | <section id='basic-variable-setting'> |
| 23 | <title>Basic Variable Setting</title> |
| 24 | |
| 25 | <para> |
| 26 | The following example sets <filename>VARIABLE</filename> to |
| 27 | "value". |
| 28 | This assignment occurs immediately as the statement is parsed. |
| 29 | It is a "hard" assignment. |
| 30 | <literallayout class='monospaced'> |
| 31 | VARIABLE = "value" |
| 32 | </literallayout> |
| 33 | As expected, if you include leading or trailing spaces as part of |
| 34 | an assignment, the spaces are retained: |
| 35 | <literallayout class='monospaced'> |
| 36 | VARIABLE = " value" |
| 37 | VARIABLE = "value " |
| 38 | </literallayout> |
| 39 | Setting <filename>VARIABLE</filename> to "" sets it to an empty string, |
| 40 | while setting the variable to " " sets it to a blank space |
| 41 | (i.e. these are not the same values). |
| 42 | <literallayout class='monospaced'> |
| 43 | VARIABLE = "" |
| 44 | VARIABLE = " " |
| 45 | </literallayout> |
| 46 | </para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 47 | |
| 48 | <para> |
| 49 | You can use single quotes instead of double quotes |
| 50 | when setting a variable's value. |
| 51 | Doing so allows you to use values that contain the double |
| 52 | quote character: |
| 53 | <literallayout class='monospaced'> |
| 54 | VARIABLE = 'I have a " in my value' |
| 55 | </literallayout> |
| 56 | <note> |
| 57 | Unlike in Bourne shells, single quotes work identically |
| 58 | to double quotes in all other ways. |
| 59 | They do not suppress variable expansions. |
| 60 | </note> |
| 61 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | </section> |
| 63 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 64 | <section id='modifying-existing-variables'> |
| 65 | <title>Modifying Existing Variables</title> |
| 66 | |
| 67 | <para> |
| 68 | Sometimes you need to modify existing variables. |
| 69 | Following are some cases where you might find you want to |
| 70 | modify an existing variable: |
| 71 | <itemizedlist> |
| 72 | <listitem><para> |
| 73 | Customize a recipe that uses the variable. |
| 74 | </para></listitem> |
| 75 | <listitem><para> |
| 76 | Change a variable's default value used in a |
| 77 | <filename>*.bbclass</filename> file. |
| 78 | </para></listitem> |
| 79 | <listitem><para> |
| 80 | Change the variable in a <filename>*.bbappend</filename> |
| 81 | file to override the variable in the original recipe. |
| 82 | </para></listitem> |
| 83 | <listitem><para> |
| 84 | Change the variable in a configuration file so that the |
| 85 | value overrides an existing configuration. |
| 86 | </para></listitem> |
| 87 | </itemizedlist> |
| 88 | </para> |
| 89 | |
| 90 | <para> |
| 91 | Changing a variable value can sometimes depend on how the |
| 92 | value was originally assigned and also on the desired |
| 93 | intent of the change. |
| 94 | In particular, when you append a value to a variable that |
| 95 | has a default value, the resulting value might not be what |
| 96 | you expect. |
| 97 | In this case, the value you provide might replace the value |
| 98 | rather than append to the default value. |
| 99 | </para> |
| 100 | |
| 101 | <para> |
| 102 | If after you have changed a variable's value and something |
| 103 | unexplained occurs, you can use BitBake to check the actual |
| 104 | value of the suspect variable. |
| 105 | You can make these checks for both configuration and recipe |
| 106 | level changes: |
| 107 | <itemizedlist> |
| 108 | <listitem><para> |
| 109 | For configuration changes, use the following: |
| 110 | <literallayout class='monospaced'> |
| 111 | $ bitbake -e |
| 112 | </literallayout> |
| 113 | This command displays variable values after the |
| 114 | configuration files (i.e. <filename>local.conf</filename>, |
| 115 | <filename>bblayers.conf</filename>, |
| 116 | <filename>bitbake.conf</filename> and so forth) have |
| 117 | been parsed. |
| 118 | <note> |
| 119 | Variables that are exported to the environment are |
| 120 | preceded by the string "export" in the command's |
| 121 | output. |
| 122 | </note> |
| 123 | </para></listitem> |
| 124 | <listitem><para> |
| 125 | For recipe changes, use the following: |
| 126 | <literallayout class='monospaced'> |
| 127 | $ bitbake <replaceable>recipe</replaceable> -e | grep VARIABLE=" |
| 128 | </literallayout> |
| 129 | This command checks to see if the variable actually |
| 130 | makes it into a specific recipe. |
| 131 | </para></listitem> |
| 132 | </itemizedlist> |
| 133 | </para> |
| 134 | </section> |
| 135 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 136 | <section id='line-joining'> |
| 137 | <title>Line Joining</title> |
| 138 | |
| 139 | <para> |
| 140 | Outside of |
| 141 | <link linkend='functions'>functions</link>, BitBake joins |
| 142 | any line ending in a backslash character ("\") |
| 143 | with the following line before parsing statements. |
| 144 | The most common use for the "\" character is to split variable |
| 145 | assignments over multiple lines, as in the following example: |
| 146 | <literallayout class='monospaced'> |
| 147 | FOO = "bar \ |
| 148 | baz \ |
| 149 | qaz" |
| 150 | </literallayout> |
| 151 | Both the "\" character and the newline character |
| 152 | that follow it are removed when joining lines. |
| 153 | Thus, no newline characters end up in the value of |
| 154 | <filename>FOO</filename>. |
| 155 | </para> |
| 156 | |
| 157 | <para> |
| 158 | Consider this additional example where the two |
| 159 | assignments both assign "barbaz" to |
| 160 | <filename>FOO</filename>: |
| 161 | <literallayout class='monospaced'> |
| 162 | FOO = "barbaz" |
| 163 | |
| 164 | FOO = "bar\ |
| 165 | baz" |
| 166 | </literallayout> |
| 167 | <note> |
| 168 | BitBake does not interpret escape sequences like |
| 169 | "\n" in variable values. |
| 170 | For these to have an effect, the value must be passed |
| 171 | to some utility that interprets escape sequences, |
| 172 | such as <filename>printf</filename> or |
| 173 | <filename>echo -n</filename>. |
| 174 | </note> |
| 175 | </para> |
| 176 | </section> |
| 177 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 178 | <section id='variable-expansion'> |
| 179 | <title>Variable Expansion</title> |
| 180 | |
| 181 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 182 | Variables can reference the contents of other variables |
| 183 | using a syntax that is similar to variable expansion in |
| 184 | Bourne shells. |
| 185 | The following assignments |
| 186 | result in A containing "aval" and B evaluating to "preavalpost". |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 187 | <literallayout class='monospaced'> |
| 188 | A = "aval" |
| 189 | B = "pre${A}post" |
| 190 | </literallayout> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 191 | <note> |
| 192 | Unlike in Bourne shells, the curly braces are mandatory: |
| 193 | Only <filename>${FOO}</filename> and not |
| 194 | <filename>$FOO</filename> is recognized as an expansion of |
| 195 | <filename>FOO</filename>. |
| 196 | </note> |
| 197 | The "=" operator does not immediately expand variable |
| 198 | references in the right-hand side. |
| 199 | Instead, expansion is deferred until the variable assigned to |
| 200 | is actually used. |
| 201 | The result depends on the current values of the referenced |
| 202 | variables. |
| 203 | The following example should clarify this behavior: |
| 204 | <literallayout class='monospaced'> |
| 205 | A = "${B} baz" |
| 206 | B = "${C} bar" |
| 207 | C = "foo" |
| 208 | *At this point, ${A} equals "foo bar baz"* |
| 209 | C = "qux" |
| 210 | *At this point, ${A} equals "qux bar baz"* |
| 211 | B = "norf" |
| 212 | *At this point, ${A} equals "norf baz"* |
| 213 | </literallayout> |
| 214 | Contrast this behavior with the |
| 215 | <link linkend='immediate-variable-expansion'>immediate variable expansion</link> |
| 216 | operator (i.e. ":="). |
| 217 | </para> |
| 218 | |
| 219 | <para> |
| 220 | If the variable expansion syntax is used on a variable that |
| 221 | does not exist, the string is kept as is. |
| 222 | For example, given the following assignment, |
| 223 | <filename>BAR</filename> expands to the literal string |
| 224 | "${FOO}" as long as <filename>FOO</filename> does not exist. |
| 225 | <literallayout class='monospaced'> |
| 226 | BAR = "${FOO}" |
| 227 | </literallayout> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | </para> |
| 229 | </section> |
| 230 | |
| 231 | <section id='setting-a-default-value'> |
| 232 | <title>Setting a default value (?=)</title> |
| 233 | |
| 234 | <para> |
| 235 | You can use the "?=" operator to achieve a "softer" assignment |
| 236 | for a variable. |
| 237 | This type of assignment allows you to define a variable if it |
| 238 | is undefined when the statement is parsed, but to leave the |
| 239 | value alone if the variable has a value. |
| 240 | Here is an example: |
| 241 | <literallayout class='monospaced'> |
| 242 | A ?= "aval" |
| 243 | </literallayout> |
| 244 | If <filename>A</filename> is set at the time this statement is parsed, |
| 245 | the variable retains its value. |
| 246 | However, if <filename>A</filename> is not set, |
| 247 | the variable is set to "aval". |
| 248 | <note> |
| 249 | This assignment is immediate. |
| 250 | Consequently, if multiple "?=" assignments |
| 251 | to a single variable exist, the first of those ends up getting |
| 252 | used. |
| 253 | </note> |
| 254 | </para> |
| 255 | </section> |
| 256 | |
| 257 | <section id='setting-a-weak-default-value'> |
| 258 | <title>Setting a weak default value (??=)</title> |
| 259 | |
| 260 | <para> |
| 261 | It is possible to use a "weaker" assignment than in the |
| 262 | previous section by using the "??=" operator. |
| 263 | This assignment behaves identical to "?=" except that the |
| 264 | assignment is made at the end of the parsing process rather |
| 265 | than immediately. |
| 266 | Consequently, when multiple "??=" assignments exist, the last |
| 267 | one is used. |
| 268 | Also, any "=" or "?=" assignment will override the value set with |
| 269 | "??=". |
| 270 | Here is an example: |
| 271 | <literallayout class='monospaced'> |
| 272 | A ??= "somevalue" |
| 273 | A ??= "someothervalue" |
| 274 | </literallayout> |
| 275 | If <filename>A</filename> is set before the above statements are parsed, |
| 276 | the variable retains its value. |
| 277 | If <filename>A</filename> is not set, |
| 278 | the variable is set to "someothervalue". |
| 279 | </para> |
| 280 | |
| 281 | <para> |
| 282 | Again, this assignment is a "lazy" or "weak" assignment |
| 283 | because it does not occur until the end |
| 284 | of the parsing process. |
| 285 | </para> |
| 286 | </section> |
| 287 | |
| 288 | <section id='immediate-variable-expansion'> |
| 289 | <title>Immediate variable expansion (:=)</title> |
| 290 | |
| 291 | <para> |
| 292 | The ":=" operator results in a variable's |
| 293 | contents being expanded immediately, |
| 294 | rather than when the variable is actually used: |
| 295 | <literallayout class='monospaced'> |
| 296 | T = "123" |
| 297 | A := "${B} ${A} test ${T}" |
| 298 | T = "456" |
| 299 | B = "${T} bval" |
| 300 | C = "cval" |
| 301 | C := "${C}append" |
| 302 | </literallayout> |
| 303 | In this example, <filename>A</filename> contains |
| 304 | "test 123" because <filename>${B}</filename> and |
| 305 | <filename>${A}</filename> at the time of parsing are undefined, |
| 306 | which leaves "test 123". |
| 307 | And, the variable <filename>C</filename> |
| 308 | contains "cvalappend" since <filename>${C}</filename> immediately |
| 309 | expands to "cval". |
| 310 | </para> |
| 311 | </section> |
| 312 | |
| 313 | <section id='appending-and-prepending'> |
| 314 | <title>Appending (+=) and prepending (=+) With Spaces</title> |
| 315 | |
| 316 | <para> |
| 317 | Appending and prepending values is common and can be accomplished |
| 318 | using the "+=" and "=+" operators. |
| 319 | These operators insert a space between the current |
| 320 | value and prepended or appended value. |
| 321 | </para> |
| 322 | |
| 323 | <para> |
| 324 | These operators take immediate effect during parsing. |
| 325 | Here are some examples: |
| 326 | <literallayout class='monospaced'> |
| 327 | B = "bval" |
| 328 | B += "additionaldata" |
| 329 | C = "cval" |
| 330 | C =+ "test" |
| 331 | </literallayout> |
| 332 | The variable <filename>B</filename> contains |
| 333 | "bval additionaldata" and <filename>C</filename> |
| 334 | contains "test cval". |
| 335 | </para> |
| 336 | </section> |
| 337 | |
| 338 | <section id='appending-and-prepending-without-spaces'> |
| 339 | <title>Appending (.=) and Prepending (=.) Without Spaces</title> |
| 340 | |
| 341 | <para> |
| 342 | If you want to append or prepend values without an |
| 343 | inserted space, use the ".=" and "=." operators. |
| 344 | </para> |
| 345 | |
| 346 | <para> |
| 347 | These operators take immediate effect during parsing. |
| 348 | Here are some examples: |
| 349 | <literallayout class='monospaced'> |
| 350 | B = "bval" |
| 351 | B .= "additionaldata" |
| 352 | C = "cval" |
| 353 | C =. "test" |
| 354 | </literallayout> |
| 355 | The variable <filename>B</filename> contains |
| 356 | "bvaladditionaldata" and |
| 357 | <filename>C</filename> contains "testcval". |
| 358 | </para> |
| 359 | </section> |
| 360 | |
| 361 | <section id='appending-and-prepending-override-style-syntax'> |
| 362 | <title>Appending and Prepending (Override Style Syntax)</title> |
| 363 | |
| 364 | <para> |
| 365 | You can also append and prepend a variable's value |
| 366 | using an override style syntax. |
| 367 | When you use this syntax, no spaces are inserted. |
| 368 | </para> |
| 369 | |
| 370 | <para> |
| 371 | These operators differ from the ":=", ".=", "=.", "+=", and "=+" |
| 372 | operators in that their effects are deferred |
| 373 | until after parsing completes rather than being immediately |
| 374 | applied. |
| 375 | Here are some examples: |
| 376 | <literallayout class='monospaced'> |
| 377 | B = "bval" |
| 378 | B_append = " additional data" |
| 379 | C = "cval" |
| 380 | C_prepend = "additional data " |
| 381 | D = "dval" |
| 382 | D_append = "additional data" |
| 383 | </literallayout> |
| 384 | The variable <filename>B</filename> becomes |
| 385 | "bval additional data" and <filename>C</filename> becomes |
| 386 | "additional data cval". |
| 387 | The variable <filename>D</filename> becomes |
| 388 | "dvaladditional data". |
| 389 | <note> |
| 390 | You must control all spacing when you use the |
| 391 | override syntax. |
| 392 | </note> |
| 393 | </para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 394 | |
| 395 | <para> |
| 396 | It is also possible to append and prepend to shell |
| 397 | functions and BitBake-style Python functions. |
| 398 | See the |
| 399 | "<link linkend='shell-functions'>Shell Functions</link>" and |
| 400 | "<link linkend='bitbake-style-python-functions'>BitBake-Style Python Functions</link> |
| 401 | sections for examples. |
| 402 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 403 | </section> |
| 404 | |
| 405 | <section id='removing-override-style-syntax'> |
| 406 | <title>Removal (Override Style Syntax)</title> |
| 407 | |
| 408 | <para> |
| 409 | You can remove values from lists using the removal |
| 410 | override style syntax. |
| 411 | Specifying a value for removal causes all occurrences of that |
| 412 | value to be removed from the variable. |
| 413 | </para> |
| 414 | |
| 415 | <para> |
| 416 | When you use this syntax, BitBake expects one or more strings. |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 417 | Surrounding spaces and spacing are preserved. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 418 | Here is an example: |
| 419 | <literallayout class='monospaced'> |
| 420 | FOO = "123 456 789 123456 123 456 123 456" |
| 421 | FOO_remove = "123" |
| 422 | FOO_remove = "456" |
| 423 | FOO2 = "abc def ghi abcdef abc def abc def" |
| 424 | FOO2_remove = "abc def" |
| 425 | </literallayout> |
| 426 | The variable <filename>FOO</filename> becomes |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 427 | " 789 123456 " |
| 428 | and <filename>FOO2</filename> becomes |
| 429 | " ghi abcdef ". |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 430 | </para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 431 | |
| 432 | <para> |
| 433 | Like "_append" and "_prepend", "_remove" |
| 434 | is deferred until after parsing completes. |
| 435 | </para> |
| 436 | </section> |
| 437 | |
| 438 | <section id='override-style-operation-advantages'> |
| 439 | <title>Override Style Operation Advantages</title> |
| 440 | |
| 441 | <para> |
| 442 | An advantage of the override style operations |
| 443 | "_append", "_prepend", and "_remove" as compared to the |
| 444 | "+=" and "=+" operators is that the override style |
| 445 | operators provide guaranteed operations. |
| 446 | For example, consider a class <filename>foo.bbclass</filename> |
| 447 | that needs to add the value "val" to the variable |
| 448 | <filename>FOO</filename>, and a recipe that uses |
| 449 | <filename>foo.bbclass</filename> as follows: |
| 450 | <literallayout class='monospaced'> |
| 451 | inherit foo |
| 452 | |
| 453 | FOO = "initial" |
| 454 | </literallayout> |
| 455 | If <filename>foo.bbclass</filename> uses the "+=" operator, |
| 456 | as follows, then the final value of <filename>FOO</filename> |
| 457 | will be "initial", which is not what is desired: |
| 458 | <literallayout class='monospaced'> |
| 459 | FOO += "val" |
| 460 | </literallayout> |
| 461 | If, on the other hand, <filename>foo.bbclass</filename> |
| 462 | uses the "_append" operator, then the final value of |
| 463 | <filename>FOO</filename> will be "initial val", as intended: |
| 464 | <literallayout class='monospaced'> |
| 465 | FOO_append = " val" |
| 466 | </literallayout> |
| 467 | <note> |
| 468 | It is never necessary to use "+=" together with "_append". |
| 469 | The following sequence of assignments appends "barbaz" to |
| 470 | <filename>FOO</filename>: |
| 471 | <literallayout class='monospaced'> |
| 472 | FOO_append = "bar" |
| 473 | FOO_append = "baz" |
| 474 | </literallayout> |
| 475 | The only effect of changing the second assignment in the |
| 476 | previous example to use "+=" would be to add a space before |
| 477 | "baz" in the appended value (due to how the "+=" operator |
| 478 | works). |
| 479 | </note> |
| 480 | Another advantage of the override style operations is that |
| 481 | you can combine them with other overrides as described in the |
| 482 | "<link linkend='conditional-syntax-overrides'>Conditional Syntax (Overrides)</link>" |
| 483 | section. |
| 484 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 485 | </section> |
| 486 | |
| 487 | <section id='variable-flag-syntax'> |
| 488 | <title>Variable Flag Syntax</title> |
| 489 | |
| 490 | <para> |
| 491 | Variable flags are BitBake's implementation of variable properties |
| 492 | or attributes. |
| 493 | It is a way of tagging extra information onto a variable. |
| 494 | You can find more out about variable flags in general in the |
| 495 | "<link linkend='variable-flags'>Variable Flags</link>" |
| 496 | section. |
| 497 | </para> |
| 498 | |
| 499 | <para> |
| 500 | You can define, append, and prepend values to variable flags. |
| 501 | All the standard syntax operations previously mentioned work |
| 502 | for variable flags except for override style syntax |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 503 | (i.e. "_prepend", "_append", and "_remove"). |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 504 | </para> |
| 505 | |
| 506 | <para> |
| 507 | Here are some examples showing how to set variable flags: |
| 508 | <literallayout class='monospaced'> |
| 509 | FOO[a] = "abc" |
| 510 | FOO[b] = "123" |
| 511 | FOO[a] += "456" |
| 512 | </literallayout> |
| 513 | The variable <filename>FOO</filename> has two flags: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 514 | <filename>[a]</filename> and <filename>[b]</filename>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 515 | The flags are immediately set to "abc" and "123", respectively. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 516 | The <filename>[a]</filename> flag becomes "abc 456". |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 517 | </para> |
| 518 | |
| 519 | <para> |
| 520 | No need exists to pre-define variable flags. |
| 521 | You can simply start using them. |
| 522 | One extremely common application |
| 523 | is to attach some brief documentation to a BitBake variable as |
| 524 | follows: |
| 525 | <literallayout class='monospaced'> |
| 526 | CACHE[doc] = "The directory holding the cache of the metadata." |
| 527 | </literallayout> |
| 528 | </para> |
| 529 | </section> |
| 530 | |
| 531 | <section id='inline-python-variable-expansion'> |
| 532 | <title>Inline Python Variable Expansion</title> |
| 533 | |
| 534 | <para> |
| 535 | You can use inline Python variable expansion to |
| 536 | set variables. |
| 537 | Here is an example: |
| 538 | <literallayout class='monospaced'> |
| 539 | DATE = "${@time.strftime('%Y%m%d',time.gmtime())}" |
| 540 | </literallayout> |
| 541 | This example results in the <filename>DATE</filename> |
| 542 | variable being set to the current date. |
| 543 | </para> |
| 544 | |
| 545 | <para> |
| 546 | Probably the most common use of this feature is to extract |
| 547 | the value of variables from BitBake's internal data dictionary, |
| 548 | <filename>d</filename>. |
| 549 | The following lines select the values of a package name |
| 550 | and its version number, respectively: |
| 551 | <literallayout class='monospaced'> |
| 552 | PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}" |
| 553 | PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}" |
| 554 | </literallayout> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 555 | <note> |
| 556 | Inline Python expressions work just like variable expansions |
| 557 | insofar as the "=" and ":=" operators are concerned. |
| 558 | Given the following assignment, <filename>foo()</filename> |
| 559 | is called each time <filename>FOO</filename> is expanded: |
| 560 | <literallayout class='monospaced'> |
| 561 | FOO = "${@foo()}" |
| 562 | </literallayout> |
| 563 | Contrast this with the following immediate assignment, where |
| 564 | <filename>foo()</filename> is only called once, while the |
| 565 | assignment is parsed: |
| 566 | <literallayout class='monospaced'> |
| 567 | FOO := "${@foo()}" |
| 568 | </literallayout> |
| 569 | </note> |
| 570 | For a different way to set variables with Python code during |
| 571 | parsing, see the |
| 572 | "<link linkend='anonymous-python-functions'>Anonymous Python Functions</link>" |
| 573 | section. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 574 | </para> |
| 575 | </section> |
| 576 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 577 | <section id='unsetting-variables'> |
Brad Bishop | b1114e5 | 2019-02-13 07:56:10 -0500 | [diff] [blame] | 578 | <title>Unsetting variables</title> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 579 | |
| 580 | <para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 581 | It is possible to completely remove a variable or a variable flag |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 582 | from BitBake's internal data dictionary by using the "unset" keyword. |
| 583 | Here is an example: |
| 584 | <literallayout class='monospaced'> |
| 585 | unset DATE |
| 586 | unset do_fetch[noexec] |
| 587 | </literallayout> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 588 | These two statements remove the <filename>DATE</filename> and the |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 589 | <filename>do_fetch[noexec]</filename> flag. |
| 590 | </para> |
| 591 | |
| 592 | </section> |
| 593 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 594 | <section id='providing-pathnames'> |
| 595 | <title>Providing Pathnames</title> |
| 596 | |
| 597 | <para> |
| 598 | When specifying pathnames for use with BitBake, |
| 599 | do not use the tilde ("~") character as a shortcut |
| 600 | for your home directory. |
| 601 | Doing so might cause BitBake to not recognize the |
| 602 | path since BitBake does not expand this character in |
| 603 | the same way a shell would. |
| 604 | </para> |
| 605 | |
| 606 | <para> |
| 607 | Instead, provide a fuller path as the following |
| 608 | example illustrates: |
| 609 | <literallayout class='monospaced'> |
| 610 | BBLAYERS ?= " \ |
| 611 | /home/scott-lenovo/LayerA \ |
| 612 | " |
| 613 | </literallayout> |
| 614 | </para> |
| 615 | </section> |
| 616 | </section> |
| 617 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 618 | <section id='exporting-variables-to-the-environment'> |
| 619 | <title>Exporting Variables to the Environment</title> |
| 620 | |
| 621 | <para> |
| 622 | You can export variables to the environment of running |
| 623 | tasks by using the <filename>export</filename> keyword. |
| 624 | For example, in the following example, the |
| 625 | <filename>do_foo</filename> task prints "value from |
| 626 | the environment" when run: |
| 627 | <literallayout class='monospaced'> |
| 628 | export ENV_VARIABLE |
| 629 | ENV_VARIABLE = "value from the environment" |
| 630 | |
| 631 | do_foo() { |
| 632 | bbplain "$ENV_VARIABLE" |
| 633 | } |
| 634 | </literallayout> |
| 635 | <note> |
| 636 | BitBake does not expand <filename>$ENV_VARIABLE</filename> |
| 637 | in this case because it lacks the obligatory |
| 638 | <filename>{}</filename>. |
| 639 | Rather, <filename>$ENV_VARIABLE</filename> is expanded |
| 640 | by the shell. |
| 641 | </note> |
| 642 | It does not matter whether |
| 643 | <filename>export ENV_VARIABLE</filename> appears before or |
| 644 | after assignments to <filename>ENV_VARIABLE</filename>. |
| 645 | </para> |
| 646 | |
| 647 | <para> |
| 648 | It is also possible to combine <filename>export</filename> |
| 649 | with setting a value for the variable. |
| 650 | Here is an example: |
| 651 | <literallayout class='monospaced'> |
| 652 | export ENV_VARIABLE = "<replaceable>variable-value</replaceable>" |
| 653 | </literallayout> |
| 654 | In the output of <filename>bitbake -e</filename>, variables |
| 655 | that are exported to the environment are preceded by "export". |
| 656 | </para> |
| 657 | |
| 658 | <para> |
| 659 | Among the variables commonly exported to the environment |
| 660 | are <filename>CC</filename> and <filename>CFLAGS</filename>, |
| 661 | which are picked up by many build systems. |
| 662 | </para> |
| 663 | </section> |
| 664 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 665 | <section id='conditional-syntax-overrides'> |
| 666 | <title>Conditional Syntax (Overrides)</title> |
| 667 | |
| 668 | <para> |
| 669 | BitBake uses |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 670 | <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 671 | to control what variables are overridden after BitBake |
| 672 | parses recipes and configuration files. |
| 673 | This section describes how you can use |
| 674 | <filename>OVERRIDES</filename> as conditional metadata, |
| 675 | talks about key expansion in relationship to |
| 676 | <filename>OVERRIDES</filename>, and provides some examples |
| 677 | to help with understanding. |
| 678 | </para> |
| 679 | |
| 680 | <section id='conditional-metadata'> |
| 681 | <title>Conditional Metadata</title> |
| 682 | |
| 683 | <para> |
| 684 | You can use <filename>OVERRIDES</filename> to conditionally select |
| 685 | a specific version of a variable and to conditionally |
| 686 | append or prepend the value of a variable. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 687 | <note> |
| 688 | Overrides can only use lower-case characters. |
| 689 | Additionally, underscores are not permitted in override names |
| 690 | as they are used to separate overrides from each other and |
| 691 | from the variable name. |
| 692 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 693 | <itemizedlist> |
| 694 | <listitem><para><emphasis>Selecting a Variable:</emphasis> |
| 695 | The <filename>OVERRIDES</filename> variable is |
| 696 | a colon-character-separated list that contains items |
| 697 | for which you want to satisfy conditions. |
| 698 | Thus, if you have a variable that is conditional on “arm”, and “arm” |
| 699 | is in <filename>OVERRIDES</filename>, then the “arm”-specific |
| 700 | version of the variable is used rather than the non-conditional |
| 701 | version. |
| 702 | Here is an example: |
| 703 | <literallayout class='monospaced'> |
| 704 | OVERRIDES = "architecture:os:machine" |
| 705 | TEST = "default" |
| 706 | TEST_os = "osspecific" |
| 707 | TEST_nooverride = "othercondvalue" |
| 708 | </literallayout> |
| 709 | In this example, the <filename>OVERRIDES</filename> |
| 710 | variable lists three overrides: |
| 711 | "architecture", "os", and "machine". |
| 712 | The variable <filename>TEST</filename> by itself has a default |
| 713 | value of "default". |
| 714 | You select the os-specific version of the <filename>TEST</filename> |
| 715 | variable by appending the "os" override to the variable |
| 716 | (i.e.<filename>TEST_os</filename>). |
| 717 | </para> |
| 718 | |
| 719 | <para> |
| 720 | To better understand this, consider a practical example |
| 721 | that assumes an OpenEmbedded metadata-based Linux |
| 722 | kernel recipe file. |
| 723 | The following lines from the recipe file first set |
| 724 | the kernel branch variable <filename>KBRANCH</filename> |
| 725 | to a default value, then conditionally override that |
| 726 | value based on the architecture of the build: |
| 727 | <literallayout class='monospaced'> |
| 728 | KBRANCH = "standard/base" |
| 729 | KBRANCH_qemuarm = "standard/arm-versatile-926ejs" |
| 730 | KBRANCH_qemumips = "standard/mti-malta32" |
| 731 | KBRANCH_qemuppc = "standard/qemuppc" |
| 732 | KBRANCH_qemux86 = "standard/common-pc/base" |
| 733 | KBRANCH_qemux86-64 = "standard/common-pc-64/base" |
| 734 | KBRANCH_qemumips64 = "standard/mti-malta64" |
| 735 | </literallayout> |
| 736 | </para></listitem> |
| 737 | <listitem><para><emphasis>Appending and Prepending:</emphasis> |
| 738 | BitBake also supports append and prepend operations to |
| 739 | variable values based on whether a specific item is |
| 740 | listed in <filename>OVERRIDES</filename>. |
| 741 | Here is an example: |
| 742 | <literallayout class='monospaced'> |
| 743 | DEPENDS = "glibc ncurses" |
| 744 | OVERRIDES = "machine:local" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 745 | DEPENDS_append_machine = " libmad" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 746 | </literallayout> |
| 747 | In this example, <filename>DEPENDS</filename> becomes |
| 748 | "glibc ncurses libmad". |
| 749 | </para> |
| 750 | |
| 751 | <para> |
| 752 | Again, using an OpenEmbedded metadata-based |
| 753 | kernel recipe file as an example, the |
| 754 | following lines will conditionally append to the |
| 755 | <filename>KERNEL_FEATURES</filename> variable based |
| 756 | on the architecture: |
| 757 | <literallayout class='monospaced'> |
| 758 | KERNEL_FEATURES_append = " ${KERNEL_EXTRA_FEATURES}" |
| 759 | KERNEL_FEATURES_append_qemux86=" cfg/sound.scc cfg/paravirt_kvm.scc" |
| 760 | KERNEL_FEATURES_append_qemux86-64=" cfg/sound.scc cfg/paravirt_kvm.scc" |
| 761 | </literallayout> |
| 762 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 763 | <listitem><para><emphasis>Setting a Variable for a Single Task:</emphasis> |
| 764 | BitBake supports setting a variable just for the |
| 765 | duration of a single task. |
| 766 | Here is an example: |
| 767 | <literallayout class='monospaced'> |
| 768 | FOO_task-configure = "val 1" |
| 769 | FOO_task-compile = "val 2" |
| 770 | </literallayout> |
| 771 | In the previous example, <filename>FOO</filename> |
| 772 | has the value "val 1" while the |
| 773 | <filename>do_configure</filename> task is executed, |
| 774 | and the value "val 2" while the |
| 775 | <filename>do_compile</filename> task is executed. |
| 776 | </para> |
| 777 | |
| 778 | <para>Internally, this is implemented by prepending |
| 779 | the task (e.g. "task-compile:") to the value of |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 780 | <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 781 | for the local datastore of the <filename>do_compile</filename> |
| 782 | task.</para> |
| 783 | |
| 784 | <para>You can also use this syntax with other combinations |
| 785 | (e.g. "<filename>_prepend</filename>") as shown in the |
| 786 | following example: |
| 787 | <literallayout class='monospaced'> |
| 788 | EXTRA_OEMAKE_prepend_task-compile = "${PARALLEL_MAKE} " |
| 789 | </literallayout> |
| 790 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 791 | </itemizedlist> |
| 792 | </para> |
| 793 | </section> |
| 794 | |
| 795 | <section id='key-expansion'> |
| 796 | <title>Key Expansion</title> |
| 797 | |
| 798 | <para> |
| 799 | Key expansion happens when the BitBake datastore is finalized |
| 800 | just before BitBake expands overrides. |
| 801 | To better understand this, consider the following example: |
| 802 | <literallayout class='monospaced'> |
| 803 | A${B} = "X" |
| 804 | B = "2" |
| 805 | A2 = "Y" |
| 806 | </literallayout> |
| 807 | In this case, after all the parsing is complete, and |
| 808 | before any overrides are handled, BitBake expands |
| 809 | <filename>${B}</filename> into "2". |
| 810 | This expansion causes <filename>A2</filename>, which was |
| 811 | set to "Y" before the expansion, to become "X". |
| 812 | </para> |
| 813 | </section> |
| 814 | |
| 815 | <section id='variable-interaction-worked-examples'> |
| 816 | <title>Examples</title> |
| 817 | |
| 818 | <para> |
| 819 | Despite the previous explanations that show the different forms of |
| 820 | variable definitions, it can be hard to work |
| 821 | out exactly what happens when variable operators, conditional |
| 822 | overrides, and unconditional overrides are combined. |
| 823 | This section presents some common scenarios along |
| 824 | with explanations for variable interactions that |
| 825 | typically confuse users. |
| 826 | </para> |
| 827 | |
| 828 | <para> |
| 829 | There is often confusion concerning the order in which |
| 830 | overrides and various "append" operators take effect. |
| 831 | Recall that an append or prepend operation using "_append" |
| 832 | and "_prepend" does not result in an immediate assignment |
| 833 | as would "+=", ".=", "=+", or "=.". |
| 834 | Consider the following example: |
| 835 | <literallayout class='monospaced'> |
| 836 | OVERRIDES = "foo" |
| 837 | A = "Z" |
| 838 | A_foo_append = "X" |
| 839 | </literallayout> |
| 840 | For this case, <filename>A</filename> is |
| 841 | unconditionally set to "Z" and "X" is |
| 842 | unconditionally and immediately appended to the variable |
| 843 | <filename>A_foo</filename>. |
| 844 | Because overrides have not been applied yet, |
| 845 | <filename>A_foo</filename> is set to "X" due to the append |
| 846 | and <filename>A</filename> simply equals "Z". |
| 847 | </para> |
| 848 | |
| 849 | <para> |
| 850 | Applying overrides, however, changes things. |
| 851 | Since "foo" is listed in <filename>OVERRIDES</filename>, |
| 852 | the conditional variable <filename>A</filename> is replaced |
| 853 | with the "foo" version, which is equal to "X". |
| 854 | So effectively, <filename>A_foo</filename> replaces <filename>A</filename>. |
| 855 | </para> |
| 856 | |
| 857 | <para> |
| 858 | This next example changes the order of the override and |
| 859 | the append: |
| 860 | <literallayout class='monospaced'> |
| 861 | OVERRIDES = "foo" |
| 862 | A = "Z" |
| 863 | A_append_foo = "X" |
| 864 | </literallayout> |
| 865 | For this case, before overrides are handled, |
| 866 | <filename>A</filename> is set to "Z" and <filename>A_append_foo</filename> |
| 867 | is set to "X". |
| 868 | Once the override for "foo" is applied, however, |
| 869 | <filename>A</filename> gets appended with "X". |
| 870 | Consequently, <filename>A</filename> becomes "ZX". |
| 871 | Notice that spaces are not appended. |
| 872 | </para> |
| 873 | |
| 874 | <para> |
| 875 | This next example has the order of the appends and overrides reversed |
| 876 | back as in the first example: |
| 877 | <literallayout class='monospaced'> |
| 878 | OVERRIDES = "foo" |
| 879 | A = "Y" |
| 880 | A_foo_append = "Z" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 881 | A_foo_append = "X" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 882 | </literallayout> |
| 883 | For this case, before any overrides are resolved, |
| 884 | <filename>A</filename> is set to "Y" using an immediate assignment. |
| 885 | After this immediate assignment, <filename>A_foo</filename> is set |
| 886 | to "Z", and then further appended with |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 887 | "X" leaving the variable set to "ZX". |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 888 | Finally, applying the override for "foo" results in the conditional |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 889 | variable <filename>A</filename> becoming "ZX" (i.e. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 890 | <filename>A</filename> is replaced with <filename>A_foo</filename>). |
| 891 | </para> |
| 892 | |
| 893 | <para> |
| 894 | This final example mixes in some varying operators: |
| 895 | <literallayout class='monospaced'> |
| 896 | A = "1" |
| 897 | A_append = "2" |
| 898 | A_append = "3" |
| 899 | A += "4" |
| 900 | A .= "5" |
| 901 | </literallayout> |
| 902 | For this case, the type of append operators are affecting the |
| 903 | order of assignments as BitBake passes through the code |
| 904 | multiple times. |
| 905 | Initially, <filename>A</filename> is set to "1 45" because |
| 906 | of the three statements that use immediate operators. |
| 907 | After these assignments are made, BitBake applies the |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 908 | "_append" operations. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 909 | Those operations result in <filename>A</filename> becoming "1 4523". |
| 910 | </para> |
| 911 | </section> |
| 912 | </section> |
| 913 | |
| 914 | <section id='sharing-functionality'> |
| 915 | <title>Sharing Functionality</title> |
| 916 | |
| 917 | <para> |
| 918 | BitBake allows for metadata sharing through include files |
| 919 | (<filename>.inc</filename>) and class files |
| 920 | (<filename>.bbclass</filename>). |
| 921 | For example, suppose you have a piece of common functionality |
| 922 | such as a task definition that you want to share between |
| 923 | more than one recipe. |
| 924 | In this case, creating a <filename>.bbclass</filename> |
| 925 | file that contains the common functionality and then using |
| 926 | the <filename>inherit</filename> directive in your recipes to |
| 927 | inherit the class would be a common way to share the task. |
| 928 | </para> |
| 929 | |
| 930 | <para> |
| 931 | This section presents the mechanisms BitBake provides to |
| 932 | allow you to share functionality between recipes. |
| 933 | Specifically, the mechanisms include <filename>include</filename>, |
| 934 | <filename>inherit</filename>, <filename>INHERIT</filename>, and |
| 935 | <filename>require</filename> directives. |
| 936 | </para> |
| 937 | |
| 938 | <section id='locating-include-and-class-files'> |
| 939 | <title>Locating Include and Class Files</title> |
| 940 | |
| 941 | <para> |
| 942 | BitBake uses the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 943 | <link linkend='var-bb-BBPATH'><filename>BBPATH</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 944 | variable to locate needed include and class files. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 945 | Additionally, BitBake searches the current directory for |
| 946 | <filename>include</filename> and <filename>require</filename> |
| 947 | directives. |
| 948 | <note> |
| 949 | The <filename>BBPATH</filename> variable is analogous to |
| 950 | the environment variable <filename>PATH</filename>. |
| 951 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 952 | </para> |
| 953 | |
| 954 | <para> |
| 955 | In order for include and class files to be found by BitBake, |
| 956 | they need to be located in a "classes" subdirectory that can |
| 957 | be found in <filename>BBPATH</filename>. |
| 958 | </para> |
| 959 | </section> |
| 960 | |
| 961 | <section id='inherit-directive'> |
| 962 | <title><filename>inherit</filename> Directive</title> |
| 963 | |
| 964 | <para> |
| 965 | When writing a recipe or class file, you can use the |
| 966 | <filename>inherit</filename> directive to inherit the |
| 967 | functionality of a class (<filename>.bbclass</filename>). |
| 968 | BitBake only supports this directive when used within recipe |
| 969 | and class files (i.e. <filename>.bb</filename> and |
| 970 | <filename>.bbclass</filename>). |
| 971 | </para> |
| 972 | |
| 973 | <para> |
| 974 | The <filename>inherit</filename> directive is a rudimentary |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 975 | means of specifying functionality contained in class files |
| 976 | that your recipes require. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 977 | For example, you can easily abstract out the tasks involved in |
| 978 | building a package that uses Autoconf and Automake and put |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 979 | those tasks into a class file and then have your recipe |
| 980 | inherit that class file. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 981 | </para> |
| 982 | |
| 983 | <para> |
| 984 | As an example, your recipes could use the following directive |
| 985 | to inherit an <filename>autotools.bbclass</filename> file. |
| 986 | The class file would contain common functionality for using |
| 987 | Autotools that could be shared across recipes: |
| 988 | <literallayout class='monospaced'> |
| 989 | inherit autotools |
| 990 | </literallayout> |
| 991 | In this case, BitBake would search for the directory |
| 992 | <filename>classes/autotools.bbclass</filename> |
| 993 | in <filename>BBPATH</filename>. |
| 994 | <note> |
| 995 | You can override any values and functions of the |
| 996 | inherited class within your recipe by doing so |
| 997 | after the "inherit" statement. |
| 998 | </note> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 999 | If you want to use the directive to inherit |
| 1000 | multiple classes, separate them with spaces. |
| 1001 | The following example shows how to inherit both the |
| 1002 | <filename>buildhistory</filename> and <filename>rm_work</filename> |
| 1003 | classes: |
| 1004 | <literallayout class='monospaced'> |
| 1005 | inherit buildhistory rm_work |
| 1006 | </literallayout> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1007 | </para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1008 | |
| 1009 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1010 | An advantage with the inherit directive as compared to both |
| 1011 | the |
| 1012 | <link linkend='include-directive'>include</link> and |
| 1013 | <link linkend='require-inclusion'>require</link> directives |
| 1014 | is that you can inherit class files conditionally. |
| 1015 | You can accomplish this by using a variable expression |
| 1016 | after the <filename>inherit</filename> statement. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1017 | Here is an example: |
| 1018 | <literallayout class='monospaced'> |
| 1019 | inherit ${VARNAME} |
| 1020 | </literallayout> |
| 1021 | If <filename>VARNAME</filename> is going to be set, it needs |
| 1022 | to be set before the <filename>inherit</filename> statement |
| 1023 | is parsed. |
| 1024 | One way to achieve a conditional inherit in this case is to use |
| 1025 | overrides: |
| 1026 | <literallayout class='monospaced'> |
| 1027 | VARIABLE = "" |
| 1028 | VARIABLE_someoverride = "myclass" |
| 1029 | </literallayout> |
| 1030 | </para> |
| 1031 | |
| 1032 | <para> |
| 1033 | Another method is by using anonymous Python. |
| 1034 | Here is an example: |
| 1035 | <literallayout class='monospaced'> |
| 1036 | python () { |
| 1037 | if condition == value: |
| 1038 | d.setVar('VARIABLE', 'myclass') |
| 1039 | else: |
| 1040 | d.setVar('VARIABLE', '') |
| 1041 | } |
| 1042 | </literallayout> |
| 1043 | </para> |
| 1044 | |
| 1045 | <para> |
| 1046 | Alternatively, you could use an in-line Python expression |
| 1047 | in the following form: |
| 1048 | <literallayout class='monospaced'> |
| 1049 | inherit ${@'classname' if condition else ''} |
| 1050 | inherit ${@functionname(params)} |
| 1051 | </literallayout> |
| 1052 | In all cases, if the expression evaluates to an empty |
| 1053 | string, the statement does not trigger a syntax error |
| 1054 | because it becomes a no-op. |
| 1055 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1056 | </section> |
| 1057 | |
| 1058 | <section id='include-directive'> |
| 1059 | <title><filename>include</filename> Directive</title> |
| 1060 | |
| 1061 | <para> |
| 1062 | BitBake understands the <filename>include</filename> |
| 1063 | directive. |
| 1064 | This directive causes BitBake to parse whatever file you specify, |
| 1065 | and to insert that file at that location. |
| 1066 | The directive is much like its equivalent in Make except |
| 1067 | that if the path specified on the include line is a relative |
| 1068 | path, BitBake locates the first file it can find |
| 1069 | within <filename>BBPATH</filename>. |
| 1070 | </para> |
| 1071 | |
| 1072 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1073 | The include directive is a more generic method of including |
| 1074 | functionality as compared to the |
| 1075 | <link linkend='inherit-directive'>inherit</link> directive, |
| 1076 | which is restricted to class (i.e. <filename>.bbclass</filename>) |
| 1077 | files. |
| 1078 | The include directive is applicable for any other kind of |
| 1079 | shared or encapsulated functionality or configuration that |
| 1080 | does not suit a <filename>.bbclass</filename> file. |
| 1081 | </para> |
| 1082 | |
| 1083 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1084 | As an example, suppose you needed a recipe to include some |
| 1085 | self-test definitions: |
| 1086 | <literallayout class='monospaced'> |
| 1087 | include test_defs.inc |
| 1088 | </literallayout> |
| 1089 | <note> |
| 1090 | The <filename>include</filename> directive does not |
| 1091 | produce an error when the file cannot be found. |
| 1092 | Consequently, it is recommended that if the file you |
| 1093 | are including is expected to exist, you should use |
| 1094 | <link linkend='require-inclusion'><filename>require</filename></link> |
| 1095 | instead of <filename>include</filename>. |
| 1096 | Doing so makes sure that an error is produced if the |
| 1097 | file cannot be found. |
| 1098 | </note> |
| 1099 | </para> |
| 1100 | </section> |
| 1101 | |
| 1102 | <section id='require-inclusion'> |
| 1103 | <title><filename>require</filename> Directive</title> |
| 1104 | |
| 1105 | <para> |
| 1106 | BitBake understands the <filename>require</filename> |
| 1107 | directive. |
| 1108 | This directive behaves just like the |
| 1109 | <filename>include</filename> directive with the exception that |
| 1110 | BitBake raises a parsing error if the file to be included cannot |
| 1111 | be found. |
| 1112 | Thus, any file you require is inserted into the file that is |
| 1113 | being parsed at the location of the directive. |
| 1114 | </para> |
| 1115 | |
| 1116 | <para> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1117 | The require directive, like the include directive previously |
| 1118 | described, is a more generic method of including |
| 1119 | functionality as compared to the |
| 1120 | <link linkend='inherit-directive'>inherit</link> directive, |
| 1121 | which is restricted to class (i.e. <filename>.bbclass</filename>) |
| 1122 | files. |
| 1123 | The require directive is applicable for any other kind of |
| 1124 | shared or encapsulated functionality or configuration that |
| 1125 | does not suit a <filename>.bbclass</filename> file. |
| 1126 | </para> |
| 1127 | |
| 1128 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1129 | Similar to how BitBake handles |
| 1130 | <link linkend='include-directive'><filename>include</filename></link>, |
| 1131 | if the path specified |
| 1132 | on the require line is a relative path, BitBake locates |
| 1133 | the first file it can find within <filename>BBPATH</filename>. |
| 1134 | </para> |
| 1135 | |
| 1136 | <para> |
| 1137 | As an example, suppose you have two versions of a recipe |
| 1138 | (e.g. <filename>foo_1.2.2.bb</filename> and |
| 1139 | <filename>foo_2.0.0.bb</filename>) where |
| 1140 | each version contains some identical functionality that could be |
| 1141 | shared. |
| 1142 | You could create an include file named <filename>foo.inc</filename> |
| 1143 | that contains the common definitions needed to build "foo". |
| 1144 | You need to be sure <filename>foo.inc</filename> is located in the |
| 1145 | same directory as your two recipe files as well. |
| 1146 | Once these conditions are set up, you can share the functionality |
| 1147 | using a <filename>require</filename> directive from within each |
| 1148 | recipe: |
| 1149 | <literallayout class='monospaced'> |
| 1150 | require foo.inc |
| 1151 | </literallayout> |
| 1152 | </para> |
| 1153 | </section> |
| 1154 | |
| 1155 | <section id='inherit-configuration-directive'> |
| 1156 | <title><filename>INHERIT</filename> Configuration Directive</title> |
| 1157 | |
| 1158 | <para> |
| 1159 | When creating a configuration file (<filename>.conf</filename>), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1160 | you can use the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1161 | <link linkend='var-bb-INHERIT'><filename>INHERIT</filename></link> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1162 | configuration directive to inherit a class. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1163 | BitBake only supports this directive when used within |
| 1164 | a configuration file. |
| 1165 | </para> |
| 1166 | |
| 1167 | <para> |
| 1168 | As an example, suppose you needed to inherit a class |
| 1169 | file called <filename>abc.bbclass</filename> from a |
| 1170 | configuration file as follows: |
| 1171 | <literallayout class='monospaced'> |
| 1172 | INHERIT += "abc" |
| 1173 | </literallayout> |
| 1174 | This configuration directive causes the named |
| 1175 | class to be inherited at the point of the directive |
| 1176 | during parsing. |
| 1177 | As with the <filename>inherit</filename> directive, the |
| 1178 | <filename>.bbclass</filename> file must be located in a |
| 1179 | "classes" subdirectory in one of the directories specified |
| 1180 | in <filename>BBPATH</filename>. |
| 1181 | <note> |
| 1182 | Because <filename>.conf</filename> files are parsed |
| 1183 | first during BitBake's execution, using |
| 1184 | <filename>INHERIT</filename> to inherit a class effectively |
| 1185 | inherits the class globally (i.e. for all recipes). |
| 1186 | </note> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1187 | If you want to use the directive to inherit |
| 1188 | multiple classes, you can provide them on the same line in the |
| 1189 | <filename>local.conf</filename> file. |
| 1190 | Use spaces to separate the classes. |
| 1191 | The following example shows how to inherit both the |
| 1192 | <filename>autotools</filename> and <filename>pkgconfig</filename> |
| 1193 | classes: |
| 1194 | <literallayout class='monospaced'> |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1195 | INHERIT += "autotools pkgconfig" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1196 | </literallayout> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1197 | </para> |
| 1198 | </section> |
| 1199 | </section> |
| 1200 | |
| 1201 | <section id='functions'> |
| 1202 | <title>Functions</title> |
| 1203 | |
| 1204 | <para> |
| 1205 | As with most languages, functions are the building blocks that |
| 1206 | are used to build up operations into tasks. |
| 1207 | BitBake supports these types of functions: |
| 1208 | <itemizedlist> |
| 1209 | <listitem><para><emphasis>Shell Functions:</emphasis> |
| 1210 | Functions written in shell script and executed either |
| 1211 | directly as functions, tasks, or both. |
| 1212 | They can also be called by other shell functions. |
| 1213 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1214 | <listitem><para><emphasis>BitBake-Style Python Functions:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1215 | Functions written in Python and executed by BitBake or other |
| 1216 | Python functions using <filename>bb.build.exec_func()</filename>. |
| 1217 | </para></listitem> |
| 1218 | <listitem><para><emphasis>Python Functions:</emphasis> |
| 1219 | Functions written in Python and executed by Python. |
| 1220 | </para></listitem> |
| 1221 | <listitem><para><emphasis>Anonymous Python Functions:</emphasis> |
| 1222 | Python functions executed automatically during |
| 1223 | parsing. |
| 1224 | </para></listitem> |
| 1225 | </itemizedlist> |
| 1226 | Regardless of the type of function, you can only |
| 1227 | define them in class (<filename>.bbclass</filename>) |
| 1228 | and recipe (<filename>.bb</filename> or <filename>.inc</filename>) |
| 1229 | files. |
| 1230 | </para> |
| 1231 | |
| 1232 | <section id='shell-functions'> |
| 1233 | <title>Shell Functions</title> |
| 1234 | |
| 1235 | <para> |
| 1236 | Functions written in shell script and executed either |
| 1237 | directly as functions, tasks, or both. |
| 1238 | They can also be called by other shell functions. |
| 1239 | Here is an example shell function definition: |
| 1240 | <literallayout class='monospaced'> |
| 1241 | some_function () { |
| 1242 | echo "Hello World" |
| 1243 | } |
| 1244 | </literallayout> |
| 1245 | When you create these types of functions in your recipe |
| 1246 | or class files, you need to follow the shell programming |
| 1247 | rules. |
| 1248 | The scripts are executed by <filename>/bin/sh</filename>, |
| 1249 | which may not be a bash shell but might be something |
| 1250 | such as <filename>dash</filename>. |
| 1251 | You should not use Bash-specific script (bashisms). |
| 1252 | </para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1253 | |
| 1254 | <para> |
| 1255 | Overrides and override-style operators like |
| 1256 | <filename>_append</filename> and |
| 1257 | <filename>_prepend</filename> can also be applied to |
| 1258 | shell functions. |
| 1259 | Most commonly, this application would be used in a |
| 1260 | <filename>.bbappend</filename> file to modify functions in |
| 1261 | the main recipe. |
| 1262 | It can also be used to modify functions inherited from |
| 1263 | classes. |
| 1264 | </para> |
| 1265 | |
| 1266 | <para> |
| 1267 | As an example, consider the following: |
| 1268 | <literallayout class='monospaced'> |
| 1269 | do_foo() { |
| 1270 | bbplain first |
| 1271 | fn |
| 1272 | } |
| 1273 | |
| 1274 | fn_prepend() { |
| 1275 | bbplain second |
| 1276 | } |
| 1277 | |
| 1278 | fn() { |
| 1279 | bbplain third |
| 1280 | } |
| 1281 | |
| 1282 | do_foo_append() { |
| 1283 | bbplain fourth |
| 1284 | } |
| 1285 | </literallayout> |
| 1286 | Running <filename>do_foo</filename> |
| 1287 | prints the following: |
| 1288 | <literallayout class='monospaced'> |
| 1289 | recipename do_foo: first |
| 1290 | recipename do_foo: second |
| 1291 | recipename do_foo: third |
| 1292 | recipename do_foo: fourth |
| 1293 | </literallayout> |
| 1294 | <note> |
| 1295 | Overrides and override-style operators can |
| 1296 | be applied to any shell function, not just |
| 1297 | <link linkend='tasks'>tasks</link>. |
| 1298 | </note> |
| 1299 | You can use the <filename>bitbake -e</filename> <replaceable>recipename</replaceable> |
| 1300 | command to view the final assembled function |
| 1301 | after all overrides have been applied. |
| 1302 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1303 | </section> |
| 1304 | |
| 1305 | <section id='bitbake-style-python-functions'> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1306 | <title>BitBake-Style Python Functions</title> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1307 | |
| 1308 | <para> |
| 1309 | These functions are written in Python and executed by |
| 1310 | BitBake or other Python functions using |
| 1311 | <filename>bb.build.exec_func()</filename>. |
| 1312 | </para> |
| 1313 | |
| 1314 | <para> |
| 1315 | An example BitBake function is: |
| 1316 | <literallayout class='monospaced'> |
| 1317 | python some_python_function () { |
| 1318 | d.setVar("TEXT", "Hello World") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1319 | print d.getVar("TEXT") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1320 | } |
| 1321 | </literallayout> |
| 1322 | Because the Python "bb" and "os" modules are already |
| 1323 | imported, you do not need to import these modules. |
| 1324 | Also in these types of functions, the datastore ("d") |
| 1325 | is a global variable and is always automatically |
| 1326 | available. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1327 | <note> |
| 1328 | Variable expressions (e.g. <filename>${X}</filename>) |
| 1329 | are no longer expanded within Python functions. |
| 1330 | This behavior is intentional in order to allow you |
| 1331 | to freely set variable values to expandable expressions |
| 1332 | without having them expanded prematurely. |
| 1333 | If you do wish to expand a variable within a Python |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1334 | function, use <filename>d.getVar("X")</filename>. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1335 | Or, for more complicated expressions, use |
| 1336 | <filename>d.expand()</filename>. |
| 1337 | </note> |
| 1338 | </para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1339 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1340 | <para> |
| 1341 | Similar to shell functions, you can also apply overrides |
| 1342 | and override-style operators to BitBake-style Python |
| 1343 | functions. |
| 1344 | </para> |
| 1345 | |
| 1346 | <para> |
| 1347 | As an example, consider the following: |
| 1348 | <literallayout class='monospaced'> |
| 1349 | python do_foo_prepend() { |
| 1350 | bb.plain("first") |
| 1351 | } |
| 1352 | |
| 1353 | python do_foo() { |
| 1354 | bb.plain("second") |
| 1355 | } |
| 1356 | |
| 1357 | python do_foo_append() { |
| 1358 | bb.plain("third") |
| 1359 | } |
| 1360 | </literallayout> |
| 1361 | Running <filename>do_foo</filename> prints |
| 1362 | the following: |
| 1363 | <literallayout class='monospaced'> |
| 1364 | recipename do_foo: first |
| 1365 | recipename do_foo: second |
| 1366 | recipename do_foo: third |
| 1367 | </literallayout> |
| 1368 | You can use the <filename>bitbake -e</filename> <replaceable>recipename</replaceable> |
| 1369 | command to view the final assembled function |
| 1370 | after all overrides have been applied. |
| 1371 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1372 | </section> |
| 1373 | |
| 1374 | <section id='python-functions'> |
| 1375 | <title>Python Functions</title> |
| 1376 | |
| 1377 | <para> |
| 1378 | These functions are written in Python and are executed by |
| 1379 | other Python code. |
| 1380 | Examples of Python functions are utility functions |
| 1381 | that you intend to call from in-line Python or |
| 1382 | from within other Python functions. |
| 1383 | Here is an example: |
| 1384 | <literallayout class='monospaced'> |
| 1385 | def get_depends(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1386 | if d.getVar('SOMECONDITION'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1387 | return "dependencywithcond" |
| 1388 | else: |
| 1389 | return "dependency" |
| 1390 | SOMECONDITION = "1" |
| 1391 | DEPENDS = "${@get_depends(d)}" |
| 1392 | </literallayout> |
| 1393 | This would result in <filename>DEPENDS</filename> |
| 1394 | containing <filename>dependencywithcond</filename>. |
| 1395 | </para> |
| 1396 | |
| 1397 | <para> |
| 1398 | Here are some things to know about Python functions: |
| 1399 | <itemizedlist> |
| 1400 | <listitem><para>Python functions can take parameters. |
| 1401 | </para></listitem> |
| 1402 | <listitem><para>The BitBake datastore is not |
| 1403 | automatically available. |
| 1404 | Consequently, you must pass it in as a |
| 1405 | parameter to the function. |
| 1406 | </para></listitem> |
| 1407 | <listitem><para>The "bb" and "os" Python modules are |
| 1408 | automatically available. |
| 1409 | You do not need to import them. |
| 1410 | </para></listitem> |
| 1411 | </itemizedlist> |
| 1412 | </para> |
| 1413 | </section> |
| 1414 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1415 | <section id='bitbake-style-python-functions-versus-python-functions'> |
| 1416 | <title>Bitbake-Style Python Functions Versus Python Functions</title> |
| 1417 | |
| 1418 | <para> |
| 1419 | Following are some important differences between |
| 1420 | BitBake-style Python functions and regular Python |
| 1421 | functions defined with "def": |
| 1422 | <itemizedlist> |
| 1423 | <listitem><para> |
| 1424 | Only BitBake-style Python functions can be |
| 1425 | <link linkend='tasks'>tasks</link>. |
| 1426 | </para></listitem> |
| 1427 | <listitem><para> |
| 1428 | Overrides and override-style operators can only |
| 1429 | be applied to BitBake-style Python functions. |
| 1430 | </para></listitem> |
| 1431 | <listitem><para> |
| 1432 | Only regular Python functions can take arguments |
| 1433 | and return values. |
| 1434 | </para></listitem> |
| 1435 | <listitem><para> |
| 1436 | <link linkend='variable-flags'>Variable flags</link> |
| 1437 | such as <filename>[dirs]</filename>, |
| 1438 | <filename>[cleandirs]</filename>, and |
| 1439 | <filename>[lockfiles]</filename> can be used |
| 1440 | on BitBake-style Python functions, but not on |
| 1441 | regular Python functions. |
| 1442 | </para></listitem> |
| 1443 | <listitem><para> |
| 1444 | BitBake-style Python functions generate a separate |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1445 | <filename>${</filename><link linkend='var-bb-T'><filename>T</filename></link><filename>}/run.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1446 | script that is executed to run the function, and also |
| 1447 | generate a log file in |
| 1448 | <filename>${T}/log.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable> |
| 1449 | if they are executed as tasks.</para> |
| 1450 | |
| 1451 | <para> |
| 1452 | Regular Python functions execute "inline" and do not |
| 1453 | generate any files in <filename>${T}</filename>. |
| 1454 | </para></listitem> |
| 1455 | <listitem><para> |
| 1456 | Regular Python functions are called with the usual |
| 1457 | Python syntax. |
| 1458 | BitBake-style Python functions are usually tasks and |
| 1459 | are called directly by BitBake, but can also be called |
| 1460 | manually from Python code by using the |
| 1461 | <filename>bb.build.exec_func()</filename> function. |
| 1462 | Here is an example: |
| 1463 | <literallayout class='monospaced'> |
| 1464 | bb.build.exec_func("my_bitbake_style_function", d) |
| 1465 | </literallayout> |
| 1466 | <note> |
| 1467 | <filename>bb.build.exec_func()</filename> can also |
| 1468 | be used to run shell functions from Python code. |
| 1469 | If you want to run a shell function before a Python |
| 1470 | function within the same task, then you can use a |
| 1471 | parent helper Python function that starts by running |
| 1472 | the shell function with |
| 1473 | <filename>bb.build.exec_func()</filename> and then |
| 1474 | runs the Python code. |
| 1475 | </note></para> |
| 1476 | |
| 1477 | <para>To detect errors from functions executed with |
| 1478 | <filename>bb.build.exec_func()</filename>, you |
| 1479 | can catch the <filename>bb.build.FuncFailed</filename> |
| 1480 | exception. |
| 1481 | <note> |
| 1482 | Functions in metadata (recipes and classes) should |
| 1483 | not themselves raise |
| 1484 | <filename>bb.build.FuncFailed</filename>. |
| 1485 | Rather, <filename>bb.build.FuncFailed</filename> |
| 1486 | should be viewed as a general indicator that the |
| 1487 | called function failed by raising an exception. |
| 1488 | For example, an exception raised by |
| 1489 | <filename>bb.fatal()</filename> will be caught inside |
| 1490 | <filename>bb.build.exec_func()</filename>, and a |
| 1491 | <filename>bb.build.FuncFailed</filename> will be raised |
| 1492 | in response. |
| 1493 | </note> |
| 1494 | </para></listitem> |
| 1495 | </itemizedlist> |
| 1496 | </para> |
| 1497 | |
| 1498 | <para> |
| 1499 | Due to their simplicity, you should prefer regular Python functions |
| 1500 | over BitBake-style Python functions unless you need a feature specific |
| 1501 | to BitBake-style Python functions. |
| 1502 | Regular Python functions in metadata are a more recent invention than |
| 1503 | BitBake-style Python functions, and older code tends to use |
| 1504 | <filename>bb.build.exec_func()</filename> more often. |
| 1505 | </para> |
| 1506 | </section> |
| 1507 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1508 | <section id='anonymous-python-functions'> |
| 1509 | <title>Anonymous Python Functions</title> |
| 1510 | |
| 1511 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1512 | Sometimes it is useful to set variables or perform |
| 1513 | other operations programmatically during parsing. |
| 1514 | To do this, you can define special Python functions, |
| 1515 | called anonymous Python functions, that run at the |
| 1516 | end of parsing. |
| 1517 | For example, the following conditionally sets a variable |
| 1518 | based on the value of another variable: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1519 | <literallayout class='monospaced'> |
| 1520 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 1521 | if d.getVar('SOMEVAR') == 'value': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1522 | d.setVar('ANOTHERVAR', 'value2') |
| 1523 | } |
| 1524 | </literallayout> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1525 | An equivalent way to mark a function as an anonymous |
| 1526 | function is to give it the name "__anonymous", rather |
| 1527 | than no name. |
| 1528 | </para> |
| 1529 | |
| 1530 | <para> |
| 1531 | Anonymous Python functions always run at the end |
| 1532 | of parsing, regardless of where they are defined. |
| 1533 | If a recipe contains many anonymous functions, they |
| 1534 | run in the same order as they are defined within the |
| 1535 | recipe. |
| 1536 | As an example, consider the following snippet: |
| 1537 | <literallayout class='monospaced'> |
| 1538 | python () { |
| 1539 | d.setVar('FOO', 'foo 2') |
| 1540 | } |
| 1541 | |
| 1542 | FOO = "foo 1" |
| 1543 | |
| 1544 | python () { |
| 1545 | d.appendVar('BAR', ' bar 2') |
| 1546 | } |
| 1547 | |
| 1548 | BAR = "bar 1" |
| 1549 | </literallayout> |
| 1550 | The previous example is conceptually equivalent to the |
| 1551 | following snippet: |
| 1552 | <literallayout class='monospaced'> |
| 1553 | FOO = "foo 1" |
| 1554 | BAR = "bar 1" |
| 1555 | FOO = "foo 2" |
| 1556 | BAR += "bar 2" |
| 1557 | </literallayout> |
| 1558 | <filename>FOO</filename> ends up with the value "foo 2", |
| 1559 | and <filename>BAR</filename> with the value "bar 1 bar 2". |
| 1560 | Just as in the second snippet, the values set for the |
| 1561 | variables within the anonymous functions become available |
| 1562 | to tasks, which always run after parsing. |
| 1563 | </para> |
| 1564 | |
| 1565 | <para> |
| 1566 | Overrides and override-style operators such as |
| 1567 | "<filename>_append</filename>" are applied before |
| 1568 | anonymous functions run. |
| 1569 | In the following example, <filename>FOO</filename> ends |
| 1570 | up with the value "foo from anonymous": |
| 1571 | <literallayout class='monospaced'> |
| 1572 | FOO = "foo" |
| 1573 | FOO_append = " from outside" |
| 1574 | |
| 1575 | python () { |
| 1576 | d.setVar("FOO", "foo from anonymous") |
| 1577 | } |
| 1578 | </literallayout> |
| 1579 | For methods you can use with anonymous Python functions, |
| 1580 | see the |
| 1581 | "<link linkend='functions-you-can-call-from-within-python'>Functions You Can Call From Within Python</link>" |
| 1582 | section. |
| 1583 | For a different method to run Python code during parsing, |
| 1584 | see the |
| 1585 | "<link linkend='inline-python-variable-expansion'>Inline Python Variable Expansion</link>" |
| 1586 | section. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1587 | </para> |
| 1588 | </section> |
| 1589 | |
| 1590 | <section id='flexible-inheritance-for-class-functions'> |
| 1591 | <title>Flexible Inheritance for Class Functions</title> |
| 1592 | |
| 1593 | <para> |
| 1594 | Through coding techniques and the use of |
| 1595 | <filename>EXPORT_FUNCTIONS</filename>, BitBake supports |
| 1596 | exporting a function from a class such that the |
| 1597 | class function appears as the default implementation |
| 1598 | of the function, but can still be called if a recipe |
| 1599 | inheriting the class needs to define its own version of |
| 1600 | the function. |
| 1601 | </para> |
| 1602 | |
| 1603 | <para> |
| 1604 | To understand the benefits of this feature, consider |
| 1605 | the basic scenario where a class defines a task function |
| 1606 | and your recipe inherits the class. |
| 1607 | In this basic scenario, your recipe inherits the task |
| 1608 | function as defined in the class. |
| 1609 | If desired, your recipe can add to the start and end of the |
| 1610 | function by using the "_prepend" or "_append" operations |
| 1611 | respectively, or it can redefine the function completely. |
| 1612 | However, if it redefines the function, there is |
| 1613 | no means for it to call the class version of the function. |
| 1614 | <filename>EXPORT_FUNCTIONS</filename> provides a mechanism |
| 1615 | that enables the recipe's version of the function to call |
| 1616 | the original version of the function. |
| 1617 | </para> |
| 1618 | |
| 1619 | <para> |
| 1620 | To make use of this technique, you need the following |
| 1621 | things in place: |
| 1622 | <itemizedlist> |
| 1623 | <listitem><para> |
| 1624 | The class needs to define the function as follows: |
| 1625 | <literallayout class='monospaced'> |
| 1626 | <replaceable>classname</replaceable><filename>_</filename><replaceable>functionname</replaceable> |
| 1627 | </literallayout> |
| 1628 | For example, if you have a class file |
| 1629 | <filename>bar.bbclass</filename> and a function named |
| 1630 | <filename>do_foo</filename>, the class must define the function |
| 1631 | as follows: |
| 1632 | <literallayout class='monospaced'> |
| 1633 | bar_do_foo |
| 1634 | </literallayout> |
| 1635 | </para></listitem> |
| 1636 | <listitem><para> |
| 1637 | The class needs to contain the <filename>EXPORT_FUNCTIONS</filename> |
| 1638 | statement as follows: |
| 1639 | <literallayout class='monospaced'> |
| 1640 | EXPORT_FUNCTIONS <replaceable>functionname</replaceable> |
| 1641 | </literallayout> |
| 1642 | For example, continuing with the same example, the |
| 1643 | statement in the <filename>bar.bbclass</filename> would be |
| 1644 | as follows: |
| 1645 | <literallayout class='monospaced'> |
| 1646 | EXPORT_FUNCTIONS do_foo |
| 1647 | </literallayout> |
| 1648 | </para></listitem> |
| 1649 | <listitem><para> |
| 1650 | You need to call the function appropriately from within your |
| 1651 | recipe. |
| 1652 | Continuing with the same example, if your recipe |
| 1653 | needs to call the class version of the function, |
| 1654 | it should call <filename>bar_do_foo</filename>. |
| 1655 | Assuming <filename>do_foo</filename> was a shell function |
| 1656 | and <filename>EXPORT_FUNCTIONS</filename> was used as above, |
| 1657 | the recipe's function could conditionally call the |
| 1658 | class version of the function as follows: |
| 1659 | <literallayout class='monospaced'> |
| 1660 | do_foo() { |
| 1661 | if [ somecondition ] ; then |
| 1662 | bar_do_foo |
| 1663 | else |
| 1664 | # Do something else |
| 1665 | fi |
| 1666 | } |
| 1667 | </literallayout> |
| 1668 | To call your modified version of the function as defined |
| 1669 | in your recipe, call it as <filename>do_foo</filename>. |
| 1670 | </para></listitem> |
| 1671 | </itemizedlist> |
| 1672 | With these conditions met, your single recipe |
| 1673 | can freely choose between the original function |
| 1674 | as defined in the class file and the modified function in your recipe. |
| 1675 | If you do not set up these conditions, you are limited to using one function |
| 1676 | or the other. |
| 1677 | </para> |
| 1678 | </section> |
| 1679 | </section> |
| 1680 | |
| 1681 | <section id='tasks'> |
| 1682 | <title>Tasks</title> |
| 1683 | |
| 1684 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1685 | Tasks are BitBake execution units that make up the |
| 1686 | steps that BitBake can run for a given recipe. |
| 1687 | Tasks are only supported in recipes and classes |
| 1688 | (i.e. in <filename>.bb</filename> files and files |
| 1689 | included or inherited from <filename>.bb</filename> |
| 1690 | files). |
| 1691 | By convention, tasks have names that start with "do_". |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1692 | </para> |
| 1693 | |
| 1694 | <section id='promoting-a-function-to-a-task'> |
| 1695 | <title>Promoting a Function to a Task</title> |
| 1696 | |
| 1697 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1698 | Tasks are either |
| 1699 | <link linkend='shell-functions'>shell functions</link> or |
| 1700 | <link linkend='bitbake-style-python-functions'>BitBake-style Python functions</link> |
| 1701 | that have been promoted to tasks by using the |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1702 | <filename>addtask</filename> command. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1703 | The <filename>addtask</filename> command can also |
| 1704 | optionally describe dependencies between the |
| 1705 | task and other tasks. |
| 1706 | Here is an example that shows how to define a task |
| 1707 | and declare some dependencies: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1708 | <literallayout class='monospaced'> |
| 1709 | python do_printdate () { |
| 1710 | import time |
| 1711 | print time.strftime('%Y%m%d', time.gmtime()) |
| 1712 | } |
| 1713 | addtask printdate after do_fetch before do_build |
| 1714 | </literallayout> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1715 | The first argument to <filename>addtask</filename> |
| 1716 | is the name of the function to promote to |
| 1717 | a task. |
| 1718 | If the name does not start with "do_", "do_" is |
| 1719 | implicitly added, which enforces the convention that |
| 1720 | all task names start with "do_". |
| 1721 | </para> |
| 1722 | |
| 1723 | <para> |
| 1724 | In the previous example, the |
| 1725 | <filename>do_printdate</filename> task becomes a |
| 1726 | dependency of the <filename>do_build</filename> |
| 1727 | task, which is the default task (i.e. the task run by |
| 1728 | the <filename>bitbake</filename> command unless |
| 1729 | another task is specified explicitly). |
| 1730 | Additionally, the <filename>do_printdate</filename> |
| 1731 | task becomes dependent upon the |
| 1732 | <filename>do_fetch</filename> task. |
| 1733 | Running the <filename>do_build</filename> task |
| 1734 | results in the <filename>do_printdate</filename> |
| 1735 | task running first. |
| 1736 | <note> |
| 1737 | If you try out the previous example, you might see that |
| 1738 | the <filename>do_printdate</filename> task is only run |
| 1739 | the first time you build the recipe with |
| 1740 | the <filename>bitbake</filename> command. |
| 1741 | This is because BitBake considers the task "up-to-date" |
| 1742 | after that initial run. |
| 1743 | If you want to force the task to always be rerun for |
| 1744 | experimentation purposes, you can make BitBake always |
| 1745 | consider the task "out-of-date" by using the |
| 1746 | <filename>[</filename><link linkend='variable-flags'><filename>nostamp</filename></link><filename>]</filename> |
| 1747 | variable flag, as follows: |
| 1748 | <literallayout class='monospaced'> |
| 1749 | do_printdate[nostamp] = "1" |
| 1750 | </literallayout> |
| 1751 | You can also explicitly run the task and provide the |
| 1752 | <filename>-f</filename> option as follows: |
| 1753 | <literallayout class='monospaced'> |
| 1754 | $ bitbake <replaceable>recipe</replaceable> -c printdate -f |
| 1755 | </literallayout> |
| 1756 | When manually selecting a task to run with the |
| 1757 | <filename>bitbake</filename> <replaceable>recipe</replaceable> <filename>-c</filename> <replaceable>task</replaceable> |
| 1758 | command, you can omit the "do_" prefix as part of the |
| 1759 | task name. |
| 1760 | </note> |
| 1761 | </para> |
| 1762 | |
| 1763 | <para> |
| 1764 | You might wonder about the practical effects of using |
| 1765 | <filename>addtask</filename> without specifying any |
| 1766 | dependencies as is done in the following example: |
| 1767 | <literallayout class='monospaced'> |
| 1768 | addtask printdate |
| 1769 | </literallayout> |
| 1770 | In this example, assuming dependencies have not been |
| 1771 | added through some other means, the only way to run |
| 1772 | the task is by explicitly selecting it with |
| 1773 | <filename>bitbake</filename> <replaceable>recipe</replaceable> <filename>-c printdate</filename>. |
| 1774 | You can use the |
| 1775 | <filename>do_listtasks</filename> task to list all tasks |
| 1776 | defined in a recipe as shown in the following example: |
| 1777 | <literallayout class='monospaced'> |
| 1778 | $ bitbake <replaceable>recipe</replaceable> -c listtasks |
| 1779 | </literallayout> |
| 1780 | For more information on task dependencies, see the |
| 1781 | "<link linkend='dependencies'>Dependencies</link>" |
| 1782 | section. |
| 1783 | </para> |
| 1784 | |
| 1785 | <para> |
| 1786 | See the |
| 1787 | "<link linkend='variable-flags'>Variable Flags</link>" |
| 1788 | section for information on variable flags you can use with |
| 1789 | tasks. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1790 | </para> |
| 1791 | </section> |
| 1792 | |
| 1793 | <section id='deleting-a-task'> |
| 1794 | <title>Deleting a Task</title> |
| 1795 | |
| 1796 | <para> |
| 1797 | As well as being able to add tasks, you can delete them. |
| 1798 | Simply use the <filename>deltask</filename> command to |
| 1799 | delete a task. |
| 1800 | For example, to delete the example task used in the previous |
| 1801 | sections, you would use: |
| 1802 | <literallayout class='monospaced'> |
| 1803 | deltask printdate |
| 1804 | </literallayout> |
| 1805 | If you delete a task using the <filename>deltask</filename> |
| 1806 | command and the task has dependencies, the dependencies are |
| 1807 | not reconnected. |
| 1808 | For example, suppose you have three tasks named |
| 1809 | <filename>do_a</filename>, <filename>do_b</filename>, and |
| 1810 | <filename>do_c</filename>. |
| 1811 | Furthermore, <filename>do_c</filename> is dependent on |
| 1812 | <filename>do_b</filename>, which in turn is dependent on |
| 1813 | <filename>do_a</filename>. |
| 1814 | Given this scenario, if you use <filename>deltask</filename> |
| 1815 | to delete <filename>do_b</filename>, the implicit dependency |
| 1816 | relationship between <filename>do_c</filename> and |
| 1817 | <filename>do_a</filename> through <filename>do_b</filename> |
| 1818 | no longer exists, and <filename>do_c</filename> dependencies |
| 1819 | are not updated to include <filename>do_a</filename>. |
| 1820 | Thus, <filename>do_c</filename> is free to run before |
| 1821 | <filename>do_a</filename>. |
| 1822 | </para> |
| 1823 | |
| 1824 | <para> |
| 1825 | If you want dependencies such as these to remain intact, use |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1826 | the <filename>[noexec]</filename> varflag to disable the task |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1827 | instead of using the <filename>deltask</filename> command to |
| 1828 | delete it: |
| 1829 | <literallayout class='monospaced'> |
| 1830 | do_b[noexec] = "1" |
| 1831 | </literallayout> |
| 1832 | </para> |
| 1833 | </section> |
| 1834 | |
| 1835 | <section id='passing-information-into-the-build-task-environment'> |
| 1836 | <title>Passing Information Into the Build Task Environment</title> |
| 1837 | |
| 1838 | <para> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1839 | When running a task, BitBake tightly controls the shell execution |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1840 | environment of the build tasks to make |
| 1841 | sure unwanted contamination from the build machine cannot |
| 1842 | influence the build. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1843 | <note> |
| 1844 | By default, BitBake cleans the environment to include only those |
| 1845 | things exported or listed in its whitelist to ensure that the build |
| 1846 | environment is reproducible and consistent. |
| 1847 | You can prevent this "cleaning" by setting the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1848 | <link linkend='var-bb-BB_PRESERVE_ENV'><filename>BB_PRESERVE_ENV</filename></link> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1849 | variable. |
| 1850 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1851 | Consequently, if you do want something to get passed into the |
| 1852 | build task environment, you must take these two steps: |
| 1853 | <orderedlist> |
| 1854 | <listitem><para> |
| 1855 | Tell BitBake to load what you want from the environment |
| 1856 | into the datastore. |
| 1857 | You can do so through the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1858 | <link linkend='var-bb-BB_ENV_WHITELIST'><filename>BB_ENV_WHITELIST</filename></link> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1859 | and |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1860 | <link linkend='var-bb-BB_ENV_EXTRAWHITE'><filename>BB_ENV_EXTRAWHITE</filename></link> |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1861 | variables. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1862 | For example, assume you want to prevent the build system from |
| 1863 | accessing your <filename>$HOME/.ccache</filename> |
| 1864 | directory. |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1865 | The following command "whitelists" the environment variable |
| 1866 | <filename>CCACHE_DIR</filename> causing BitBack to allow that |
| 1867 | variable into the datastore: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1868 | <literallayout class='monospaced'> |
| 1869 | export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE CCACHE_DIR" |
| 1870 | </literallayout></para></listitem> |
| 1871 | <listitem><para> |
| 1872 | Tell BitBake to export what you have loaded into the |
| 1873 | datastore to the task environment of every running task. |
| 1874 | Loading something from the environment into the datastore |
| 1875 | (previous step) only makes it available in the datastore. |
| 1876 | To export it to the task environment of every running task, |
| 1877 | use a command similar to the following in your local configuration |
| 1878 | file <filename>local.conf</filename> or your |
| 1879 | distribution configuration file: |
| 1880 | <literallayout class='monospaced'> |
| 1881 | export CCACHE_DIR |
| 1882 | </literallayout> |
| 1883 | <note> |
| 1884 | A side effect of the previous steps is that BitBake |
| 1885 | records the variable as a dependency of the build process |
| 1886 | in things like the setscene checksums. |
| 1887 | If doing so results in unnecessary rebuilds of tasks, you can |
| 1888 | whitelist the variable so that the setscene code |
| 1889 | ignores the dependency when it creates checksums. |
| 1890 | </note></para></listitem> |
| 1891 | </orderedlist> |
| 1892 | </para> |
| 1893 | |
| 1894 | <para> |
| 1895 | Sometimes, it is useful to be able to obtain information |
| 1896 | from the original execution environment. |
| 1897 | Bitbake saves a copy of the original environment into |
| 1898 | a special variable named |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1899 | <link linkend='var-bb-BB_ORIGENV'><filename>BB_ORIGENV</filename></link>. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1900 | </para> |
| 1901 | |
| 1902 | <para> |
| 1903 | The <filename>BB_ORIGENV</filename> variable returns a datastore |
| 1904 | object that can be queried using the standard datastore operators |
| 1905 | such as <filename>getVar(, False)</filename>. |
| 1906 | The datastore object is useful, for example, to find the original |
| 1907 | <filename>DISPLAY</filename> variable. |
| 1908 | Here is an example: |
| 1909 | <literallayout class='monospaced'> |
| 1910 | origenv = d.getVar("BB_ORIGENV", False) |
| 1911 | bar = origenv.getVar("BAR", False) |
| 1912 | </literallayout> |
| 1913 | The previous example returns <filename>BAR</filename> from the original |
| 1914 | execution environment. |
| 1915 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1916 | </section> |
| 1917 | </section> |
| 1918 | |
| 1919 | <section id='variable-flags'> |
| 1920 | <title>Variable Flags</title> |
| 1921 | |
| 1922 | <para> |
| 1923 | Variable flags (varflags) help control a task's functionality |
| 1924 | and dependencies. |
| 1925 | BitBake reads and writes varflags to the datastore using the following |
| 1926 | command forms: |
| 1927 | <literallayout class='monospaced'> |
| 1928 | <replaceable>variable</replaceable> = d.getVarFlags("<replaceable>variable</replaceable>") |
| 1929 | self.d.setVarFlags("FOO", {"func": True}) |
| 1930 | </literallayout> |
| 1931 | </para> |
| 1932 | |
| 1933 | <para> |
| 1934 | When working with varflags, the same syntax, with the exception of |
| 1935 | overrides, applies. |
| 1936 | In other words, you can set, append, and prepend varflags just like |
| 1937 | variables. |
| 1938 | See the |
| 1939 | "<link linkend='variable-flag-syntax'>Variable Flag Syntax</link>" |
| 1940 | section for details. |
| 1941 | </para> |
| 1942 | |
| 1943 | <para> |
| 1944 | BitBake has a defined set of varflags available for recipes and |
| 1945 | classes. |
| 1946 | Tasks support a number of these flags which control various |
| 1947 | functionality of the task: |
| 1948 | <itemizedlist> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1949 | <listitem><para><emphasis><filename>[cleandirs]</filename>:</emphasis> |
| 1950 | Empty directories that should be created before the |
| 1951 | task runs. |
| 1952 | Directories that already exist are removed and recreated |
| 1953 | to empty them. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1954 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1955 | <listitem><para><emphasis><filename>[depends]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1956 | Controls inter-task dependencies. |
| 1957 | See the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1958 | <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1959 | variable and the |
| 1960 | "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>" |
| 1961 | section for more information. |
| 1962 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1963 | <listitem><para><emphasis><filename>[deptask]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1964 | Controls task build-time dependencies. |
| 1965 | See the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1966 | <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1967 | variable and the |
| 1968 | "<link linkend='build-dependencies'>Build Dependencies</link>" |
| 1969 | section for more information. |
| 1970 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1971 | <listitem><para><emphasis><filename>[dirs]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1972 | Directories that should be created before the task runs. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1973 | Directories that already exist are left as is. |
| 1974 | The last directory listed is used as the |
| 1975 | current working directory for the task. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1976 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1977 | <listitem><para><emphasis><filename>[lockfiles]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1978 | Specifies one or more lockfiles to lock while the task |
| 1979 | executes. |
| 1980 | Only one task may hold a lockfile, and any task that |
| 1981 | attempts to lock an already locked file will block until |
| 1982 | the lock is released. |
| 1983 | You can use this variable flag to accomplish mutual |
| 1984 | exclusion. |
| 1985 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1986 | <listitem><para><emphasis><filename>[noexec]</filename>:</emphasis> |
| 1987 | When set to "1", marks the task as being empty, with |
| 1988 | no execution required. |
| 1989 | You can use the <filename>[noexec]</filename> flag to set up |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1990 | tasks as dependency placeholders, or to disable tasks defined |
| 1991 | elsewhere that are not needed in a particular recipe. |
| 1992 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1993 | <listitem><para><emphasis><filename>[nostamp]</filename>:</emphasis> |
| 1994 | When set to "1", tells BitBake to not generate a stamp |
| 1995 | file for a task, which implies the task should always |
| 1996 | be executed. |
| 1997 | <note><title>Caution</title> |
| 1998 | Any task that depends (possibly indirectly) on a |
| 1999 | <filename>[nostamp]</filename> task will always be |
| 2000 | executed as well. |
| 2001 | This can cause unnecessary rebuilding if you are |
| 2002 | not careful. |
| 2003 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2004 | </para></listitem> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2005 | <listitem><para><emphasis><filename>[number_threads]</filename>:</emphasis> |
| 2006 | Limits tasks to a specific number of simultaneous threads |
| 2007 | during execution. |
| 2008 | This varflag is useful when your build host has a large number |
| 2009 | of cores but certain tasks need to be rate-limited due to various |
| 2010 | kinds of resource constraints (e.g. to avoid network throttling). |
| 2011 | <filename>number_threads</filename> works similarly to the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2012 | <link linkend='var-bb-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename></link> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2013 | variable but is task-specific.</para> |
| 2014 | |
| 2015 | <para>Set the value globally. |
| 2016 | For example, the following makes sure the |
| 2017 | <filename>do_fetch</filename> task uses no more than two |
| 2018 | simultaneous execution threads: |
| 2019 | <literallayout class='monospaced'> |
| 2020 | do_fetch[number_threads] = "2" |
| 2021 | </literallayout> |
| 2022 | <note><title>Warnings</title> |
| 2023 | <itemizedlist> |
| 2024 | <listitem><para> |
| 2025 | Setting the varflag in individual recipes rather |
| 2026 | than globally can result in unpredictable behavior. |
| 2027 | </para></listitem> |
| 2028 | <listitem><para> |
| 2029 | Setting the varflag to a value greater than the |
| 2030 | value used in the <filename>BB_NUMBER_THREADS</filename> |
| 2031 | variable causes <filename>number_threads</filename> |
| 2032 | to have no effect. |
| 2033 | </para></listitem> |
| 2034 | </itemizedlist> |
| 2035 | </note> |
| 2036 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2037 | <listitem><para><emphasis><filename>[postfuncs]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2038 | List of functions to call after the completion of the task. |
| 2039 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2040 | <listitem><para><emphasis><filename>[prefuncs]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2041 | List of functions to call before the task executes. |
| 2042 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2043 | <listitem><para><emphasis><filename>[rdepends]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2044 | Controls inter-task runtime dependencies. |
| 2045 | See the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2046 | <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2047 | variable, the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2048 | <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2049 | variable, and the |
| 2050 | "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>" |
| 2051 | section for more information. |
| 2052 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2053 | <listitem><para><emphasis><filename>[rdeptask]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2054 | Controls task runtime dependencies. |
| 2055 | See the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2056 | <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2057 | variable, the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2058 | <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2059 | variable, and the |
| 2060 | "<link linkend='runtime-dependencies'>Runtime Dependencies</link>" |
| 2061 | section for more information. |
| 2062 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2063 | <listitem><para><emphasis><filename>[recideptask]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2064 | When set in conjunction with |
| 2065 | <filename>recrdeptask</filename>, specifies a task that |
| 2066 | should be inspected for additional dependencies. |
| 2067 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2068 | <listitem><para><emphasis><filename>[recrdeptask]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2069 | Controls task recursive runtime dependencies. |
| 2070 | See the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2071 | <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2072 | variable, the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2073 | <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2074 | variable, and the |
| 2075 | "<link linkend='recursive-dependencies'>Recursive Dependencies</link>" |
| 2076 | section for more information. |
| 2077 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2078 | <listitem><para><emphasis><filename>[stamp-extra-info]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2079 | Extra stamp information to append to the task's stamp. |
| 2080 | As an example, OpenEmbedded uses this flag to allow |
| 2081 | machine-specific tasks. |
| 2082 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2083 | <listitem><para><emphasis><filename>[umask]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2084 | The umask to run the task under. |
| 2085 | </para></listitem> |
| 2086 | </itemizedlist> |
| 2087 | </para> |
| 2088 | |
| 2089 | <para> |
| 2090 | Several varflags are useful for controlling how signatures are |
| 2091 | calculated for variables. |
| 2092 | For more information on this process, see the |
| 2093 | "<link linkend='checksums'>Checksums (Signatures)</link>" |
| 2094 | section. |
| 2095 | <itemizedlist> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2096 | <listitem><para><emphasis><filename>[vardeps]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2097 | Specifies a space-separated list of additional |
| 2098 | variables to add to a variable's dependencies |
| 2099 | for the purposes of calculating its signature. |
| 2100 | Adding variables to this list is useful, for example, when |
| 2101 | a function refers to a variable in a manner that |
| 2102 | does not allow BitBake to automatically determine |
| 2103 | that the variable is referred to. |
| 2104 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2105 | <listitem><para><emphasis><filename>[vardepsexclude]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2106 | Specifies a space-separated list of variables |
| 2107 | that should be excluded from a variable's dependencies |
| 2108 | for the purposes of calculating its signature. |
| 2109 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2110 | <listitem><para><emphasis><filename>[vardepvalue]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2111 | If set, instructs BitBake to ignore the actual |
| 2112 | value of the variable and instead use the specified |
| 2113 | value when calculating the variable's signature. |
| 2114 | </para></listitem> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2115 | <listitem><para><emphasis><filename>[vardepvalueexclude]</filename>:</emphasis> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2116 | Specifies a pipe-separated list of strings to exclude |
| 2117 | from the variable's value when calculating the |
| 2118 | variable's signature. |
| 2119 | </para></listitem> |
| 2120 | </itemizedlist> |
| 2121 | </para> |
| 2122 | </section> |
| 2123 | |
| 2124 | <section id='events'> |
| 2125 | <title>Events</title> |
| 2126 | |
| 2127 | <para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2128 | BitBake allows installation of event handlers within recipe |
| 2129 | and class files. |
| 2130 | Events are triggered at certain points during operation, such |
| 2131 | as the beginning of operation against a given recipe |
| 2132 | (i.e. <filename>*.bb</filename>), the start of a given task, |
| 2133 | a task failure, a task success, and so forth. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2134 | The intent is to make it easy to do things like email |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2135 | notification on build failures. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2136 | </para> |
| 2137 | |
| 2138 | <para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2139 | Following is an example event handler that prints the name |
| 2140 | of the event and the content of the |
| 2141 | <filename>FILE</filename> variable: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2142 | <literallayout class='monospaced'> |
| 2143 | addhandler myclass_eventhandler |
| 2144 | python myclass_eventhandler() { |
| 2145 | from bb.event import getName |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2146 | print("The name of the Event is %s" % getName(e)) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2147 | print("The file we run for is %s" % d.getVar('FILE')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2148 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2149 | myclass_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2150 | </literallayout> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2151 | In the previous example, an eventmask has been set so that |
| 2152 | the handler only sees the "BuildStarted" and "BuildCompleted" |
| 2153 | events. |
| 2154 | This event handler gets called every time an event matching |
| 2155 | the eventmask is triggered. |
| 2156 | A global variable "e" is defined, which represents the current |
| 2157 | event. |
| 2158 | With the <filename>getName(e)</filename> method, you can get |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2159 | the name of the triggered event. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2160 | The global datastore is available as "d". |
| 2161 | In legacy code, you might see "e.data" used to get the datastore. |
| 2162 | However, realize that "e.data" is deprecated and you should use |
| 2163 | "d" going forward. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2164 | </para> |
| 2165 | |
| 2166 | <para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2167 | The context of the datastore is appropriate to the event |
| 2168 | in question. |
| 2169 | For example, "BuildStarted" and "BuildCompleted" events run |
| 2170 | before any tasks are executed so would be in the global |
| 2171 | configuration datastore namespace. |
| 2172 | No recipe-specific metadata exists in that namespace. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2173 | The "BuildStarted" and "BuildCompleted" events also run in |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2174 | the main cooker/server process rather than any worker context. |
| 2175 | Thus, any changes made to the datastore would be seen by other |
| 2176 | cooker/server events within the current build but not seen |
| 2177 | outside of that build or in any worker context. |
| 2178 | Task events run in the actual tasks in question consequently |
| 2179 | have recipe-specific and task-specific contents. |
| 2180 | These events run in the worker context and are discarded at |
| 2181 | the end of task execution. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2182 | </para> |
| 2183 | |
| 2184 | <para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2185 | During a standard build, the following common events might |
| 2186 | occur. |
| 2187 | The following events are the most common kinds of events that |
| 2188 | most metadata might have an interest in viewing: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2189 | <itemizedlist> |
| 2190 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2191 | <filename>bb.event.ConfigParsed()</filename>: |
| 2192 | Fired when the base configuration; which consists of |
| 2193 | <filename>bitbake.conf</filename>, |
| 2194 | <filename>base.bbclass</filename> and any global |
| 2195 | <filename>INHERIT</filename> statements; has been parsed. |
| 2196 | You can see multiple such events when each of the |
| 2197 | workers parse the base configuration or if the server |
| 2198 | changes configuration and reparses. |
| 2199 | Any given datastore only has one such event executed |
| 2200 | against it, however. |
| 2201 | If |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2202 | <link linkende='var-bb-BB_INVALIDCONF'><filename>BB_INVALIDCONF</filename></link> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2203 | is set in the datastore by the event handler, the |
| 2204 | configuration is reparsed and a new event triggered, |
| 2205 | allowing the metadata to update configuration. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2206 | </para></listitem> |
| 2207 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2208 | <filename>bb.event.HeartbeatEvent()</filename>: |
| 2209 | Fires at regular time intervals of one second. |
| 2210 | You can configure the interval time using the |
| 2211 | <filename>BB_HEARTBEAT_EVENT</filename> variable. |
| 2212 | The event's "time" attribute is the |
| 2213 | <filename>time.time()</filename> value when the |
| 2214 | event is triggered. |
| 2215 | This event is useful for activities such as |
| 2216 | system state monitoring. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2217 | </para></listitem> |
| 2218 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2219 | <filename>bb.event.ParseStarted()</filename>: |
| 2220 | Fired when BitBake is about to start parsing recipes. |
| 2221 | This event's "total" attribute represents the number of |
| 2222 | recipes BitBake plans to parse. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2223 | </para></listitem> |
| 2224 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2225 | <filename>bb.event.ParseProgress()</filename>: |
| 2226 | Fired as parsing progresses. |
| 2227 | This event's "current" attribute is the number of |
| 2228 | recipes parsed as well as the "total" attribute. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2229 | </para></listitem> |
| 2230 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2231 | <filename>bb.event.ParseCompleted()</filename>: |
| 2232 | Fired when parsing is complete. |
| 2233 | This event's "cached", "parsed", "skipped", "virtuals", |
| 2234 | "masked", and "errors" attributes provide statistics |
| 2235 | for the parsing results. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2236 | </para></listitem> |
| 2237 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2238 | <filename>bb.event.BuildStarted()</filename>: |
| 2239 | Fired when a new build starts. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2240 | BitBake fires multiple "BuildStarted" events (one per configuration) |
| 2241 | when multiple configuration (multiconfig) is enabled. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2242 | </para></listitem> |
| 2243 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2244 | <filename>bb.build.TaskStarted()</filename>: |
| 2245 | Fired when a task starts. |
| 2246 | This event's "taskfile" attribute points to the recipe |
| 2247 | from which the task originates. |
| 2248 | The "taskname" attribute, which is the task's name, |
| 2249 | includes the <filename>do_</filename> prefix, and the |
| 2250 | "logfile" attribute point to where the task's output is |
| 2251 | stored. |
| 2252 | Finally, the "time" attribute is the task's execution start |
| 2253 | time. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2254 | </para></listitem> |
| 2255 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2256 | <filename>bb.build.TaskInvalid()</filename>: |
| 2257 | Fired if BitBake tries to execute a task that does not exist. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2258 | </para></listitem> |
| 2259 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2260 | <filename>bb.build.TaskFailedSilent()</filename>: |
| 2261 | Fired for setscene tasks that fail and should not be |
| 2262 | presented to the user verbosely. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2263 | </para></listitem> |
| 2264 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2265 | <filename>bb.build.TaskFailed()</filename>: |
| 2266 | Fired for normal tasks that fail. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2267 | </para></listitem> |
| 2268 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2269 | <filename>bb.build.TaskSucceeded()</filename>: |
| 2270 | Fired when a task successfully completes. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2271 | </para></listitem> |
| 2272 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2273 | <filename>bb.event.BuildCompleted()</filename>: |
| 2274 | Fired when a build finishes. |
| 2275 | </para></listitem> |
| 2276 | <listitem><para> |
| 2277 | <filename>bb.cooker.CookerExit()</filename>: |
| 2278 | Fired when the BitBake server/cooker shuts down. |
| 2279 | This event is usually only seen by the UIs as a |
| 2280 | sign they should also shutdown. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2281 | </para></listitem> |
| 2282 | </itemizedlist> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2283 | </para> |
| 2284 | |
| 2285 | <para> |
| 2286 | This next list of example events occur based on specific |
| 2287 | requests to the server. |
| 2288 | These events are often used to communicate larger pieces of |
| 2289 | information from the BitBake server to other parts of |
| 2290 | BitBake such as user interfaces: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2291 | <itemizedlist> |
| 2292 | <listitem><para> |
| 2293 | <filename>bb.event.TreeDataPreparationStarted()</filename> |
| 2294 | </para></listitem> |
| 2295 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2296 | <filename>bb.event.TreeDataPreparationProgress()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2297 | </para></listitem> |
| 2298 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2299 | <filename>bb.event.TreeDataPreparationCompleted()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2300 | </para></listitem> |
| 2301 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2302 | <filename>bb.event.DepTreeGenerated()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2303 | </para></listitem> |
| 2304 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2305 | <filename>bb.event.CoreBaseFilesFound()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2306 | </para></listitem> |
| 2307 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2308 | <filename>bb.event.ConfigFilePathFound()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2309 | </para></listitem> |
| 2310 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2311 | <filename>bb.event.FilesMatchingFound()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2312 | </para></listitem> |
| 2313 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2314 | <filename>bb.event.ConfigFilesFound()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2315 | </para></listitem> |
| 2316 | <listitem><para> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 2317 | <filename>bb.event.TargetsTreeGenerated()</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2318 | </para></listitem> |
| 2319 | </itemizedlist> |
| 2320 | </para> |
| 2321 | </section> |
| 2322 | |
| 2323 | <section id='variants-class-extension-mechanism'> |
| 2324 | <title>Variants - Class Extension Mechanism</title> |
| 2325 | |
| 2326 | <para> |
| 2327 | BitBake supports two features that facilitate creating |
| 2328 | from a single recipe file multiple incarnations of that |
| 2329 | recipe file where all incarnations are buildable. |
| 2330 | These features are enabled through the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2331 | <link linkend='var-bb-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2332 | and |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2333 | <link linkend='var-bb-BBVERSIONS'><filename>BBVERSIONS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2334 | variables. |
| 2335 | <note> |
| 2336 | The mechanism for this class extension is extremely |
| 2337 | specific to the implementation. |
| 2338 | Usually, the recipe's |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2339 | <link linkend='var-bb-PROVIDES'><filename>PROVIDES</filename></link>, |
| 2340 | <link linkend='var-bb-PN'><filename>PN</filename></link>, and |
| 2341 | <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2342 | variables would need to be modified by the extension class. |
| 2343 | For specific examples, see the OE-Core |
| 2344 | <filename>native</filename>, <filename>nativesdk</filename>, |
| 2345 | and <filename>multilib</filename> classes. |
| 2346 | </note> |
| 2347 | <itemizedlist> |
| 2348 | <listitem><para><emphasis><filename>BBCLASSEXTEND</filename>:</emphasis> |
| 2349 | This variable is a space separated list of classes used to "extend" the |
| 2350 | recipe for each variant. |
| 2351 | Here is an example that results in a second incarnation of the current |
| 2352 | recipe being available. |
| 2353 | This second incarnation will have the "native" class inherited. |
| 2354 | <literallayout class='monospaced'> |
| 2355 | BBCLASSEXTEND = "native" |
| 2356 | </literallayout></para></listitem> |
| 2357 | <listitem><para><emphasis><filename>BBVERSIONS</filename>:</emphasis> |
| 2358 | This variable allows a single recipe to build multiple versions of a |
| 2359 | project from a single recipe file. |
| 2360 | You can also specify conditional metadata |
| 2361 | (using the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2362 | <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2363 | mechanism) for a single version, or an optionally named range of versions. |
| 2364 | Here is an example: |
| 2365 | <literallayout class='monospaced'> |
| 2366 | BBVERSIONS = "1.0 2.0 git" |
| 2367 | SRC_URI_git = "git://someurl/somepath.git" |
| 2368 | |
| 2369 | BBVERSIONS = "1.0.[0-6]:1.0.0+ \ 1.0.[7-9]:1.0.7+" |
| 2370 | SRC_URI_append_1.0.7+ = "file://some_patch_which_the_new_versions_need.patch;patch=1" |
| 2371 | </literallayout> |
| 2372 | The name of the range defaults to the original version of the |
| 2373 | recipe. |
| 2374 | For example, in OpenEmbedded, the recipe file |
| 2375 | <filename>foo_1.0.0+.bb</filename> creates a default name range |
| 2376 | of <filename>1.0.0+</filename>. |
| 2377 | This is useful because the range name is not only placed |
| 2378 | into overrides, but it is also made available for the metadata to use |
| 2379 | in the variable that defines the base recipe versions for use in |
| 2380 | <filename>file://</filename> search paths |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2381 | (<link linkend='var-bb-FILESPATH'><filename>FILESPATH</filename></link>). |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2382 | </para></listitem> |
| 2383 | </itemizedlist> |
| 2384 | </para> |
| 2385 | </section> |
| 2386 | |
| 2387 | <section id='dependencies'> |
| 2388 | <title>Dependencies</title> |
| 2389 | |
| 2390 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2391 | To allow for efficient parallel processing, BitBake handles |
| 2392 | dependencies at the task level. |
| 2393 | Dependencies can exist both between tasks within a single recipe |
| 2394 | and between tasks in different recipes. |
| 2395 | Following are examples of each: |
| 2396 | <itemizedlist> |
| 2397 | <listitem><para>For tasks within a single recipe, a |
| 2398 | recipe's <filename>do_configure</filename> |
| 2399 | task might need to complete before its |
| 2400 | <filename>do_compile</filename> task can run. |
| 2401 | </para></listitem> |
| 2402 | <listitem><para>For tasks in different recipes, one |
| 2403 | recipe's <filename>do_configure</filename> |
| 2404 | task might require another recipe's |
| 2405 | <filename>do_populate_sysroot</filename> |
| 2406 | task to finish first such that the libraries and headers |
| 2407 | provided by the other recipe are available. |
| 2408 | </para></listitem> |
| 2409 | </itemizedlist> |
| 2410 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2411 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2412 | <para> |
| 2413 | This section describes several ways to declare dependencies. |
| 2414 | Remember, even though dependencies are declared in different ways, they |
| 2415 | are all simply dependencies between tasks. |
| 2416 | </para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2417 | |
| 2418 | <section id='dependencies-internal-to-the-bb-file'> |
| 2419 | <title>Dependencies Internal to the <filename>.bb</filename> File</title> |
| 2420 | |
| 2421 | <para> |
| 2422 | BitBake uses the <filename>addtask</filename> directive |
| 2423 | to manage dependencies that are internal to a given recipe |
| 2424 | file. |
| 2425 | You can use the <filename>addtask</filename> directive to |
| 2426 | indicate when a task is dependent on other tasks or when |
| 2427 | other tasks depend on that recipe. |
| 2428 | Here is an example: |
| 2429 | <literallayout class='monospaced'> |
| 2430 | addtask printdate after do_fetch before do_build |
| 2431 | </literallayout> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2432 | In this example, the <filename>do_printdate</filename> |
| 2433 | task depends on the completion of the |
| 2434 | <filename>do_fetch</filename> task, and the |
| 2435 | <filename>do_build</filename> task depends on the |
| 2436 | completion of the <filename>do_printdate</filename> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2437 | task. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2438 | <note><para> |
| 2439 | For a task to run, it must be a direct or indirect |
| 2440 | dependency of some other task that is scheduled to |
| 2441 | run.</para> |
| 2442 | |
| 2443 | <para>For illustration, here are some examples: |
| 2444 | <itemizedlist> |
| 2445 | <listitem><para> |
| 2446 | The directive |
| 2447 | <filename>addtask mytask before do_configure</filename> |
| 2448 | causes <filename>do_mytask</filename> to run before |
| 2449 | <filename>do_configure</filename> runs. |
| 2450 | Be aware that <filename>do_mytask</filename> still only |
| 2451 | runs if its <link linkend='checksums'>input checksum</link> |
| 2452 | has changed since the last time it was run. |
| 2453 | Changes to the input checksum of |
| 2454 | <filename>do_mytask</filename> also indirectly cause |
| 2455 | <filename>do_configure</filename> to run. |
| 2456 | </para></listitem> |
| 2457 | <listitem><para> |
| 2458 | The directive |
| 2459 | <filename>addtask mytask after do_configure</filename> |
| 2460 | by itself never causes <filename>do_mytask</filename> |
| 2461 | to run. |
| 2462 | <filename>do_mytask</filename> can still be run manually |
| 2463 | as follows: |
| 2464 | <literallayout class='monospaced'> |
| 2465 | $ bitbake <replaceable>recipe</replaceable> -c mytask |
| 2466 | </literallayout> |
| 2467 | Declaring <filename>do_mytask</filename> as a dependency |
| 2468 | of some other task that is scheduled to run also causes |
| 2469 | it to run. |
| 2470 | Regardless, the task runs after |
| 2471 | <filename>do_configure</filename>. |
| 2472 | </para></listitem> |
| 2473 | </itemizedlist></para> |
| 2474 | </note> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2475 | </para> |
| 2476 | </section> |
| 2477 | |
| 2478 | <section id='build-dependencies'> |
| 2479 | <title>Build Dependencies</title> |
| 2480 | |
| 2481 | <para> |
| 2482 | BitBake uses the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2483 | <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2484 | variable to manage build time dependencies. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2485 | The <filename>[deptask]</filename> varflag for tasks |
| 2486 | signifies the task of each |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2487 | item listed in <filename>DEPENDS</filename> that must |
| 2488 | complete before that task can be executed. |
| 2489 | Here is an example: |
| 2490 | <literallayout class='monospaced'> |
| 2491 | do_configure[deptask] = "do_populate_sysroot" |
| 2492 | </literallayout> |
| 2493 | In this example, the <filename>do_populate_sysroot</filename> |
| 2494 | task of each item in <filename>DEPENDS</filename> must complete before |
| 2495 | <filename>do_configure</filename> can execute. |
| 2496 | </para> |
| 2497 | </section> |
| 2498 | |
| 2499 | <section id='runtime-dependencies'> |
| 2500 | <title>Runtime Dependencies</title> |
| 2501 | |
| 2502 | <para> |
| 2503 | BitBake uses the |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2504 | <link linkend='var-bb-PACKAGES'><filename>PACKAGES</filename></link>, |
| 2505 | <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link>, and |
| 2506 | <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2507 | variables to manage runtime dependencies. |
| 2508 | </para> |
| 2509 | |
| 2510 | <para> |
| 2511 | The <filename>PACKAGES</filename> variable lists runtime |
| 2512 | packages. |
| 2513 | Each of those packages can have <filename>RDEPENDS</filename> and |
| 2514 | <filename>RRECOMMENDS</filename> runtime dependencies. |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2515 | The <filename>[rdeptask]</filename> flag for tasks is used to |
| 2516 | signify the task of each |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2517 | item runtime dependency which must have completed before that |
| 2518 | task can be executed. |
| 2519 | <literallayout class='monospaced'> |
| 2520 | do_package_qa[rdeptask] = "do_packagedata" |
| 2521 | </literallayout> |
| 2522 | In the previous example, the <filename>do_packagedata</filename> |
| 2523 | task of each item in <filename>RDEPENDS</filename> must have |
| 2524 | completed before <filename>do_package_qa</filename> can execute. |
| 2525 | </para> |
| 2526 | </section> |
| 2527 | |
| 2528 | <section id='recursive-dependencies'> |
| 2529 | <title>Recursive Dependencies</title> |
| 2530 | |
| 2531 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2532 | BitBake uses the <filename>[recrdeptask]</filename> flag to manage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2533 | recursive task dependencies. |
| 2534 | BitBake looks through the build-time and runtime |
| 2535 | dependencies of the current recipe, looks through |
| 2536 | the task's inter-task |
| 2537 | dependencies, and then adds dependencies for the |
| 2538 | listed task. |
| 2539 | Once BitBake has accomplished this, it recursively works through |
| 2540 | the dependencies of those tasks. |
| 2541 | Iterative passes continue until all dependencies are discovered |
| 2542 | and added. |
| 2543 | </para> |
| 2544 | |
| 2545 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2546 | The <filename>[recrdeptask]</filename> flag is most commonly |
| 2547 | used in high-level |
| 2548 | recipes that need to wait for some task to finish "globally". |
| 2549 | For example, <filename>image.bbclass</filename> has the following: |
| 2550 | <literallayout class='monospaced'> |
| 2551 | do_rootfs[recrdeptask] += "do_packagedata" |
| 2552 | </literallayout> |
| 2553 | This statement says that the <filename>do_packagedata</filename> |
| 2554 | task of the current recipe and all recipes reachable |
| 2555 | (by way of dependencies) from the |
| 2556 | image recipe must run before the <filename>do_rootfs</filename> |
| 2557 | task can run. |
| 2558 | </para> |
| 2559 | |
| 2560 | <para> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2561 | You might want to not only have BitBake look for |
| 2562 | dependencies of those tasks, but also have BitBake look |
| 2563 | for build-time and runtime dependencies of the dependent |
| 2564 | tasks as well. |
| 2565 | If that is the case, you need to reference the task name |
| 2566 | itself in the task list: |
| 2567 | <literallayout class='monospaced'> |
| 2568 | do_a[recrdeptask] = "do_a do_b" |
| 2569 | </literallayout> |
| 2570 | </para> |
| 2571 | </section> |
| 2572 | |
| 2573 | <section id='inter-task-dependencies'> |
| 2574 | <title>Inter-Task Dependencies</title> |
| 2575 | |
| 2576 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2577 | BitBake uses the <filename>[depends]</filename> |
| 2578 | flag in a more generic form |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2579 | to manage inter-task dependencies. |
| 2580 | This more generic form allows for inter-dependency |
| 2581 | checks for specific tasks rather than checks for |
| 2582 | the data in <filename>DEPENDS</filename>. |
| 2583 | Here is an example: |
| 2584 | <literallayout class='monospaced'> |
| 2585 | do_patch[depends] = "quilt-native:do_populate_sysroot" |
| 2586 | </literallayout> |
| 2587 | In this example, the <filename>do_populate_sysroot</filename> |
| 2588 | task of the target <filename>quilt-native</filename> |
| 2589 | must have completed before the |
| 2590 | <filename>do_patch</filename> task can execute. |
| 2591 | </para> |
| 2592 | |
| 2593 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2594 | The <filename>[rdepends]</filename> flag works in a similar |
| 2595 | way but takes targets |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2596 | in the runtime namespace instead of the build-time dependency |
| 2597 | namespace. |
| 2598 | </para> |
| 2599 | </section> |
| 2600 | </section> |
| 2601 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2602 | <section id='functions-you-can-call-from-within-python'> |
| 2603 | <title>Functions You Can Call From Within Python</title> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2604 | |
| 2605 | <para> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2606 | BitBake provides many functions you can call from |
| 2607 | within Python functions. |
| 2608 | This section lists the most commonly used functions, |
| 2609 | and mentions where to find others. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2610 | </para> |
| 2611 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2612 | <section id='functions-for-accessing-datastore-variables'> |
| 2613 | <title>Functions for Accessing Datastore Variables</title> |
| 2614 | |
| 2615 | <para> |
| 2616 | It is often necessary to access variables in the |
| 2617 | BitBake datastore using Python functions. |
| 2618 | The Bitbake datastore has an API that allows you this |
| 2619 | access. |
| 2620 | Here is a list of available operations: |
| 2621 | </para> |
| 2622 | |
| 2623 | <para> |
| 2624 | <informaltable frame='none'> |
| 2625 | <tgroup cols='2' align='left' colsep='1' rowsep='1'> |
| 2626 | <colspec colname='c1' colwidth='1*'/> |
| 2627 | <colspec colname='c2' colwidth='1*'/> |
| 2628 | <thead> |
| 2629 | <row> |
| 2630 | <entry align="left"><emphasis>Operation</emphasis></entry> |
| 2631 | <entry align="left"><emphasis>Description</emphasis></entry> |
| 2632 | </row> |
| 2633 | </thead> |
| 2634 | <tbody> |
| 2635 | <row> |
| 2636 | <entry align="left"><filename>d.getVar("X", expand)</filename></entry> |
| 2637 | <entry align="left">Returns the value of variable "X". |
| 2638 | Using "expand=True" expands the value. |
| 2639 | Returns "None" if the variable "X" does not exist.</entry> |
| 2640 | </row> |
| 2641 | <row> |
| 2642 | <entry align="left"><filename>d.setVar("X", "value")</filename></entry> |
| 2643 | <entry align="left">Sets the variable "X" to "value".</entry> |
| 2644 | </row> |
| 2645 | <row> |
| 2646 | <entry align="left"><filename>d.appendVar("X", "value")</filename></entry> |
| 2647 | <entry align="left">Adds "value" to the end of the variable "X". |
| 2648 | Acts like <filename>d.setVar("X", "value")</filename> |
| 2649 | if the variable "X" does not exist.</entry> |
| 2650 | </row> |
| 2651 | <row> |
| 2652 | <entry align="left"><filename>d.prependVar("X", "value")</filename></entry> |
| 2653 | <entry align="left">Adds "value" to the start of the variable "X". |
| 2654 | Acts like <filename>d.setVar("X", "value")</filename> |
| 2655 | if the variable "X" does not exist.</entry> |
| 2656 | </row> |
| 2657 | <row> |
| 2658 | <entry align="left"><filename>d.delVar("X")</filename></entry> |
| 2659 | <entry align="left">Deletes the variable "X" from the datastore. |
| 2660 | Does nothing if the variable "X" does not exist.</entry> |
| 2661 | </row> |
| 2662 | <row> |
| 2663 | <entry align="left"><filename>d.renameVar("X", "Y")</filename></entry> |
| 2664 | <entry align="left">Renames the variable "X" to "Y". |
| 2665 | Does nothing if the variable "X" does not exist.</entry> |
| 2666 | </row> |
| 2667 | <row> |
| 2668 | <entry align="left"><filename>d.getVarFlag("X", flag, expand)</filename></entry> |
| 2669 | <entry align="left">Returns the value of variable "X". |
| 2670 | Using "expand=True" expands the value. |
| 2671 | Returns "None" if either the variable "X" or the named flag |
| 2672 | does not exist.</entry> |
| 2673 | </row> |
| 2674 | <row> |
| 2675 | <entry align="left"><filename>d.setVarFlag("X", flag, "value")</filename></entry> |
| 2676 | <entry align="left">Sets the named flag for variable "X" to "value".</entry> |
| 2677 | </row> |
| 2678 | <row> |
| 2679 | <entry align="left"><filename>d.appendVarFlag("X", flag, "value")</filename></entry> |
| 2680 | <entry align="left">Appends "value" to the named flag on the |
| 2681 | variable "X". |
| 2682 | Acts like <filename>d.setVarFlag("X", flag, "value")</filename> |
| 2683 | if the named flag does not exist.</entry> |
| 2684 | </row> |
| 2685 | <row> |
| 2686 | <entry align="left"><filename>d.prependVarFlag("X", flag, "value")</filename></entry> |
| 2687 | <entry align="left">Prepends "value" to the named flag on |
| 2688 | the variable "X". |
| 2689 | Acts like <filename>d.setVarFlag("X", flag, "value")</filename> |
| 2690 | if the named flag does not exist.</entry> |
| 2691 | </row> |
| 2692 | <row> |
| 2693 | <entry align="left"><filename>d.delVarFlag("X", flag)</filename></entry> |
| 2694 | <entry align="left">Deletes the named flag on the variable |
| 2695 | "X" from the datastore.</entry> |
| 2696 | </row> |
| 2697 | <row> |
| 2698 | <entry align="left"><filename>d.setVarFlags("X", flagsdict)</filename></entry> |
| 2699 | <entry align="left">Sets the flags specified in |
| 2700 | the <filename>flagsdict()</filename> parameter. |
| 2701 | <filename>setVarFlags</filename> does not clear previous flags. |
| 2702 | Think of this operation as <filename>addVarFlags</filename>.</entry> |
| 2703 | </row> |
| 2704 | <row> |
| 2705 | <entry align="left"><filename>d.getVarFlags("X")</filename></entry> |
| 2706 | <entry align="left">Returns a <filename>flagsdict</filename> |
| 2707 | of the flags for the variable "X". |
| 2708 | Returns "None" if the variable "X" does not exist.</entry> |
| 2709 | </row> |
| 2710 | <row> |
| 2711 | <entry align="left"><filename>d.delVarFlags("X")</filename></entry> |
| 2712 | <entry align="left">Deletes all the flags for the variable "X". |
| 2713 | Does nothing if the variable "X" does not exist.</entry> |
| 2714 | </row> |
| 2715 | <row> |
| 2716 | <entry align="left"><filename>d.expand(expression)</filename></entry> |
| 2717 | <entry align="left">Expands variable references in the specified |
| 2718 | string expression. |
| 2719 | References to variables that do not exist are left as is. |
| 2720 | For example, <filename>d.expand("foo ${X}")</filename> |
| 2721 | expands to the literal string "foo ${X}" if the |
| 2722 | variable "X" does not exist.</entry> |
| 2723 | </row> |
| 2724 | </tbody> |
| 2725 | </tgroup> |
| 2726 | </informaltable> |
| 2727 | </para> |
| 2728 | </section> |
| 2729 | |
| 2730 | <section id='other-functions'> |
| 2731 | <title>Other Functions</title> |
| 2732 | |
| 2733 | <para> |
| 2734 | You can find many other functions that can be called |
| 2735 | from Python by looking at the source code of the |
| 2736 | <filename>bb</filename> module, which is in |
| 2737 | <filename>bitbake/lib/bb</filename>. |
| 2738 | For example, |
| 2739 | <filename>bitbake/lib/bb/utils.py</filename> includes |
| 2740 | the commonly used functions |
| 2741 | <filename>bb.utils.contains()</filename> and |
| 2742 | <filename>bb.utils.mkdirhier()</filename>, which come |
| 2743 | with docstrings. |
| 2744 | </para> |
| 2745 | </section> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2746 | </section> |
| 2747 | |
| 2748 | <section id='task-checksums-and-setscene'> |
| 2749 | <title>Task Checksums and Setscene</title> |
| 2750 | |
| 2751 | <para> |
| 2752 | BitBake uses checksums (or signatures) along with the setscene |
| 2753 | to determine if a task needs to be run. |
| 2754 | This section describes the process. |
| 2755 | To help understand how BitBake does this, the section assumes an |
| 2756 | OpenEmbedded metadata-based example. |
| 2757 | </para> |
| 2758 | |
| 2759 | <para> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2760 | These checksums are stored in |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2761 | <link linkend='var-bb-STAMP'><filename>STAMP</filename></link>. |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2762 | You can examine the checksums using the following BitBake command: |
| 2763 | <literallayout class='monospaced'> |
| 2764 | $ bitbake-dumpsigs |
| 2765 | </literallayout> |
| 2766 | This command returns the signature data in a readable format |
| 2767 | that allows you to examine the inputs used when the |
| 2768 | OpenEmbedded build system generates signatures. |
| 2769 | For example, using <filename>bitbake-dumpsigs</filename> |
| 2770 | allows you to examine the <filename>do_compile</filename> |
| 2771 | task's “sigdata” for a C application (e.g. |
| 2772 | <filename>bash</filename>). |
| 2773 | Running the command also reveals that the “CC” variable is part of |
| 2774 | the inputs that are hashed. |
| 2775 | Any changes to this variable would invalidate the stamp and |
| 2776 | cause the <filename>do_compile</filename> task to run. |
| 2777 | </para> |
| 2778 | |
| 2779 | <para> |
| 2780 | The following list describes related variables: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2781 | <itemizedlist> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2782 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2783 | <link linkend='var-bb-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></link>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2784 | Specifies the name of the function to call during |
| 2785 | the "setscene" part of the task's execution in order |
| 2786 | to validate the list of task hashes. |
| 2787 | </para></listitem> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2788 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2789 | <link linkend='var-bb-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></link>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2790 | Specifies a function BitBake calls that determines |
| 2791 | whether BitBake requires a setscene dependency to |
| 2792 | be met. |
| 2793 | </para></listitem> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2794 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2795 | <link linkend='var-bb-BB_SETSCENE_VERIFY_FUNCTION2'><filename>BB_SETSCENE_VERIFY_FUNCTION2</filename></link>: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2796 | Specifies a function to call that verifies the list of |
| 2797 | planned task execution before the main task execution |
| 2798 | happens. |
| 2799 | </para></listitem> |
| 2800 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2801 | <link linkend='var-bb-BB_STAMP_POLICY'><filename>BB_STAMP_POLICY</filename></link>: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2802 | Defines the mode for comparing timestamps of stamp files. |
| 2803 | </para></listitem> |
| 2804 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2805 | <link linkend='var-bb-BB_STAMP_WHITELIST'><filename>BB_STAMP_WHITELIST</filename></link>: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2806 | Lists stamp files that are looked at when the stamp policy |
| 2807 | is "whitelist". |
| 2808 | </para></listitem> |
| 2809 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2810 | <link linkend='var-bb-BB_TASKHASH'><filename>BB_TASKHASH</filename></link>: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2811 | Within an executing task, this variable holds the hash |
| 2812 | of the task as returned by the currently enabled |
| 2813 | signature generator. |
| 2814 | </para></listitem> |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2815 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2816 | <link linkend='var-bb-STAMP'><filename>STAMP</filename></link>: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2817 | The base path to create stamp files. |
| 2818 | </para></listitem> |
| 2819 | <listitem><para> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 2820 | <link linkend='var-bb-STAMPCLEAN'><filename>STAMPCLEAN</filename></link>: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 2821 | Again, the base path to create stamp files but can use wildcards |
| 2822 | for matching a range of files for clean operations. |
| 2823 | </para></listitem> |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2824 | </itemizedlist> |
| 2825 | </para> |
| 2826 | </section> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2827 | |
| 2828 | <section id='wildcard-support-in-variables'> |
| 2829 | <title>Wildcard Support in Variables</title> |
| 2830 | |
| 2831 | <para> |
| 2832 | Support for wildcard use in variables varies depending on the |
| 2833 | context in which it is used. |
| 2834 | For example, some variables and file names allow limited use of |
| 2835 | wildcards through the "<filename>%</filename>" and |
| 2836 | "<filename>*</filename>" characters. |
| 2837 | Other variables or names support Python's |
| 2838 | <ulink url='https://docs.python.org/3/library/glob.html'><filename>glob</filename></ulink> |
| 2839 | syntax, |
| 2840 | <ulink url='https://docs.python.org/3/library/fnmatch.html#module-fnmatch'><filename>fnmatch</filename></ulink> |
| 2841 | syntax, or |
| 2842 | <ulink url='https://docs.python.org/3/library/re.html#re'><filename>Regular Expression (re)</filename></ulink> |
| 2843 | syntax. |
| 2844 | </para> |
| 2845 | |
| 2846 | <para> |
| 2847 | For variables that have wildcard suport, the |
| 2848 | documentation describes which form of wildcard, its |
| 2849 | use, and its limitations. |
| 2850 | </para> |
| 2851 | </section> |
| 2852 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2853 | </chapter> |