blob: 421364c2cf93550e05f03a31cbd5ec5ee3695070 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001<!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 Williamsc0f7c042017-02-23 20:41:17 -060047
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 Williamsc124f4f2015-09-15 14:41:29 -050062 </section>
63
Brad Bishopc342db32019-05-15 21:57:59 -040064 <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 Bishop6e60e8b2018-02-01 10:27:11 -0500136 <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 Williamsc124f4f2015-09-15 14:41:29 -0500178 <section id='variable-expansion'>
179 <title>Variable Expansion</title>
180
181 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600182 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 Williamsc124f4f2015-09-15 14:41:29 -0500187 <literallayout class='monospaced'>
188 A = "aval"
189 B = "pre${A}post"
190 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600191 <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 Williamsc124f4f2015-09-15 14:41:29 -0500228 </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 "=+"
Brad Bishopacc069e2019-09-13 06:48:36 -0400372 operators in that their effects are applied at variable
373 expansion time rather than being immediately applied.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500374 Here are some examples:
375 <literallayout class='monospaced'>
376 B = "bval"
377 B_append = " additional data"
378 C = "cval"
379 C_prepend = "additional data "
380 D = "dval"
381 D_append = "additional data"
382 </literallayout>
383 The variable <filename>B</filename> becomes
384 "bval additional data" and <filename>C</filename> becomes
385 "additional data cval".
386 The variable <filename>D</filename> becomes
387 "dvaladditional data".
388 <note>
389 You must control all spacing when you use the
390 override syntax.
391 </note>
392 </para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393
394 <para>
395 It is also possible to append and prepend to shell
396 functions and BitBake-style Python functions.
397 See the
398 "<link linkend='shell-functions'>Shell Functions</link>" and
399 "<link linkend='bitbake-style-python-functions'>BitBake-Style Python Functions</link>
400 sections for examples.
401 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402 </section>
403
404 <section id='removing-override-style-syntax'>
405 <title>Removal (Override Style Syntax)</title>
406
407 <para>
408 You can remove values from lists using the removal
409 override style syntax.
410 Specifying a value for removal causes all occurrences of that
411 value to be removed from the variable.
412 </para>
413
414 <para>
415 When you use this syntax, BitBake expects one or more strings.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800416 Surrounding spaces and spacing are preserved.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500417 Here is an example:
418 <literallayout class='monospaced'>
419 FOO = "123 456 789 123456 123 456 123 456"
420 FOO_remove = "123"
421 FOO_remove = "456"
Brad Bishop79641f22019-09-10 07:20:22 -0400422 FOO2 = " abc def ghi abcdef abc def abc def def"
423 FOO2_remove = " \
424 def \
425 abc \
426 ghi \
427 "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500428 </literallayout>
429 The variable <filename>FOO</filename> becomes
Brad Bishop79641f22019-09-10 07:20:22 -0400430 "&nbsp;&nbsp;789&nbsp;123456&nbsp;&nbsp;&nbsp;&nbsp;"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800431 and <filename>FOO2</filename> becomes
Brad Bishop79641f22019-09-10 07:20:22 -0400432 "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;jkl&nbsp;&nbsp;abcdef&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433 </para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600434
435 <para>
436 Like "_append" and "_prepend", "_remove"
Brad Bishopacc069e2019-09-13 06:48:36 -0400437 is applied at variable expansion time.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600438 </para>
439 </section>
440
441 <section id='override-style-operation-advantages'>
442 <title>Override Style Operation Advantages</title>
443
444 <para>
445 An advantage of the override style operations
446 "_append", "_prepend", and "_remove" as compared to the
447 "+=" and "=+" operators is that the override style
448 operators provide guaranteed operations.
449 For example, consider a class <filename>foo.bbclass</filename>
450 that needs to add the value "val" to the variable
451 <filename>FOO</filename>, and a recipe that uses
452 <filename>foo.bbclass</filename> as follows:
453 <literallayout class='monospaced'>
454 inherit foo
455
456 FOO = "initial"
457 </literallayout>
458 If <filename>foo.bbclass</filename> uses the "+=" operator,
459 as follows, then the final value of <filename>FOO</filename>
460 will be "initial", which is not what is desired:
461 <literallayout class='monospaced'>
462 FOO += "val"
463 </literallayout>
464 If, on the other hand, <filename>foo.bbclass</filename>
465 uses the "_append" operator, then the final value of
466 <filename>FOO</filename> will be "initial val", as intended:
467 <literallayout class='monospaced'>
468 FOO_append = " val"
469 </literallayout>
470 <note>
471 It is never necessary to use "+=" together with "_append".
472 The following sequence of assignments appends "barbaz" to
473 <filename>FOO</filename>:
474 <literallayout class='monospaced'>
475 FOO_append = "bar"
476 FOO_append = "baz"
477 </literallayout>
478 The only effect of changing the second assignment in the
479 previous example to use "+=" would be to add a space before
480 "baz" in the appended value (due to how the "+=" operator
481 works).
482 </note>
483 Another advantage of the override style operations is that
484 you can combine them with other overrides as described in the
485 "<link linkend='conditional-syntax-overrides'>Conditional Syntax (Overrides)</link>"
486 section.
487 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500488 </section>
489
490 <section id='variable-flag-syntax'>
491 <title>Variable Flag Syntax</title>
492
493 <para>
494 Variable flags are BitBake's implementation of variable properties
495 or attributes.
496 It is a way of tagging extra information onto a variable.
497 You can find more out about variable flags in general in the
498 "<link linkend='variable-flags'>Variable Flags</link>"
499 section.
500 </para>
501
502 <para>
503 You can define, append, and prepend values to variable flags.
504 All the standard syntax operations previously mentioned work
505 for variable flags except for override style syntax
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600506 (i.e. "_prepend", "_append", and "_remove").
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500507 </para>
508
509 <para>
510 Here are some examples showing how to set variable flags:
511 <literallayout class='monospaced'>
512 FOO[a] = "abc"
513 FOO[b] = "123"
514 FOO[a] += "456"
515 </literallayout>
516 The variable <filename>FOO</filename> has two flags:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600517 <filename>[a]</filename> and <filename>[b]</filename>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500518 The flags are immediately set to "abc" and "123", respectively.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600519 The <filename>[a]</filename> flag becomes "abc 456".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500520 </para>
521
522 <para>
523 No need exists to pre-define variable flags.
524 You can simply start using them.
525 One extremely common application
526 is to attach some brief documentation to a BitBake variable as
527 follows:
528 <literallayout class='monospaced'>
529 CACHE[doc] = "The directory holding the cache of the metadata."
530 </literallayout>
531 </para>
532 </section>
533
534 <section id='inline-python-variable-expansion'>
535 <title>Inline Python Variable Expansion</title>
536
537 <para>
538 You can use inline Python variable expansion to
539 set variables.
540 Here is an example:
541 <literallayout class='monospaced'>
542 DATE = "${@time.strftime('%Y%m%d',time.gmtime())}"
543 </literallayout>
544 This example results in the <filename>DATE</filename>
545 variable being set to the current date.
546 </para>
547
548 <para>
549 Probably the most common use of this feature is to extract
550 the value of variables from BitBake's internal data dictionary,
551 <filename>d</filename>.
552 The following lines select the values of a package name
553 and its version number, respectively:
554 <literallayout class='monospaced'>
555 PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[0] or 'defaultpkgname'}"
556 PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE', False),d)[1] or '1.0'}"
557 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600558 <note>
559 Inline Python expressions work just like variable expansions
560 insofar as the "=" and ":=" operators are concerned.
561 Given the following assignment, <filename>foo()</filename>
562 is called each time <filename>FOO</filename> is expanded:
563 <literallayout class='monospaced'>
564 FOO = "${@foo()}"
565 </literallayout>
566 Contrast this with the following immediate assignment, where
567 <filename>foo()</filename> is only called once, while the
568 assignment is parsed:
569 <literallayout class='monospaced'>
570 FOO := "${@foo()}"
571 </literallayout>
572 </note>
573 For a different way to set variables with Python code during
574 parsing, see the
575 "<link linkend='anonymous-python-functions'>Anonymous Python Functions</link>"
576 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500577 </para>
578 </section>
579
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600580 <section id='unsetting-variables'>
Brad Bishopb1114e52019-02-13 07:56:10 -0500581 <title>Unsetting variables</title>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600582
583 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500584 It is possible to completely remove a variable or a variable flag
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600585 from BitBake's internal data dictionary by using the "unset" keyword.
586 Here is an example:
587 <literallayout class='monospaced'>
588 unset DATE
589 unset do_fetch[noexec]
590 </literallayout>
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500591 These two statements remove the <filename>DATE</filename> and the
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600592 <filename>do_fetch[noexec]</filename> flag.
593 </para>
594
595 </section>
596
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500597 <section id='providing-pathnames'>
598 <title>Providing Pathnames</title>
599
600 <para>
601 When specifying pathnames for use with BitBake,
602 do not use the tilde ("~") character as a shortcut
603 for your home directory.
604 Doing so might cause BitBake to not recognize the
605 path since BitBake does not expand this character in
606 the same way a shell would.
607 </para>
608
609 <para>
610 Instead, provide a fuller path as the following
611 example illustrates:
612 <literallayout class='monospaced'>
613 BBLAYERS ?= " \
614 /home/scott-lenovo/LayerA \
615 "
616 </literallayout>
617 </para>
618 </section>
619 </section>
620
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600621 <section id='exporting-variables-to-the-environment'>
622 <title>Exporting Variables to the Environment</title>
623
624 <para>
625 You can export variables to the environment of running
626 tasks by using the <filename>export</filename> keyword.
627 For example, in the following example, the
628 <filename>do_foo</filename> task prints "value from
629 the environment" when run:
630 <literallayout class='monospaced'>
631 export ENV_VARIABLE
632 ENV_VARIABLE = "value from the environment"
633
634 do_foo() {
635 bbplain "$ENV_VARIABLE"
636 }
637 </literallayout>
638 <note>
639 BitBake does not expand <filename>$ENV_VARIABLE</filename>
640 in this case because it lacks the obligatory
641 <filename>{}</filename>.
642 Rather, <filename>$ENV_VARIABLE</filename> is expanded
643 by the shell.
644 </note>
645 It does not matter whether
646 <filename>export ENV_VARIABLE</filename> appears before or
647 after assignments to <filename>ENV_VARIABLE</filename>.
648 </para>
649
650 <para>
651 It is also possible to combine <filename>export</filename>
652 with setting a value for the variable.
653 Here is an example:
654 <literallayout class='monospaced'>
655 export ENV_VARIABLE = "<replaceable>variable-value</replaceable>"
656 </literallayout>
657 In the output of <filename>bitbake -e</filename>, variables
658 that are exported to the environment are preceded by "export".
659 </para>
660
661 <para>
662 Among the variables commonly exported to the environment
663 are <filename>CC</filename> and <filename>CFLAGS</filename>,
664 which are picked up by many build systems.
665 </para>
666 </section>
667
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500668 <section id='conditional-syntax-overrides'>
669 <title>Conditional Syntax (Overrides)</title>
670
671 <para>
672 BitBake uses
Brad Bishop19323692019-04-05 15:28:33 -0400673 <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500674 to control what variables are overridden after BitBake
675 parses recipes and configuration files.
676 This section describes how you can use
677 <filename>OVERRIDES</filename> as conditional metadata,
678 talks about key expansion in relationship to
679 <filename>OVERRIDES</filename>, and provides some examples
680 to help with understanding.
681 </para>
682
683 <section id='conditional-metadata'>
684 <title>Conditional Metadata</title>
685
686 <para>
687 You can use <filename>OVERRIDES</filename> to conditionally select
688 a specific version of a variable and to conditionally
689 append or prepend the value of a variable.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500690 <note>
691 Overrides can only use lower-case characters.
692 Additionally, underscores are not permitted in override names
693 as they are used to separate overrides from each other and
694 from the variable name.
695 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500696 <itemizedlist>
697 <listitem><para><emphasis>Selecting a Variable:</emphasis>
698 The <filename>OVERRIDES</filename> variable is
699 a colon-character-separated list that contains items
700 for which you want to satisfy conditions.
701 Thus, if you have a variable that is conditional on “arm”, and “arm”
702 is in <filename>OVERRIDES</filename>, then the “arm”-specific
703 version of the variable is used rather than the non-conditional
704 version.
705 Here is an example:
706 <literallayout class='monospaced'>
707 OVERRIDES = "architecture:os:machine"
708 TEST = "default"
709 TEST_os = "osspecific"
710 TEST_nooverride = "othercondvalue"
711 </literallayout>
712 In this example, the <filename>OVERRIDES</filename>
713 variable lists three overrides:
714 "architecture", "os", and "machine".
715 The variable <filename>TEST</filename> by itself has a default
716 value of "default".
717 You select the os-specific version of the <filename>TEST</filename>
718 variable by appending the "os" override to the variable
719 (i.e.<filename>TEST_os</filename>).
720 </para>
721
722 <para>
723 To better understand this, consider a practical example
724 that assumes an OpenEmbedded metadata-based Linux
725 kernel recipe file.
726 The following lines from the recipe file first set
727 the kernel branch variable <filename>KBRANCH</filename>
728 to a default value, then conditionally override that
729 value based on the architecture of the build:
730 <literallayout class='monospaced'>
731 KBRANCH = "standard/base"
732 KBRANCH_qemuarm = "standard/arm-versatile-926ejs"
733 KBRANCH_qemumips = "standard/mti-malta32"
734 KBRANCH_qemuppc = "standard/qemuppc"
735 KBRANCH_qemux86 = "standard/common-pc/base"
736 KBRANCH_qemux86-64 = "standard/common-pc-64/base"
737 KBRANCH_qemumips64 = "standard/mti-malta64"
738 </literallayout>
739 </para></listitem>
740 <listitem><para><emphasis>Appending and Prepending:</emphasis>
741 BitBake also supports append and prepend operations to
742 variable values based on whether a specific item is
743 listed in <filename>OVERRIDES</filename>.
744 Here is an example:
745 <literallayout class='monospaced'>
746 DEPENDS = "glibc ncurses"
747 OVERRIDES = "machine:local"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500748 DEPENDS_append_machine = " libmad"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500749 </literallayout>
750 In this example, <filename>DEPENDS</filename> becomes
751 "glibc ncurses libmad".
752 </para>
753
754 <para>
755 Again, using an OpenEmbedded metadata-based
756 kernel recipe file as an example, the
757 following lines will conditionally append to the
758 <filename>KERNEL_FEATURES</filename> variable based
759 on the architecture:
760 <literallayout class='monospaced'>
761 KERNEL_FEATURES_append = " ${KERNEL_EXTRA_FEATURES}"
762 KERNEL_FEATURES_append_qemux86=" cfg/sound.scc cfg/paravirt_kvm.scc"
763 KERNEL_FEATURES_append_qemux86-64=" cfg/sound.scc cfg/paravirt_kvm.scc"
764 </literallayout>
765 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600766 <listitem><para><emphasis>Setting a Variable for a Single Task:</emphasis>
767 BitBake supports setting a variable just for the
768 duration of a single task.
769 Here is an example:
770 <literallayout class='monospaced'>
771 FOO_task-configure = "val 1"
772 FOO_task-compile = "val 2"
773 </literallayout>
774 In the previous example, <filename>FOO</filename>
775 has the value "val 1" while the
776 <filename>do_configure</filename> task is executed,
777 and the value "val 2" while the
778 <filename>do_compile</filename> task is executed.
779 </para>
780
781 <para>Internally, this is implemented by prepending
782 the task (e.g. "task-compile:") to the value of
Brad Bishop19323692019-04-05 15:28:33 -0400783 <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link>
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600784 for the local datastore of the <filename>do_compile</filename>
785 task.</para>
786
787 <para>You can also use this syntax with other combinations
788 (e.g. "<filename>_prepend</filename>") as shown in the
789 following example:
790 <literallayout class='monospaced'>
791 EXTRA_OEMAKE_prepend_task-compile = "${PARALLEL_MAKE} "
792 </literallayout>
793 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500794 </itemizedlist>
795 </para>
796 </section>
797
798 <section id='key-expansion'>
799 <title>Key Expansion</title>
800
801 <para>
Brad Bishopacc069e2019-09-13 06:48:36 -0400802 Key expansion happens when the BitBake datastore is finalized.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500803 To better understand this, consider the following example:
804 <literallayout class='monospaced'>
805 A${B} = "X"
806 B = "2"
807 A2 = "Y"
808 </literallayout>
Brad Bishopacc069e2019-09-13 06:48:36 -0400809 In this case, after all the parsing is complete,
810 BitBake expands <filename>${B}</filename> into "2".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500811 This expansion causes <filename>A2</filename>, which was
812 set to "Y" before the expansion, to become "X".
813 </para>
814 </section>
815
816 <section id='variable-interaction-worked-examples'>
817 <title>Examples</title>
818
819 <para>
820 Despite the previous explanations that show the different forms of
821 variable definitions, it can be hard to work
822 out exactly what happens when variable operators, conditional
823 overrides, and unconditional overrides are combined.
824 This section presents some common scenarios along
825 with explanations for variable interactions that
826 typically confuse users.
827 </para>
828
829 <para>
830 There is often confusion concerning the order in which
831 overrides and various "append" operators take effect.
832 Recall that an append or prepend operation using "_append"
833 and "_prepend" does not result in an immediate assignment
834 as would "+=", ".=", "=+", or "=.".
835 Consider the following example:
836 <literallayout class='monospaced'>
837 OVERRIDES = "foo"
838 A = "Z"
839 A_foo_append = "X"
840 </literallayout>
841 For this case, <filename>A</filename> is
842 unconditionally set to "Z" and "X" is
843 unconditionally and immediately appended to the variable
844 <filename>A_foo</filename>.
845 Because overrides have not been applied yet,
846 <filename>A_foo</filename> is set to "X" due to the append
847 and <filename>A</filename> simply equals "Z".
848 </para>
849
850 <para>
851 Applying overrides, however, changes things.
852 Since "foo" is listed in <filename>OVERRIDES</filename>,
853 the conditional variable <filename>A</filename> is replaced
854 with the "foo" version, which is equal to "X".
855 So effectively, <filename>A_foo</filename> replaces <filename>A</filename>.
856 </para>
857
858 <para>
859 This next example changes the order of the override and
860 the append:
861 <literallayout class='monospaced'>
862 OVERRIDES = "foo"
863 A = "Z"
864 A_append_foo = "X"
865 </literallayout>
866 For this case, before overrides are handled,
867 <filename>A</filename> is set to "Z" and <filename>A_append_foo</filename>
868 is set to "X".
869 Once the override for "foo" is applied, however,
870 <filename>A</filename> gets appended with "X".
871 Consequently, <filename>A</filename> becomes "ZX".
872 Notice that spaces are not appended.
873 </para>
874
875 <para>
876 This next example has the order of the appends and overrides reversed
877 back as in the first example:
878 <literallayout class='monospaced'>
879 OVERRIDES = "foo"
880 A = "Y"
881 A_foo_append = "Z"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600882 A_foo_append = "X"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500883 </literallayout>
884 For this case, before any overrides are resolved,
885 <filename>A</filename> is set to "Y" using an immediate assignment.
886 After this immediate assignment, <filename>A_foo</filename> is set
887 to "Z", and then further appended with
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600888 "X" leaving the variable set to "ZX".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500889 Finally, applying the override for "foo" results in the conditional
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600890 variable <filename>A</filename> becoming "ZX" (i.e.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500891 <filename>A</filename> is replaced with <filename>A_foo</filename>).
892 </para>
893
894 <para>
895 This final example mixes in some varying operators:
896 <literallayout class='monospaced'>
897 A = "1"
898 A_append = "2"
899 A_append = "3"
900 A += "4"
901 A .= "5"
902 </literallayout>
903 For this case, the type of append operators are affecting the
904 order of assignments as BitBake passes through the code
905 multiple times.
906 Initially, <filename>A</filename> is set to "1 45" because
907 of the three statements that use immediate operators.
908 After these assignments are made, BitBake applies the
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600909 "_append" operations.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500910 Those operations result in <filename>A</filename> becoming "1 4523".
911 </para>
912 </section>
913 </section>
914
915 <section id='sharing-functionality'>
916 <title>Sharing Functionality</title>
917
918 <para>
919 BitBake allows for metadata sharing through include files
920 (<filename>.inc</filename>) and class files
921 (<filename>.bbclass</filename>).
922 For example, suppose you have a piece of common functionality
923 such as a task definition that you want to share between
924 more than one recipe.
925 In this case, creating a <filename>.bbclass</filename>
926 file that contains the common functionality and then using
927 the <filename>inherit</filename> directive in your recipes to
928 inherit the class would be a common way to share the task.
929 </para>
930
931 <para>
932 This section presents the mechanisms BitBake provides to
933 allow you to share functionality between recipes.
934 Specifically, the mechanisms include <filename>include</filename>,
935 <filename>inherit</filename>, <filename>INHERIT</filename>, and
936 <filename>require</filename> directives.
937 </para>
938
939 <section id='locating-include-and-class-files'>
940 <title>Locating Include and Class Files</title>
941
942 <para>
943 BitBake uses the
Brad Bishop19323692019-04-05 15:28:33 -0400944 <link linkend='var-bb-BBPATH'><filename>BBPATH</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500945 variable to locate needed include and class files.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500946 Additionally, BitBake searches the current directory for
947 <filename>include</filename> and <filename>require</filename>
948 directives.
949 <note>
950 The <filename>BBPATH</filename> variable is analogous to
951 the environment variable <filename>PATH</filename>.
952 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500953 </para>
954
955 <para>
956 In order for include and class files to be found by BitBake,
957 they need to be located in a "classes" subdirectory that can
958 be found in <filename>BBPATH</filename>.
959 </para>
960 </section>
961
962 <section id='inherit-directive'>
963 <title><filename>inherit</filename> Directive</title>
964
965 <para>
966 When writing a recipe or class file, you can use the
967 <filename>inherit</filename> directive to inherit the
968 functionality of a class (<filename>.bbclass</filename>).
969 BitBake only supports this directive when used within recipe
970 and class files (i.e. <filename>.bb</filename> and
971 <filename>.bbclass</filename>).
972 </para>
973
974 <para>
975 The <filename>inherit</filename> directive is a rudimentary
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500976 means of specifying functionality contained in class files
977 that your recipes require.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500978 For example, you can easily abstract out the tasks involved in
979 building a package that uses Autoconf and Automake and put
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500980 those tasks into a class file and then have your recipe
981 inherit that class file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500982 </para>
983
984 <para>
985 As an example, your recipes could use the following directive
986 to inherit an <filename>autotools.bbclass</filename> file.
987 The class file would contain common functionality for using
988 Autotools that could be shared across recipes:
989 <literallayout class='monospaced'>
990 inherit autotools
991 </literallayout>
992 In this case, BitBake would search for the directory
993 <filename>classes/autotools.bbclass</filename>
994 in <filename>BBPATH</filename>.
995 <note>
996 You can override any values and functions of the
997 inherited class within your recipe by doing so
998 after the "inherit" statement.
999 </note>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001000 If you want to use the directive to inherit
1001 multiple classes, separate them with spaces.
1002 The following example shows how to inherit both the
1003 <filename>buildhistory</filename> and <filename>rm_work</filename>
1004 classes:
1005 <literallayout class='monospaced'>
1006 inherit buildhistory rm_work
1007 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001008 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001009
1010 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001011 An advantage with the inherit directive as compared to both
1012 the
1013 <link linkend='include-directive'>include</link> and
1014 <link linkend='require-inclusion'>require</link> directives
1015 is that you can inherit class files conditionally.
1016 You can accomplish this by using a variable expression
1017 after the <filename>inherit</filename> statement.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001018 Here is an example:
1019 <literallayout class='monospaced'>
1020 inherit ${VARNAME}
1021 </literallayout>
1022 If <filename>VARNAME</filename> is going to be set, it needs
1023 to be set before the <filename>inherit</filename> statement
1024 is parsed.
1025 One way to achieve a conditional inherit in this case is to use
1026 overrides:
1027 <literallayout class='monospaced'>
1028 VARIABLE = ""
1029 VARIABLE_someoverride = "myclass"
1030 </literallayout>
1031 </para>
1032
1033 <para>
1034 Another method is by using anonymous Python.
1035 Here is an example:
1036 <literallayout class='monospaced'>
1037 python () {
1038 if condition == value:
1039 d.setVar('VARIABLE', 'myclass')
1040 else:
1041 d.setVar('VARIABLE', '')
1042 }
1043 </literallayout>
1044 </para>
1045
1046 <para>
1047 Alternatively, you could use an in-line Python expression
1048 in the following form:
1049 <literallayout class='monospaced'>
1050 inherit ${@'classname' if condition else ''}
1051 inherit ${@functionname(params)}
1052 </literallayout>
1053 In all cases, if the expression evaluates to an empty
1054 string, the statement does not trigger a syntax error
1055 because it becomes a no-op.
1056 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001057 </section>
1058
1059 <section id='include-directive'>
1060 <title><filename>include</filename> Directive</title>
1061
1062 <para>
1063 BitBake understands the <filename>include</filename>
1064 directive.
1065 This directive causes BitBake to parse whatever file you specify,
1066 and to insert that file at that location.
1067 The directive is much like its equivalent in Make except
1068 that if the path specified on the include line is a relative
1069 path, BitBake locates the first file it can find
1070 within <filename>BBPATH</filename>.
1071 </para>
1072
1073 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001074 The include directive is a more generic method of including
1075 functionality as compared to the
1076 <link linkend='inherit-directive'>inherit</link> directive,
1077 which is restricted to class (i.e. <filename>.bbclass</filename>)
1078 files.
1079 The include directive is applicable for any other kind of
1080 shared or encapsulated functionality or configuration that
1081 does not suit a <filename>.bbclass</filename> file.
1082 </para>
1083
1084 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001085 As an example, suppose you needed a recipe to include some
1086 self-test definitions:
1087 <literallayout class='monospaced'>
1088 include test_defs.inc
1089 </literallayout>
1090 <note>
1091 The <filename>include</filename> directive does not
1092 produce an error when the file cannot be found.
1093 Consequently, it is recommended that if the file you
1094 are including is expected to exist, you should use
1095 <link linkend='require-inclusion'><filename>require</filename></link>
1096 instead of <filename>include</filename>.
1097 Doing so makes sure that an error is produced if the
1098 file cannot be found.
1099 </note>
1100 </para>
1101 </section>
1102
1103 <section id='require-inclusion'>
1104 <title><filename>require</filename> Directive</title>
1105
1106 <para>
1107 BitBake understands the <filename>require</filename>
1108 directive.
1109 This directive behaves just like the
1110 <filename>include</filename> directive with the exception that
1111 BitBake raises a parsing error if the file to be included cannot
1112 be found.
1113 Thus, any file you require is inserted into the file that is
1114 being parsed at the location of the directive.
1115 </para>
1116
1117 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001118 The require directive, like the include directive previously
1119 described, is a more generic method of including
1120 functionality as compared to the
1121 <link linkend='inherit-directive'>inherit</link> directive,
1122 which is restricted to class (i.e. <filename>.bbclass</filename>)
1123 files.
1124 The require directive is applicable for any other kind of
1125 shared or encapsulated functionality or configuration that
1126 does not suit a <filename>.bbclass</filename> file.
1127 </para>
1128
1129 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001130 Similar to how BitBake handles
1131 <link linkend='include-directive'><filename>include</filename></link>,
1132 if the path specified
1133 on the require line is a relative path, BitBake locates
1134 the first file it can find within <filename>BBPATH</filename>.
1135 </para>
1136
1137 <para>
1138 As an example, suppose you have two versions of a recipe
1139 (e.g. <filename>foo_1.2.2.bb</filename> and
1140 <filename>foo_2.0.0.bb</filename>) where
1141 each version contains some identical functionality that could be
1142 shared.
1143 You could create an include file named <filename>foo.inc</filename>
1144 that contains the common definitions needed to build "foo".
1145 You need to be sure <filename>foo.inc</filename> is located in the
1146 same directory as your two recipe files as well.
1147 Once these conditions are set up, you can share the functionality
1148 using a <filename>require</filename> directive from within each
1149 recipe:
1150 <literallayout class='monospaced'>
1151 require foo.inc
1152 </literallayout>
1153 </para>
1154 </section>
1155
1156 <section id='inherit-configuration-directive'>
1157 <title><filename>INHERIT</filename> Configuration Directive</title>
1158
1159 <para>
1160 When creating a configuration file (<filename>.conf</filename>),
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001161 you can use the
Brad Bishop19323692019-04-05 15:28:33 -04001162 <link linkend='var-bb-INHERIT'><filename>INHERIT</filename></link>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001163 configuration directive to inherit a class.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001164 BitBake only supports this directive when used within
1165 a configuration file.
1166 </para>
1167
1168 <para>
1169 As an example, suppose you needed to inherit a class
1170 file called <filename>abc.bbclass</filename> from a
1171 configuration file as follows:
1172 <literallayout class='monospaced'>
1173 INHERIT += "abc"
1174 </literallayout>
1175 This configuration directive causes the named
1176 class to be inherited at the point of the directive
1177 during parsing.
1178 As with the <filename>inherit</filename> directive, the
1179 <filename>.bbclass</filename> file must be located in a
1180 "classes" subdirectory in one of the directories specified
1181 in <filename>BBPATH</filename>.
1182 <note>
1183 Because <filename>.conf</filename> files are parsed
1184 first during BitBake's execution, using
1185 <filename>INHERIT</filename> to inherit a class effectively
1186 inherits the class globally (i.e. for all recipes).
1187 </note>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001188 If you want to use the directive to inherit
1189 multiple classes, you can provide them on the same line in the
1190 <filename>local.conf</filename> file.
1191 Use spaces to separate the classes.
1192 The following example shows how to inherit both the
1193 <filename>autotools</filename> and <filename>pkgconfig</filename>
1194 classes:
1195 <literallayout class='monospaced'>
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001196 INHERIT += "autotools pkgconfig"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001197 </literallayout>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001198 </para>
1199 </section>
1200 </section>
1201
1202 <section id='functions'>
1203 <title>Functions</title>
1204
1205 <para>
1206 As with most languages, functions are the building blocks that
1207 are used to build up operations into tasks.
1208 BitBake supports these types of functions:
1209 <itemizedlist>
1210 <listitem><para><emphasis>Shell Functions:</emphasis>
1211 Functions written in shell script and executed either
1212 directly as functions, tasks, or both.
1213 They can also be called by other shell functions.
1214 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001215 <listitem><para><emphasis>BitBake-Style Python Functions:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001216 Functions written in Python and executed by BitBake or other
1217 Python functions using <filename>bb.build.exec_func()</filename>.
1218 </para></listitem>
1219 <listitem><para><emphasis>Python Functions:</emphasis>
1220 Functions written in Python and executed by Python.
1221 </para></listitem>
1222 <listitem><para><emphasis>Anonymous Python Functions:</emphasis>
1223 Python functions executed automatically during
1224 parsing.
1225 </para></listitem>
1226 </itemizedlist>
1227 Regardless of the type of function, you can only
1228 define them in class (<filename>.bbclass</filename>)
1229 and recipe (<filename>.bb</filename> or <filename>.inc</filename>)
1230 files.
1231 </para>
1232
1233 <section id='shell-functions'>
1234 <title>Shell Functions</title>
1235
1236 <para>
1237 Functions written in shell script and executed either
1238 directly as functions, tasks, or both.
1239 They can also be called by other shell functions.
1240 Here is an example shell function definition:
1241 <literallayout class='monospaced'>
1242 some_function () {
1243 echo "Hello World"
1244 }
1245 </literallayout>
1246 When you create these types of functions in your recipe
1247 or class files, you need to follow the shell programming
1248 rules.
1249 The scripts are executed by <filename>/bin/sh</filename>,
1250 which may not be a bash shell but might be something
1251 such as <filename>dash</filename>.
1252 You should not use Bash-specific script (bashisms).
1253 </para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001254
1255 <para>
1256 Overrides and override-style operators like
1257 <filename>_append</filename> and
1258 <filename>_prepend</filename> can also be applied to
1259 shell functions.
1260 Most commonly, this application would be used in a
1261 <filename>.bbappend</filename> file to modify functions in
1262 the main recipe.
1263 It can also be used to modify functions inherited from
1264 classes.
1265 </para>
1266
1267 <para>
1268 As an example, consider the following:
1269 <literallayout class='monospaced'>
1270 do_foo() {
1271 bbplain first
1272 fn
1273 }
1274
1275 fn_prepend() {
1276 bbplain second
1277 }
1278
1279 fn() {
1280 bbplain third
1281 }
1282
1283 do_foo_append() {
1284 bbplain fourth
1285 }
1286 </literallayout>
1287 Running <filename>do_foo</filename>
1288 prints the following:
1289 <literallayout class='monospaced'>
1290 recipename do_foo: first
1291 recipename do_foo: second
1292 recipename do_foo: third
1293 recipename do_foo: fourth
1294 </literallayout>
1295 <note>
1296 Overrides and override-style operators can
1297 be applied to any shell function, not just
1298 <link linkend='tasks'>tasks</link>.
1299 </note>
1300 You can use the <filename>bitbake -e</filename>&nbsp;<replaceable>recipename</replaceable>
1301 command to view the final assembled function
1302 after all overrides have been applied.
1303 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001304 </section>
1305
1306 <section id='bitbake-style-python-functions'>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001307 <title>BitBake-Style Python Functions</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001308
1309 <para>
1310 These functions are written in Python and executed by
1311 BitBake or other Python functions using
1312 <filename>bb.build.exec_func()</filename>.
1313 </para>
1314
1315 <para>
1316 An example BitBake function is:
1317 <literallayout class='monospaced'>
1318 python some_python_function () {
1319 d.setVar("TEXT", "Hello World")
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001320 print d.getVar("TEXT")
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001321 }
1322 </literallayout>
1323 Because the Python "bb" and "os" modules are already
1324 imported, you do not need to import these modules.
1325 Also in these types of functions, the datastore ("d")
1326 is a global variable and is always automatically
1327 available.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001328 <note>
1329 Variable expressions (e.g. <filename>${X}</filename>)
1330 are no longer expanded within Python functions.
1331 This behavior is intentional in order to allow you
1332 to freely set variable values to expandable expressions
1333 without having them expanded prematurely.
1334 If you do wish to expand a variable within a Python
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001335 function, use <filename>d.getVar("X")</filename>.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001336 Or, for more complicated expressions, use
1337 <filename>d.expand()</filename>.
1338 </note>
1339 </para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001340
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001341 <para>
1342 Similar to shell functions, you can also apply overrides
1343 and override-style operators to BitBake-style Python
1344 functions.
1345 </para>
1346
1347 <para>
1348 As an example, consider the following:
1349 <literallayout class='monospaced'>
1350 python do_foo_prepend() {
1351 bb.plain("first")
1352 }
1353
1354 python do_foo() {
1355 bb.plain("second")
1356 }
1357
1358 python do_foo_append() {
1359 bb.plain("third")
1360 }
1361 </literallayout>
1362 Running <filename>do_foo</filename> prints
1363 the following:
1364 <literallayout class='monospaced'>
1365 recipename do_foo: first
1366 recipename do_foo: second
1367 recipename do_foo: third
1368 </literallayout>
1369 You can use the <filename>bitbake -e</filename>&nbsp;<replaceable>recipename</replaceable>
1370 command to view the final assembled function
1371 after all overrides have been applied.
1372 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001373 </section>
1374
1375 <section id='python-functions'>
1376 <title>Python Functions</title>
1377
1378 <para>
1379 These functions are written in Python and are executed by
1380 other Python code.
1381 Examples of Python functions are utility functions
1382 that you intend to call from in-line Python or
1383 from within other Python functions.
1384 Here is an example:
1385 <literallayout class='monospaced'>
1386 def get_depends(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001387 if d.getVar('SOMECONDITION'):
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001388 return "dependencywithcond"
1389 else:
1390 return "dependency"
1391 SOMECONDITION = "1"
1392 DEPENDS = "${@get_depends(d)}"
1393 </literallayout>
1394 This would result in <filename>DEPENDS</filename>
1395 containing <filename>dependencywithcond</filename>.
1396 </para>
1397
1398 <para>
1399 Here are some things to know about Python functions:
1400 <itemizedlist>
1401 <listitem><para>Python functions can take parameters.
1402 </para></listitem>
1403 <listitem><para>The BitBake datastore is not
1404 automatically available.
1405 Consequently, you must pass it in as a
1406 parameter to the function.
1407 </para></listitem>
1408 <listitem><para>The "bb" and "os" Python modules are
1409 automatically available.
1410 You do not need to import them.
1411 </para></listitem>
1412 </itemizedlist>
1413 </para>
1414 </section>
1415
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001416 <section id='bitbake-style-python-functions-versus-python-functions'>
1417 <title>Bitbake-Style Python Functions Versus Python Functions</title>
1418
1419 <para>
1420 Following are some important differences between
1421 BitBake-style Python functions and regular Python
1422 functions defined with "def":
1423 <itemizedlist>
1424 <listitem><para>
1425 Only BitBake-style Python functions can be
1426 <link linkend='tasks'>tasks</link>.
1427 </para></listitem>
1428 <listitem><para>
1429 Overrides and override-style operators can only
1430 be applied to BitBake-style Python functions.
1431 </para></listitem>
1432 <listitem><para>
1433 Only regular Python functions can take arguments
1434 and return values.
1435 </para></listitem>
1436 <listitem><para>
1437 <link linkend='variable-flags'>Variable flags</link>
1438 such as <filename>[dirs]</filename>,
1439 <filename>[cleandirs]</filename>, and
1440 <filename>[lockfiles]</filename> can be used
1441 on BitBake-style Python functions, but not on
1442 regular Python functions.
1443 </para></listitem>
1444 <listitem><para>
1445 BitBake-style Python functions generate a separate
Brad Bishop19323692019-04-05 15:28:33 -04001446 <filename>${</filename><link linkend='var-bb-T'><filename>T</filename></link><filename>}/run.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001447 script that is executed to run the function, and also
1448 generate a log file in
1449 <filename>${T}/log.</filename><replaceable>function-name</replaceable><filename>.</filename><replaceable>pid</replaceable>
1450 if they are executed as tasks.</para>
1451
1452 <para>
1453 Regular Python functions execute "inline" and do not
1454 generate any files in <filename>${T}</filename>.
1455 </para></listitem>
1456 <listitem><para>
1457 Regular Python functions are called with the usual
1458 Python syntax.
1459 BitBake-style Python functions are usually tasks and
1460 are called directly by BitBake, but can also be called
1461 manually from Python code by using the
1462 <filename>bb.build.exec_func()</filename> function.
1463 Here is an example:
1464 <literallayout class='monospaced'>
1465 bb.build.exec_func("my_bitbake_style_function", d)
1466 </literallayout>
1467 <note>
1468 <filename>bb.build.exec_func()</filename> can also
1469 be used to run shell functions from Python code.
1470 If you want to run a shell function before a Python
1471 function within the same task, then you can use a
1472 parent helper Python function that starts by running
1473 the shell function with
1474 <filename>bb.build.exec_func()</filename> and then
1475 runs the Python code.
1476 </note></para>
1477
1478 <para>To detect errors from functions executed with
1479 <filename>bb.build.exec_func()</filename>, you
1480 can catch the <filename>bb.build.FuncFailed</filename>
1481 exception.
1482 <note>
1483 Functions in metadata (recipes and classes) should
1484 not themselves raise
1485 <filename>bb.build.FuncFailed</filename>.
1486 Rather, <filename>bb.build.FuncFailed</filename>
1487 should be viewed as a general indicator that the
1488 called function failed by raising an exception.
1489 For example, an exception raised by
1490 <filename>bb.fatal()</filename> will be caught inside
1491 <filename>bb.build.exec_func()</filename>, and a
1492 <filename>bb.build.FuncFailed</filename> will be raised
1493 in response.
1494 </note>
1495 </para></listitem>
1496 </itemizedlist>
1497 </para>
1498
1499 <para>
1500 Due to their simplicity, you should prefer regular Python functions
1501 over BitBake-style Python functions unless you need a feature specific
1502 to BitBake-style Python functions.
1503 Regular Python functions in metadata are a more recent invention than
1504 BitBake-style Python functions, and older code tends to use
1505 <filename>bb.build.exec_func()</filename> more often.
1506 </para>
1507 </section>
1508
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001509 <section id='anonymous-python-functions'>
1510 <title>Anonymous Python Functions</title>
1511
1512 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001513 Sometimes it is useful to set variables or perform
1514 other operations programmatically during parsing.
1515 To do this, you can define special Python functions,
1516 called anonymous Python functions, that run at the
1517 end of parsing.
1518 For example, the following conditionally sets a variable
1519 based on the value of another variable:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001520 <literallayout class='monospaced'>
1521 python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001522 if d.getVar('SOMEVAR') == 'value':
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001523 d.setVar('ANOTHERVAR', 'value2')
1524 }
1525 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001526 An equivalent way to mark a function as an anonymous
1527 function is to give it the name "__anonymous", rather
1528 than no name.
1529 </para>
1530
1531 <para>
1532 Anonymous Python functions always run at the end
1533 of parsing, regardless of where they are defined.
1534 If a recipe contains many anonymous functions, they
1535 run in the same order as they are defined within the
1536 recipe.
1537 As an example, consider the following snippet:
1538 <literallayout class='monospaced'>
1539 python () {
1540 d.setVar('FOO', 'foo 2')
1541 }
1542
1543 FOO = "foo 1"
1544
1545 python () {
1546 d.appendVar('BAR', ' bar 2')
1547 }
1548
1549 BAR = "bar 1"
1550 </literallayout>
1551 The previous example is conceptually equivalent to the
1552 following snippet:
1553 <literallayout class='monospaced'>
1554 FOO = "foo 1"
1555 BAR = "bar 1"
1556 FOO = "foo 2"
1557 BAR += "bar 2"
1558 </literallayout>
1559 <filename>FOO</filename> ends up with the value "foo 2",
1560 and <filename>BAR</filename> with the value "bar 1 bar 2".
1561 Just as in the second snippet, the values set for the
1562 variables within the anonymous functions become available
1563 to tasks, which always run after parsing.
1564 </para>
1565
1566 <para>
1567 Overrides and override-style operators such as
1568 "<filename>_append</filename>" are applied before
1569 anonymous functions run.
1570 In the following example, <filename>FOO</filename> ends
1571 up with the value "foo from anonymous":
1572 <literallayout class='monospaced'>
1573 FOO = "foo"
1574 FOO_append = " from outside"
1575
1576 python () {
1577 d.setVar("FOO", "foo from anonymous")
1578 }
1579 </literallayout>
1580 For methods you can use with anonymous Python functions,
1581 see the
1582 "<link linkend='functions-you-can-call-from-within-python'>Functions You Can Call From Within Python</link>"
1583 section.
1584 For a different method to run Python code during parsing,
1585 see the
1586 "<link linkend='inline-python-variable-expansion'>Inline Python Variable Expansion</link>"
1587 section.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001588 </para>
1589 </section>
1590
1591 <section id='flexible-inheritance-for-class-functions'>
1592 <title>Flexible Inheritance for Class Functions</title>
1593
1594 <para>
1595 Through coding techniques and the use of
1596 <filename>EXPORT_FUNCTIONS</filename>, BitBake supports
1597 exporting a function from a class such that the
1598 class function appears as the default implementation
1599 of the function, but can still be called if a recipe
1600 inheriting the class needs to define its own version of
1601 the function.
1602 </para>
1603
1604 <para>
1605 To understand the benefits of this feature, consider
1606 the basic scenario where a class defines a task function
1607 and your recipe inherits the class.
1608 In this basic scenario, your recipe inherits the task
1609 function as defined in the class.
1610 If desired, your recipe can add to the start and end of the
1611 function by using the "_prepend" or "_append" operations
1612 respectively, or it can redefine the function completely.
1613 However, if it redefines the function, there is
1614 no means for it to call the class version of the function.
1615 <filename>EXPORT_FUNCTIONS</filename> provides a mechanism
1616 that enables the recipe's version of the function to call
1617 the original version of the function.
1618 </para>
1619
1620 <para>
1621 To make use of this technique, you need the following
1622 things in place:
1623 <itemizedlist>
1624 <listitem><para>
1625 The class needs to define the function as follows:
1626 <literallayout class='monospaced'>
1627 <replaceable>classname</replaceable><filename>_</filename><replaceable>functionname</replaceable>
1628 </literallayout>
1629 For example, if you have a class file
1630 <filename>bar.bbclass</filename> and a function named
1631 <filename>do_foo</filename>, the class must define the function
1632 as follows:
1633 <literallayout class='monospaced'>
1634 bar_do_foo
1635 </literallayout>
1636 </para></listitem>
1637 <listitem><para>
1638 The class needs to contain the <filename>EXPORT_FUNCTIONS</filename>
1639 statement as follows:
1640 <literallayout class='monospaced'>
1641 EXPORT_FUNCTIONS <replaceable>functionname</replaceable>
1642 </literallayout>
1643 For example, continuing with the same example, the
1644 statement in the <filename>bar.bbclass</filename> would be
1645 as follows:
1646 <literallayout class='monospaced'>
1647 EXPORT_FUNCTIONS do_foo
1648 </literallayout>
1649 </para></listitem>
1650 <listitem><para>
1651 You need to call the function appropriately from within your
1652 recipe.
1653 Continuing with the same example, if your recipe
1654 needs to call the class version of the function,
1655 it should call <filename>bar_do_foo</filename>.
1656 Assuming <filename>do_foo</filename> was a shell function
1657 and <filename>EXPORT_FUNCTIONS</filename> was used as above,
1658 the recipe's function could conditionally call the
1659 class version of the function as follows:
1660 <literallayout class='monospaced'>
1661 do_foo() {
1662 if [ somecondition ] ; then
1663 bar_do_foo
1664 else
1665 # Do something else
1666 fi
1667 }
1668 </literallayout>
1669 To call your modified version of the function as defined
1670 in your recipe, call it as <filename>do_foo</filename>.
1671 </para></listitem>
1672 </itemizedlist>
1673 With these conditions met, your single recipe
1674 can freely choose between the original function
1675 as defined in the class file and the modified function in your recipe.
1676 If you do not set up these conditions, you are limited to using one function
1677 or the other.
1678 </para>
1679 </section>
1680 </section>
1681
1682 <section id='tasks'>
1683 <title>Tasks</title>
1684
1685 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001686 Tasks are BitBake execution units that make up the
1687 steps that BitBake can run for a given recipe.
1688 Tasks are only supported in recipes and classes
1689 (i.e. in <filename>.bb</filename> files and files
1690 included or inherited from <filename>.bb</filename>
1691 files).
1692 By convention, tasks have names that start with "do_".
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001693 </para>
1694
1695 <section id='promoting-a-function-to-a-task'>
1696 <title>Promoting a Function to a Task</title>
1697
1698 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001699 Tasks are either
1700 <link linkend='shell-functions'>shell functions</link> or
1701 <link linkend='bitbake-style-python-functions'>BitBake-style Python functions</link>
1702 that have been promoted to tasks by using the
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001703 <filename>addtask</filename> command.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001704 The <filename>addtask</filename> command can also
1705 optionally describe dependencies between the
1706 task and other tasks.
1707 Here is an example that shows how to define a task
1708 and declare some dependencies:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001709 <literallayout class='monospaced'>
1710 python do_printdate () {
1711 import time
1712 print time.strftime('%Y%m%d', time.gmtime())
1713 }
1714 addtask printdate after do_fetch before do_build
1715 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001716 The first argument to <filename>addtask</filename>
1717 is the name of the function to promote to
1718 a task.
1719 If the name does not start with "do_", "do_" is
1720 implicitly added, which enforces the convention that
1721 all task names start with "do_".
1722 </para>
1723
1724 <para>
1725 In the previous example, the
1726 <filename>do_printdate</filename> task becomes a
1727 dependency of the <filename>do_build</filename>
1728 task, which is the default task (i.e. the task run by
1729 the <filename>bitbake</filename> command unless
1730 another task is specified explicitly).
1731 Additionally, the <filename>do_printdate</filename>
1732 task becomes dependent upon the
1733 <filename>do_fetch</filename> task.
1734 Running the <filename>do_build</filename> task
1735 results in the <filename>do_printdate</filename>
1736 task running first.
1737 <note>
1738 If you try out the previous example, you might see that
1739 the <filename>do_printdate</filename> task is only run
1740 the first time you build the recipe with
1741 the <filename>bitbake</filename> command.
1742 This is because BitBake considers the task "up-to-date"
1743 after that initial run.
1744 If you want to force the task to always be rerun for
1745 experimentation purposes, you can make BitBake always
1746 consider the task "out-of-date" by using the
1747 <filename>[</filename><link linkend='variable-flags'><filename>nostamp</filename></link><filename>]</filename>
1748 variable flag, as follows:
1749 <literallayout class='monospaced'>
1750 do_printdate[nostamp] = "1"
1751 </literallayout>
1752 You can also explicitly run the task and provide the
1753 <filename>-f</filename> option as follows:
1754 <literallayout class='monospaced'>
1755 $ bitbake <replaceable>recipe</replaceable> -c printdate -f
1756 </literallayout>
1757 When manually selecting a task to run with the
1758 <filename>bitbake</filename>&nbsp;<replaceable>recipe</replaceable>&nbsp;<filename>-c</filename>&nbsp;<replaceable>task</replaceable>
1759 command, you can omit the "do_" prefix as part of the
1760 task name.
1761 </note>
1762 </para>
1763
1764 <para>
1765 You might wonder about the practical effects of using
1766 <filename>addtask</filename> without specifying any
1767 dependencies as is done in the following example:
1768 <literallayout class='monospaced'>
1769 addtask printdate
1770 </literallayout>
1771 In this example, assuming dependencies have not been
1772 added through some other means, the only way to run
1773 the task is by explicitly selecting it with
1774 <filename>bitbake</filename>&nbsp;<replaceable>recipe</replaceable>&nbsp;<filename>-c printdate</filename>.
1775 You can use the
1776 <filename>do_listtasks</filename> task to list all tasks
1777 defined in a recipe as shown in the following example:
1778 <literallayout class='monospaced'>
1779 $ bitbake <replaceable>recipe</replaceable> -c listtasks
1780 </literallayout>
1781 For more information on task dependencies, see the
1782 "<link linkend='dependencies'>Dependencies</link>"
1783 section.
1784 </para>
1785
1786 <para>
1787 See the
1788 "<link linkend='variable-flags'>Variable Flags</link>"
1789 section for information on variable flags you can use with
1790 tasks.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001791 </para>
1792 </section>
1793
1794 <section id='deleting-a-task'>
1795 <title>Deleting a Task</title>
1796
1797 <para>
1798 As well as being able to add tasks, you can delete them.
1799 Simply use the <filename>deltask</filename> command to
1800 delete a task.
1801 For example, to delete the example task used in the previous
1802 sections, you would use:
1803 <literallayout class='monospaced'>
1804 deltask printdate
1805 </literallayout>
1806 If you delete a task using the <filename>deltask</filename>
1807 command and the task has dependencies, the dependencies are
1808 not reconnected.
1809 For example, suppose you have three tasks named
1810 <filename>do_a</filename>, <filename>do_b</filename>, and
1811 <filename>do_c</filename>.
1812 Furthermore, <filename>do_c</filename> is dependent on
1813 <filename>do_b</filename>, which in turn is dependent on
1814 <filename>do_a</filename>.
1815 Given this scenario, if you use <filename>deltask</filename>
1816 to delete <filename>do_b</filename>, the implicit dependency
1817 relationship between <filename>do_c</filename> and
1818 <filename>do_a</filename> through <filename>do_b</filename>
1819 no longer exists, and <filename>do_c</filename> dependencies
1820 are not updated to include <filename>do_a</filename>.
1821 Thus, <filename>do_c</filename> is free to run before
1822 <filename>do_a</filename>.
1823 </para>
1824
1825 <para>
1826 If you want dependencies such as these to remain intact, use
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001827 the <filename>[noexec]</filename> varflag to disable the task
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001828 instead of using the <filename>deltask</filename> command to
1829 delete it:
1830 <literallayout class='monospaced'>
1831 do_b[noexec] = "1"
1832 </literallayout>
1833 </para>
1834 </section>
1835
1836 <section id='passing-information-into-the-build-task-environment'>
1837 <title>Passing Information Into the Build Task Environment</title>
1838
1839 <para>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001840 When running a task, BitBake tightly controls the shell execution
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001841 environment of the build tasks to make
1842 sure unwanted contamination from the build machine cannot
1843 influence the build.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001844 <note>
1845 By default, BitBake cleans the environment to include only those
1846 things exported or listed in its whitelist to ensure that the build
1847 environment is reproducible and consistent.
1848 You can prevent this "cleaning" by setting the
Brad Bishop19323692019-04-05 15:28:33 -04001849 <link linkend='var-bb-BB_PRESERVE_ENV'><filename>BB_PRESERVE_ENV</filename></link>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001850 variable.
1851 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001852 Consequently, if you do want something to get passed into the
1853 build task environment, you must take these two steps:
1854 <orderedlist>
1855 <listitem><para>
1856 Tell BitBake to load what you want from the environment
1857 into the datastore.
1858 You can do so through the
Brad Bishop19323692019-04-05 15:28:33 -04001859 <link linkend='var-bb-BB_ENV_WHITELIST'><filename>BB_ENV_WHITELIST</filename></link>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001860 and
Brad Bishop19323692019-04-05 15:28:33 -04001861 <link linkend='var-bb-BB_ENV_EXTRAWHITE'><filename>BB_ENV_EXTRAWHITE</filename></link>
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001862 variables.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001863 For example, assume you want to prevent the build system from
1864 accessing your <filename>$HOME/.ccache</filename>
1865 directory.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001866 The following command "whitelists" the environment variable
1867 <filename>CCACHE_DIR</filename> causing BitBack to allow that
1868 variable into the datastore:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001869 <literallayout class='monospaced'>
1870 export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE CCACHE_DIR"
1871 </literallayout></para></listitem>
1872 <listitem><para>
1873 Tell BitBake to export what you have loaded into the
1874 datastore to the task environment of every running task.
1875 Loading something from the environment into the datastore
1876 (previous step) only makes it available in the datastore.
1877 To export it to the task environment of every running task,
1878 use a command similar to the following in your local configuration
1879 file <filename>local.conf</filename> or your
1880 distribution configuration file:
1881 <literallayout class='monospaced'>
1882 export CCACHE_DIR
1883 </literallayout>
1884 <note>
1885 A side effect of the previous steps is that BitBake
1886 records the variable as a dependency of the build process
1887 in things like the setscene checksums.
1888 If doing so results in unnecessary rebuilds of tasks, you can
1889 whitelist the variable so that the setscene code
1890 ignores the dependency when it creates checksums.
1891 </note></para></listitem>
1892 </orderedlist>
1893 </para>
1894
1895 <para>
1896 Sometimes, it is useful to be able to obtain information
1897 from the original execution environment.
1898 Bitbake saves a copy of the original environment into
1899 a special variable named
Brad Bishop19323692019-04-05 15:28:33 -04001900 <link linkend='var-bb-BB_ORIGENV'><filename>BB_ORIGENV</filename></link>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001901 </para>
1902
1903 <para>
1904 The <filename>BB_ORIGENV</filename> variable returns a datastore
1905 object that can be queried using the standard datastore operators
1906 such as <filename>getVar(, False)</filename>.
1907 The datastore object is useful, for example, to find the original
1908 <filename>DISPLAY</filename> variable.
1909 Here is an example:
1910 <literallayout class='monospaced'>
1911 origenv = d.getVar("BB_ORIGENV", False)
1912 bar = origenv.getVar("BAR", False)
1913 </literallayout>
1914 The previous example returns <filename>BAR</filename> from the original
1915 execution environment.
1916 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001917 </section>
1918 </section>
1919
1920 <section id='variable-flags'>
1921 <title>Variable Flags</title>
1922
1923 <para>
1924 Variable flags (varflags) help control a task's functionality
1925 and dependencies.
1926 BitBake reads and writes varflags to the datastore using the following
1927 command forms:
1928 <literallayout class='monospaced'>
1929 <replaceable>variable</replaceable> = d.getVarFlags("<replaceable>variable</replaceable>")
1930 self.d.setVarFlags("FOO", {"func": True})
1931 </literallayout>
1932 </para>
1933
1934 <para>
1935 When working with varflags, the same syntax, with the exception of
1936 overrides, applies.
1937 In other words, you can set, append, and prepend varflags just like
1938 variables.
1939 See the
1940 "<link linkend='variable-flag-syntax'>Variable Flag Syntax</link>"
1941 section for details.
1942 </para>
1943
1944 <para>
1945 BitBake has a defined set of varflags available for recipes and
1946 classes.
1947 Tasks support a number of these flags which control various
1948 functionality of the task:
1949 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001950 <listitem><para><emphasis><filename>[cleandirs]</filename>:</emphasis>
1951 Empty directories that should be created before the
1952 task runs.
1953 Directories that already exist are removed and recreated
1954 to empty them.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001955 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001956 <listitem><para><emphasis><filename>[depends]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001957 Controls inter-task dependencies.
1958 See the
Brad Bishop19323692019-04-05 15:28:33 -04001959 <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001960 variable and the
1961 "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>"
1962 section for more information.
1963 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001964 <listitem><para><emphasis><filename>[deptask]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001965 Controls task build-time dependencies.
1966 See the
Brad Bishop19323692019-04-05 15:28:33 -04001967 <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001968 variable and the
1969 "<link linkend='build-dependencies'>Build Dependencies</link>"
1970 section for more information.
1971 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001972 <listitem><para><emphasis><filename>[dirs]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001973 Directories that should be created before the task runs.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001974 Directories that already exist are left as is.
1975 The last directory listed is used as the
1976 current working directory for the task.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001977 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001978 <listitem><para><emphasis><filename>[lockfiles]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001979 Specifies one or more lockfiles to lock while the task
1980 executes.
1981 Only one task may hold a lockfile, and any task that
1982 attempts to lock an already locked file will block until
1983 the lock is released.
1984 You can use this variable flag to accomplish mutual
1985 exclusion.
1986 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001987 <listitem><para><emphasis><filename>[noexec]</filename>:</emphasis>
1988 When set to "1", marks the task as being empty, with
1989 no execution required.
1990 You can use the <filename>[noexec]</filename> flag to set up
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001991 tasks as dependency placeholders, or to disable tasks defined
1992 elsewhere that are not needed in a particular recipe.
1993 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001994 <listitem><para><emphasis><filename>[nostamp]</filename>:</emphasis>
1995 When set to "1", tells BitBake to not generate a stamp
1996 file for a task, which implies the task should always
1997 be executed.
1998 <note><title>Caution</title>
1999 Any task that depends (possibly indirectly) on a
2000 <filename>[nostamp]</filename> task will always be
2001 executed as well.
2002 This can cause unnecessary rebuilding if you are
2003 not careful.
2004 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002005 </para></listitem>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002006 <listitem><para><emphasis><filename>[number_threads]</filename>:</emphasis>
2007 Limits tasks to a specific number of simultaneous threads
2008 during execution.
2009 This varflag is useful when your build host has a large number
2010 of cores but certain tasks need to be rate-limited due to various
2011 kinds of resource constraints (e.g. to avoid network throttling).
2012 <filename>number_threads</filename> works similarly to the
Brad Bishop19323692019-04-05 15:28:33 -04002013 <link linkend='var-bb-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename></link>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002014 variable but is task-specific.</para>
2015
2016 <para>Set the value globally.
2017 For example, the following makes sure the
2018 <filename>do_fetch</filename> task uses no more than two
2019 simultaneous execution threads:
2020 <literallayout class='monospaced'>
2021 do_fetch[number_threads] = "2"
2022 </literallayout>
2023 <note><title>Warnings</title>
2024 <itemizedlist>
2025 <listitem><para>
2026 Setting the varflag in individual recipes rather
2027 than globally can result in unpredictable behavior.
2028 </para></listitem>
2029 <listitem><para>
2030 Setting the varflag to a value greater than the
2031 value used in the <filename>BB_NUMBER_THREADS</filename>
2032 variable causes <filename>number_threads</filename>
2033 to have no effect.
2034 </para></listitem>
2035 </itemizedlist>
2036 </note>
2037 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002038 <listitem><para><emphasis><filename>[postfuncs]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002039 List of functions to call after the completion of the task.
2040 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002041 <listitem><para><emphasis><filename>[prefuncs]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002042 List of functions to call before the task executes.
2043 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002044 <listitem><para><emphasis><filename>[rdepends]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002045 Controls inter-task runtime dependencies.
2046 See the
Brad Bishop19323692019-04-05 15:28:33 -04002047 <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002048 variable, the
Brad Bishop19323692019-04-05 15:28:33 -04002049 <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002050 variable, and the
2051 "<link linkend='inter-task-dependencies'>Inter-Task Dependencies</link>"
2052 section for more information.
2053 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002054 <listitem><para><emphasis><filename>[rdeptask]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002055 Controls task runtime dependencies.
2056 See the
Brad Bishop19323692019-04-05 15:28:33 -04002057 <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002058 variable, the
Brad Bishop19323692019-04-05 15:28:33 -04002059 <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002060 variable, and the
2061 "<link linkend='runtime-dependencies'>Runtime Dependencies</link>"
2062 section for more information.
2063 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002064 <listitem><para><emphasis><filename>[recideptask]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002065 When set in conjunction with
2066 <filename>recrdeptask</filename>, specifies a task that
2067 should be inspected for additional dependencies.
2068 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002069 <listitem><para><emphasis><filename>[recrdeptask]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002070 Controls task recursive runtime dependencies.
2071 See the
Brad Bishop19323692019-04-05 15:28:33 -04002072 <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002073 variable, the
Brad Bishop19323692019-04-05 15:28:33 -04002074 <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002075 variable, and the
2076 "<link linkend='recursive-dependencies'>Recursive Dependencies</link>"
2077 section for more information.
2078 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002079 <listitem><para><emphasis><filename>[stamp-extra-info]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002080 Extra stamp information to append to the task's stamp.
2081 As an example, OpenEmbedded uses this flag to allow
2082 machine-specific tasks.
2083 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002084 <listitem><para><emphasis><filename>[umask]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002085 The umask to run the task under.
2086 </para></listitem>
2087 </itemizedlist>
2088 </para>
2089
2090 <para>
2091 Several varflags are useful for controlling how signatures are
2092 calculated for variables.
2093 For more information on this process, see the
2094 "<link linkend='checksums'>Checksums (Signatures)</link>"
2095 section.
2096 <itemizedlist>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002097 <listitem><para><emphasis><filename>[vardeps]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002098 Specifies a space-separated list of additional
2099 variables to add to a variable's dependencies
2100 for the purposes of calculating its signature.
2101 Adding variables to this list is useful, for example, when
2102 a function refers to a variable in a manner that
2103 does not allow BitBake to automatically determine
2104 that the variable is referred to.
2105 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002106 <listitem><para><emphasis><filename>[vardepsexclude]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002107 Specifies a space-separated list of variables
2108 that should be excluded from a variable's dependencies
2109 for the purposes of calculating its signature.
2110 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002111 <listitem><para><emphasis><filename>[vardepvalue]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002112 If set, instructs BitBake to ignore the actual
2113 value of the variable and instead use the specified
2114 value when calculating the variable's signature.
2115 </para></listitem>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002116 <listitem><para><emphasis><filename>[vardepvalueexclude]</filename>:</emphasis>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002117 Specifies a pipe-separated list of strings to exclude
2118 from the variable's value when calculating the
2119 variable's signature.
2120 </para></listitem>
2121 </itemizedlist>
2122 </para>
2123 </section>
2124
2125 <section id='events'>
2126 <title>Events</title>
2127
2128 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002129 BitBake allows installation of event handlers within recipe
2130 and class files.
2131 Events are triggered at certain points during operation, such
2132 as the beginning of operation against a given recipe
2133 (i.e. <filename>*.bb</filename>), the start of a given task,
2134 a task failure, a task success, and so forth.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002135 The intent is to make it easy to do things like email
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002136 notification on build failures.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002137 </para>
2138
2139 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002140 Following is an example event handler that prints the name
2141 of the event and the content of the
2142 <filename>FILE</filename> variable:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002143 <literallayout class='monospaced'>
2144 addhandler myclass_eventhandler
2145 python myclass_eventhandler() {
2146 from bb.event import getName
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002147 print("The name of the Event is %s" % getName(e))
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002148 print("The file we run for is %s" % d.getVar('FILE'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002149 }
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002150 myclass_eventhandler[eventmask] = "bb.event.BuildStarted bb.event.BuildCompleted"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002151 </literallayout>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002152 In the previous example, an eventmask has been set so that
2153 the handler only sees the "BuildStarted" and "BuildCompleted"
2154 events.
2155 This event handler gets called every time an event matching
2156 the eventmask is triggered.
2157 A global variable "e" is defined, which represents the current
2158 event.
2159 With the <filename>getName(e)</filename> method, you can get
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002160 the name of the triggered event.
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002161 The global datastore is available as "d".
2162 In legacy code, you might see "e.data" used to get the datastore.
2163 However, realize that "e.data" is deprecated and you should use
2164 "d" going forward.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002165 </para>
2166
2167 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002168 The context of the datastore is appropriate to the event
2169 in question.
2170 For example, "BuildStarted" and "BuildCompleted" events run
2171 before any tasks are executed so would be in the global
2172 configuration datastore namespace.
2173 No recipe-specific metadata exists in that namespace.
Brad Bishopd7bf8c12018-02-25 22:55:05 -05002174 The "BuildStarted" and "BuildCompleted" events also run in
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002175 the main cooker/server process rather than any worker context.
2176 Thus, any changes made to the datastore would be seen by other
2177 cooker/server events within the current build but not seen
2178 outside of that build or in any worker context.
2179 Task events run in the actual tasks in question consequently
2180 have recipe-specific and task-specific contents.
2181 These events run in the worker context and are discarded at
2182 the end of task execution.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002183 </para>
2184
2185 <para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002186 During a standard build, the following common events might
2187 occur.
2188 The following events are the most common kinds of events that
2189 most metadata might have an interest in viewing:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002190 <itemizedlist>
2191 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002192 <filename>bb.event.ConfigParsed()</filename>:
2193 Fired when the base configuration; which consists of
2194 <filename>bitbake.conf</filename>,
2195 <filename>base.bbclass</filename> and any global
2196 <filename>INHERIT</filename> statements; has been parsed.
2197 You can see multiple such events when each of the
2198 workers parse the base configuration or if the server
2199 changes configuration and reparses.
2200 Any given datastore only has one such event executed
2201 against it, however.
2202 If
Brad Bishop19323692019-04-05 15:28:33 -04002203 <link linkende='var-bb-BB_INVALIDCONF'><filename>BB_INVALIDCONF</filename></link>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002204 is set in the datastore by the event handler, the
2205 configuration is reparsed and a new event triggered,
2206 allowing the metadata to update configuration.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002207 </para></listitem>
2208 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002209 <filename>bb.event.HeartbeatEvent()</filename>:
2210 Fires at regular time intervals of one second.
2211 You can configure the interval time using the
2212 <filename>BB_HEARTBEAT_EVENT</filename> variable.
2213 The event's "time" attribute is the
2214 <filename>time.time()</filename> value when the
2215 event is triggered.
2216 This event is useful for activities such as
2217 system state monitoring.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002218 </para></listitem>
2219 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002220 <filename>bb.event.ParseStarted()</filename>:
2221 Fired when BitBake is about to start parsing recipes.
2222 This event's "total" attribute represents the number of
2223 recipes BitBake plans to parse.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002224 </para></listitem>
2225 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002226 <filename>bb.event.ParseProgress()</filename>:
2227 Fired as parsing progresses.
2228 This event's "current" attribute is the number of
2229 recipes parsed as well as the "total" attribute.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002230 </para></listitem>
2231 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002232 <filename>bb.event.ParseCompleted()</filename>:
2233 Fired when parsing is complete.
2234 This event's "cached", "parsed", "skipped", "virtuals",
2235 "masked", and "errors" attributes provide statistics
2236 for the parsing results.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002237 </para></listitem>
2238 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002239 <filename>bb.event.BuildStarted()</filename>:
2240 Fired when a new build starts.
Brad Bishop316dfdd2018-06-25 12:45:53 -04002241 BitBake fires multiple "BuildStarted" events (one per configuration)
2242 when multiple configuration (multiconfig) is enabled.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002243 </para></listitem>
2244 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002245 <filename>bb.build.TaskStarted()</filename>:
2246 Fired when a task starts.
2247 This event's "taskfile" attribute points to the recipe
2248 from which the task originates.
2249 The "taskname" attribute, which is the task's name,
2250 includes the <filename>do_</filename> prefix, and the
2251 "logfile" attribute point to where the task's output is
2252 stored.
2253 Finally, the "time" attribute is the task's execution start
2254 time.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002255 </para></listitem>
2256 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002257 <filename>bb.build.TaskInvalid()</filename>:
2258 Fired if BitBake tries to execute a task that does not exist.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002259 </para></listitem>
2260 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002261 <filename>bb.build.TaskFailedSilent()</filename>:
2262 Fired for setscene tasks that fail and should not be
2263 presented to the user verbosely.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002264 </para></listitem>
2265 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002266 <filename>bb.build.TaskFailed()</filename>:
2267 Fired for normal tasks that fail.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002268 </para></listitem>
2269 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002270 <filename>bb.build.TaskSucceeded()</filename>:
2271 Fired when a task successfully completes.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002272 </para></listitem>
2273 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002274 <filename>bb.event.BuildCompleted()</filename>:
2275 Fired when a build finishes.
2276 </para></listitem>
2277 <listitem><para>
2278 <filename>bb.cooker.CookerExit()</filename>:
2279 Fired when the BitBake server/cooker shuts down.
2280 This event is usually only seen by the UIs as a
2281 sign they should also shutdown.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002282 </para></listitem>
2283 </itemizedlist>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002284 </para>
2285
2286 <para>
2287 This next list of example events occur based on specific
2288 requests to the server.
2289 These events are often used to communicate larger pieces of
2290 information from the BitBake server to other parts of
2291 BitBake such as user interfaces:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002292 <itemizedlist>
2293 <listitem><para>
2294 <filename>bb.event.TreeDataPreparationStarted()</filename>
2295 </para></listitem>
2296 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002297 <filename>bb.event.TreeDataPreparationProgress()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002298 </para></listitem>
2299 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002300 <filename>bb.event.TreeDataPreparationCompleted()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002301 </para></listitem>
2302 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002303 <filename>bb.event.DepTreeGenerated()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002304 </para></listitem>
2305 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002306 <filename>bb.event.CoreBaseFilesFound()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002307 </para></listitem>
2308 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002309 <filename>bb.event.ConfigFilePathFound()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002310 </para></listitem>
2311 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002312 <filename>bb.event.FilesMatchingFound()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002313 </para></listitem>
2314 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002315 <filename>bb.event.ConfigFilesFound()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002316 </para></listitem>
2317 <listitem><para>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002318 <filename>bb.event.TargetsTreeGenerated()</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002319 </para></listitem>
2320 </itemizedlist>
2321 </para>
2322 </section>
2323
2324 <section id='variants-class-extension-mechanism'>
2325 <title>Variants - Class Extension Mechanism</title>
2326
2327 <para>
2328 BitBake supports two features that facilitate creating
2329 from a single recipe file multiple incarnations of that
2330 recipe file where all incarnations are buildable.
2331 These features are enabled through the
Brad Bishop19323692019-04-05 15:28:33 -04002332 <link linkend='var-bb-BBCLASSEXTEND'><filename>BBCLASSEXTEND</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002333 and
Brad Bishop19323692019-04-05 15:28:33 -04002334 <link linkend='var-bb-BBVERSIONS'><filename>BBVERSIONS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002335 variables.
2336 <note>
2337 The mechanism for this class extension is extremely
2338 specific to the implementation.
2339 Usually, the recipe's
Brad Bishop19323692019-04-05 15:28:33 -04002340 <link linkend='var-bb-PROVIDES'><filename>PROVIDES</filename></link>,
2341 <link linkend='var-bb-PN'><filename>PN</filename></link>, and
2342 <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002343 variables would need to be modified by the extension class.
2344 For specific examples, see the OE-Core
2345 <filename>native</filename>, <filename>nativesdk</filename>,
2346 and <filename>multilib</filename> classes.
2347 </note>
2348 <itemizedlist>
2349 <listitem><para><emphasis><filename>BBCLASSEXTEND</filename>:</emphasis>
2350 This variable is a space separated list of classes used to "extend" the
2351 recipe for each variant.
2352 Here is an example that results in a second incarnation of the current
2353 recipe being available.
2354 This second incarnation will have the "native" class inherited.
2355 <literallayout class='monospaced'>
2356 BBCLASSEXTEND = "native"
2357 </literallayout></para></listitem>
2358 <listitem><para><emphasis><filename>BBVERSIONS</filename>:</emphasis>
2359 This variable allows a single recipe to build multiple versions of a
2360 project from a single recipe file.
2361 You can also specify conditional metadata
2362 (using the
Brad Bishop19323692019-04-05 15:28:33 -04002363 <link linkend='var-bb-OVERRIDES'><filename>OVERRIDES</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002364 mechanism) for a single version, or an optionally named range of versions.
2365 Here is an example:
2366 <literallayout class='monospaced'>
2367 BBVERSIONS = "1.0 2.0 git"
2368 SRC_URI_git = "git://someurl/somepath.git"
2369
2370 BBVERSIONS = "1.0.[0-6]:1.0.0+ \ 1.0.[7-9]:1.0.7+"
2371 SRC_URI_append_1.0.7+ = "file://some_patch_which_the_new_versions_need.patch;patch=1"
2372 </literallayout>
2373 The name of the range defaults to the original version of the
2374 recipe.
2375 For example, in OpenEmbedded, the recipe file
2376 <filename>foo_1.0.0+.bb</filename> creates a default name range
2377 of <filename>1.0.0+</filename>.
2378 This is useful because the range name is not only placed
2379 into overrides, but it is also made available for the metadata to use
2380 in the variable that defines the base recipe versions for use in
2381 <filename>file://</filename> search paths
Brad Bishop19323692019-04-05 15:28:33 -04002382 (<link linkend='var-bb-FILESPATH'><filename>FILESPATH</filename></link>).
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002383 </para></listitem>
2384 </itemizedlist>
2385 </para>
2386 </section>
2387
2388 <section id='dependencies'>
2389 <title>Dependencies</title>
2390
2391 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002392 To allow for efficient parallel processing, BitBake handles
2393 dependencies at the task level.
2394 Dependencies can exist both between tasks within a single recipe
2395 and between tasks in different recipes.
2396 Following are examples of each:
2397 <itemizedlist>
2398 <listitem><para>For tasks within a single recipe, a
2399 recipe's <filename>do_configure</filename>
2400 task might need to complete before its
2401 <filename>do_compile</filename> task can run.
2402 </para></listitem>
2403 <listitem><para>For tasks in different recipes, one
2404 recipe's <filename>do_configure</filename>
2405 task might require another recipe's
2406 <filename>do_populate_sysroot</filename>
2407 task to finish first such that the libraries and headers
2408 provided by the other recipe are available.
2409 </para></listitem>
2410 </itemizedlist>
2411 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002412
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002413 <para>
2414 This section describes several ways to declare dependencies.
2415 Remember, even though dependencies are declared in different ways, they
2416 are all simply dependencies between tasks.
2417 </para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002418
2419 <section id='dependencies-internal-to-the-bb-file'>
2420 <title>Dependencies Internal to the <filename>.bb</filename> File</title>
2421
2422 <para>
2423 BitBake uses the <filename>addtask</filename> directive
2424 to manage dependencies that are internal to a given recipe
2425 file.
2426 You can use the <filename>addtask</filename> directive to
2427 indicate when a task is dependent on other tasks or when
2428 other tasks depend on that recipe.
2429 Here is an example:
2430 <literallayout class='monospaced'>
2431 addtask printdate after do_fetch before do_build
2432 </literallayout>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002433 In this example, the <filename>do_printdate</filename>
2434 task depends on the completion of the
2435 <filename>do_fetch</filename> task, and the
2436 <filename>do_build</filename> task depends on the
2437 completion of the <filename>do_printdate</filename>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002438 task.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002439 <note><para>
2440 For a task to run, it must be a direct or indirect
2441 dependency of some other task that is scheduled to
2442 run.</para>
2443
2444 <para>For illustration, here are some examples:
2445 <itemizedlist>
2446 <listitem><para>
2447 The directive
2448 <filename>addtask mytask before do_configure</filename>
2449 causes <filename>do_mytask</filename> to run before
2450 <filename>do_configure</filename> runs.
2451 Be aware that <filename>do_mytask</filename> still only
2452 runs if its <link linkend='checksums'>input checksum</link>
2453 has changed since the last time it was run.
2454 Changes to the input checksum of
2455 <filename>do_mytask</filename> also indirectly cause
2456 <filename>do_configure</filename> to run.
2457 </para></listitem>
2458 <listitem><para>
2459 The directive
2460 <filename>addtask mytask after do_configure</filename>
2461 by itself never causes <filename>do_mytask</filename>
2462 to run.
2463 <filename>do_mytask</filename> can still be run manually
2464 as follows:
2465 <literallayout class='monospaced'>
2466 $ bitbake <replaceable>recipe</replaceable> -c mytask
2467 </literallayout>
2468 Declaring <filename>do_mytask</filename> as a dependency
2469 of some other task that is scheduled to run also causes
2470 it to run.
2471 Regardless, the task runs after
2472 <filename>do_configure</filename>.
2473 </para></listitem>
2474 </itemizedlist></para>
2475 </note>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002476 </para>
2477 </section>
2478
2479 <section id='build-dependencies'>
2480 <title>Build Dependencies</title>
2481
2482 <para>
2483 BitBake uses the
Brad Bishop19323692019-04-05 15:28:33 -04002484 <link linkend='var-bb-DEPENDS'><filename>DEPENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002485 variable to manage build time dependencies.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002486 The <filename>[deptask]</filename> varflag for tasks
2487 signifies the task of each
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002488 item listed in <filename>DEPENDS</filename> that must
2489 complete before that task can be executed.
2490 Here is an example:
2491 <literallayout class='monospaced'>
2492 do_configure[deptask] = "do_populate_sysroot"
2493 </literallayout>
2494 In this example, the <filename>do_populate_sysroot</filename>
2495 task of each item in <filename>DEPENDS</filename> must complete before
2496 <filename>do_configure</filename> can execute.
2497 </para>
2498 </section>
2499
2500 <section id='runtime-dependencies'>
2501 <title>Runtime Dependencies</title>
2502
2503 <para>
2504 BitBake uses the
Brad Bishop19323692019-04-05 15:28:33 -04002505 <link linkend='var-bb-PACKAGES'><filename>PACKAGES</filename></link>,
2506 <link linkend='var-bb-RDEPENDS'><filename>RDEPENDS</filename></link>, and
2507 <link linkend='var-bb-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002508 variables to manage runtime dependencies.
2509 </para>
2510
2511 <para>
2512 The <filename>PACKAGES</filename> variable lists runtime
2513 packages.
2514 Each of those packages can have <filename>RDEPENDS</filename> and
2515 <filename>RRECOMMENDS</filename> runtime dependencies.
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002516 The <filename>[rdeptask]</filename> flag for tasks is used to
2517 signify the task of each
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002518 item runtime dependency which must have completed before that
2519 task can be executed.
2520 <literallayout class='monospaced'>
2521 do_package_qa[rdeptask] = "do_packagedata"
2522 </literallayout>
2523 In the previous example, the <filename>do_packagedata</filename>
2524 task of each item in <filename>RDEPENDS</filename> must have
2525 completed before <filename>do_package_qa</filename> can execute.
2526 </para>
2527 </section>
2528
2529 <section id='recursive-dependencies'>
2530 <title>Recursive Dependencies</title>
2531
2532 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002533 BitBake uses the <filename>[recrdeptask]</filename> flag to manage
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002534 recursive task dependencies.
2535 BitBake looks through the build-time and runtime
2536 dependencies of the current recipe, looks through
2537 the task's inter-task
2538 dependencies, and then adds dependencies for the
2539 listed task.
2540 Once BitBake has accomplished this, it recursively works through
2541 the dependencies of those tasks.
2542 Iterative passes continue until all dependencies are discovered
2543 and added.
2544 </para>
2545
2546 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002547 The <filename>[recrdeptask]</filename> flag is most commonly
2548 used in high-level
2549 recipes that need to wait for some task to finish "globally".
2550 For example, <filename>image.bbclass</filename> has the following:
2551 <literallayout class='monospaced'>
2552 do_rootfs[recrdeptask] += "do_packagedata"
2553 </literallayout>
2554 This statement says that the <filename>do_packagedata</filename>
2555 task of the current recipe and all recipes reachable
2556 (by way of dependencies) from the
2557 image recipe must run before the <filename>do_rootfs</filename>
2558 task can run.
2559 </para>
2560
2561 <para>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002562 You might want to not only have BitBake look for
2563 dependencies of those tasks, but also have BitBake look
2564 for build-time and runtime dependencies of the dependent
2565 tasks as well.
2566 If that is the case, you need to reference the task name
2567 itself in the task list:
2568 <literallayout class='monospaced'>
2569 do_a[recrdeptask] = "do_a do_b"
2570 </literallayout>
2571 </para>
2572 </section>
2573
2574 <section id='inter-task-dependencies'>
2575 <title>Inter-Task Dependencies</title>
2576
2577 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002578 BitBake uses the <filename>[depends]</filename>
2579 flag in a more generic form
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002580 to manage inter-task dependencies.
2581 This more generic form allows for inter-dependency
2582 checks for specific tasks rather than checks for
2583 the data in <filename>DEPENDS</filename>.
2584 Here is an example:
2585 <literallayout class='monospaced'>
2586 do_patch[depends] = "quilt-native:do_populate_sysroot"
2587 </literallayout>
2588 In this example, the <filename>do_populate_sysroot</filename>
2589 task of the target <filename>quilt-native</filename>
2590 must have completed before the
2591 <filename>do_patch</filename> task can execute.
2592 </para>
2593
2594 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002595 The <filename>[rdepends]</filename> flag works in a similar
2596 way but takes targets
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002597 in the runtime namespace instead of the build-time dependency
2598 namespace.
2599 </para>
2600 </section>
2601 </section>
2602
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002603 <section id='functions-you-can-call-from-within-python'>
2604 <title>Functions You Can Call From Within Python</title>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002605
2606 <para>
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002607 BitBake provides many functions you can call from
2608 within Python functions.
2609 This section lists the most commonly used functions,
2610 and mentions where to find others.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002611 </para>
2612
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002613 <section id='functions-for-accessing-datastore-variables'>
2614 <title>Functions for Accessing Datastore Variables</title>
2615
2616 <para>
2617 It is often necessary to access variables in the
2618 BitBake datastore using Python functions.
2619 The Bitbake datastore has an API that allows you this
2620 access.
2621 Here is a list of available operations:
2622 </para>
2623
2624 <para>
2625 <informaltable frame='none'>
2626 <tgroup cols='2' align='left' colsep='1' rowsep='1'>
2627 <colspec colname='c1' colwidth='1*'/>
2628 <colspec colname='c2' colwidth='1*'/>
2629 <thead>
2630 <row>
2631 <entry align="left"><emphasis>Operation</emphasis></entry>
2632 <entry align="left"><emphasis>Description</emphasis></entry>
2633 </row>
2634 </thead>
2635 <tbody>
2636 <row>
2637 <entry align="left"><filename>d.getVar("X", expand)</filename></entry>
2638 <entry align="left">Returns the value of variable "X".
2639 Using "expand=True" expands the value.
2640 Returns "None" if the variable "X" does not exist.</entry>
2641 </row>
2642 <row>
2643 <entry align="left"><filename>d.setVar("X", "value")</filename></entry>
2644 <entry align="left">Sets the variable "X" to "value".</entry>
2645 </row>
2646 <row>
2647 <entry align="left"><filename>d.appendVar("X", "value")</filename></entry>
2648 <entry align="left">Adds "value" to the end of the variable "X".
2649 Acts like <filename>d.setVar("X", "value")</filename>
2650 if the variable "X" does not exist.</entry>
2651 </row>
2652 <row>
2653 <entry align="left"><filename>d.prependVar("X", "value")</filename></entry>
2654 <entry align="left">Adds "value" to the start of the variable "X".
2655 Acts like <filename>d.setVar("X", "value")</filename>
2656 if the variable "X" does not exist.</entry>
2657 </row>
2658 <row>
2659 <entry align="left"><filename>d.delVar("X")</filename></entry>
2660 <entry align="left">Deletes the variable "X" from the datastore.
2661 Does nothing if the variable "X" does not exist.</entry>
2662 </row>
2663 <row>
2664 <entry align="left"><filename>d.renameVar("X", "Y")</filename></entry>
2665 <entry align="left">Renames the variable "X" to "Y".
2666 Does nothing if the variable "X" does not exist.</entry>
2667 </row>
2668 <row>
2669 <entry align="left"><filename>d.getVarFlag("X", flag, expand)</filename></entry>
2670 <entry align="left">Returns the value of variable "X".
2671 Using "expand=True" expands the value.
2672 Returns "None" if either the variable "X" or the named flag
2673 does not exist.</entry>
2674 </row>
2675 <row>
2676 <entry align="left"><filename>d.setVarFlag("X", flag, "value")</filename></entry>
2677 <entry align="left">Sets the named flag for variable "X" to "value".</entry>
2678 </row>
2679 <row>
2680 <entry align="left"><filename>d.appendVarFlag("X", flag, "value")</filename></entry>
2681 <entry align="left">Appends "value" to the named flag on the
2682 variable "X".
2683 Acts like <filename>d.setVarFlag("X", flag, "value")</filename>
2684 if the named flag does not exist.</entry>
2685 </row>
2686 <row>
2687 <entry align="left"><filename>d.prependVarFlag("X", flag, "value")</filename></entry>
2688 <entry align="left">Prepends "value" to the named flag on
2689 the variable "X".
2690 Acts like <filename>d.setVarFlag("X", flag, "value")</filename>
2691 if the named flag does not exist.</entry>
2692 </row>
2693 <row>
2694 <entry align="left"><filename>d.delVarFlag("X", flag)</filename></entry>
2695 <entry align="left">Deletes the named flag on the variable
2696 "X" from the datastore.</entry>
2697 </row>
2698 <row>
2699 <entry align="left"><filename>d.setVarFlags("X", flagsdict)</filename></entry>
2700 <entry align="left">Sets the flags specified in
2701 the <filename>flagsdict()</filename> parameter.
2702 <filename>setVarFlags</filename> does not clear previous flags.
2703 Think of this operation as <filename>addVarFlags</filename>.</entry>
2704 </row>
2705 <row>
2706 <entry align="left"><filename>d.getVarFlags("X")</filename></entry>
2707 <entry align="left">Returns a <filename>flagsdict</filename>
2708 of the flags for the variable "X".
2709 Returns "None" if the variable "X" does not exist.</entry>
2710 </row>
2711 <row>
2712 <entry align="left"><filename>d.delVarFlags("X")</filename></entry>
2713 <entry align="left">Deletes all the flags for the variable "X".
2714 Does nothing if the variable "X" does not exist.</entry>
2715 </row>
2716 <row>
2717 <entry align="left"><filename>d.expand(expression)</filename></entry>
2718 <entry align="left">Expands variable references in the specified
2719 string expression.
2720 References to variables that do not exist are left as is.
2721 For example, <filename>d.expand("foo ${X}")</filename>
2722 expands to the literal string "foo ${X}" if the
2723 variable "X" does not exist.</entry>
2724 </row>
2725 </tbody>
2726 </tgroup>
2727 </informaltable>
2728 </para>
2729 </section>
2730
2731 <section id='other-functions'>
2732 <title>Other Functions</title>
2733
2734 <para>
2735 You can find many other functions that can be called
2736 from Python by looking at the source code of the
2737 <filename>bb</filename> module, which is in
2738 <filename>bitbake/lib/bb</filename>.
2739 For example,
2740 <filename>bitbake/lib/bb/utils.py</filename> includes
2741 the commonly used functions
2742 <filename>bb.utils.contains()</filename> and
2743 <filename>bb.utils.mkdirhier()</filename>, which come
2744 with docstrings.
2745 </para>
2746 </section>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002747 </section>
2748
2749 <section id='task-checksums-and-setscene'>
2750 <title>Task Checksums and Setscene</title>
2751
2752 <para>
2753 BitBake uses checksums (or signatures) along with the setscene
2754 to determine if a task needs to be run.
2755 This section describes the process.
2756 To help understand how BitBake does this, the section assumes an
2757 OpenEmbedded metadata-based example.
2758 </para>
2759
2760 <para>
Brad Bishop316dfdd2018-06-25 12:45:53 -04002761 These checksums are stored in
Brad Bishop19323692019-04-05 15:28:33 -04002762 <link linkend='var-bb-STAMP'><filename>STAMP</filename></link>.
Brad Bishop316dfdd2018-06-25 12:45:53 -04002763 You can examine the checksums using the following BitBake command:
2764 <literallayout class='monospaced'>
2765 $ bitbake-dumpsigs
2766 </literallayout>
2767 This command returns the signature data in a readable format
2768 that allows you to examine the inputs used when the
2769 OpenEmbedded build system generates signatures.
2770 For example, using <filename>bitbake-dumpsigs</filename>
2771 allows you to examine the <filename>do_compile</filename>
2772 task's “sigdata” for a C application (e.g.
2773 <filename>bash</filename>).
2774 Running the command also reveals that the “CC” variable is part of
2775 the inputs that are hashed.
2776 Any changes to this variable would invalidate the stamp and
2777 cause the <filename>do_compile</filename> task to run.
2778 </para>
2779
2780 <para>
2781 The following list describes related variables:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002782 <itemizedlist>
Brad Bishop316dfdd2018-06-25 12:45:53 -04002783 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002784 <link linkend='var-bb-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></link>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002785 Specifies the name of the function to call during
2786 the "setscene" part of the task's execution in order
2787 to validate the list of task hashes.
2788 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04002789 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002790 <link linkend='var-bb-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></link>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002791 Specifies a function BitBake calls that determines
2792 whether BitBake requires a setscene dependency to
2793 be met.
2794 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04002795 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002796 <link linkend='var-bb-BB_SETSCENE_VERIFY_FUNCTION2'><filename>BB_SETSCENE_VERIFY_FUNCTION2</filename></link>:
Brad Bishop316dfdd2018-06-25 12:45:53 -04002797 Specifies a function to call that verifies the list of
2798 planned task execution before the main task execution
2799 happens.
2800 </para></listitem>
2801 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002802 <link linkend='var-bb-BB_STAMP_POLICY'><filename>BB_STAMP_POLICY</filename></link>:
Brad Bishop316dfdd2018-06-25 12:45:53 -04002803 Defines the mode for comparing timestamps of stamp files.
2804 </para></listitem>
2805 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002806 <link linkend='var-bb-BB_STAMP_WHITELIST'><filename>BB_STAMP_WHITELIST</filename></link>:
Brad Bishop316dfdd2018-06-25 12:45:53 -04002807 Lists stamp files that are looked at when the stamp policy
2808 is "whitelist".
2809 </para></listitem>
2810 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002811 <link linkend='var-bb-BB_TASKHASH'><filename>BB_TASKHASH</filename></link>:
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002812 Within an executing task, this variable holds the hash
2813 of the task as returned by the currently enabled
2814 signature generator.
2815 </para></listitem>
Brad Bishop316dfdd2018-06-25 12:45:53 -04002816 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002817 <link linkend='var-bb-STAMP'><filename>STAMP</filename></link>:
Brad Bishop316dfdd2018-06-25 12:45:53 -04002818 The base path to create stamp files.
2819 </para></listitem>
2820 <listitem><para>
Brad Bishop19323692019-04-05 15:28:33 -04002821 <link linkend='var-bb-STAMPCLEAN'><filename>STAMPCLEAN</filename></link>:
Brad Bishop316dfdd2018-06-25 12:45:53 -04002822 Again, the base path to create stamp files but can use wildcards
2823 for matching a range of files for clean operations.
2824 </para></listitem>
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002825 </itemizedlist>
2826 </para>
2827 </section>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002828
2829 <section id='wildcard-support-in-variables'>
2830 <title>Wildcard Support in Variables</title>
2831
2832 <para>
2833 Support for wildcard use in variables varies depending on the
2834 context in which it is used.
2835 For example, some variables and file names allow limited use of
2836 wildcards through the "<filename>%</filename>" and
2837 "<filename>*</filename>" characters.
2838 Other variables or names support Python's
2839 <ulink url='https://docs.python.org/3/library/glob.html'><filename>glob</filename></ulink>
2840 syntax,
2841 <ulink url='https://docs.python.org/3/library/fnmatch.html#module-fnmatch'><filename>fnmatch</filename></ulink>
2842 syntax, or
2843 <ulink url='https://docs.python.org/3/library/re.html#re'><filename>Regular Expression (re)</filename></ulink>
2844 syntax.
2845 </para>
2846
2847 <para>
2848 For variables that have wildcard suport, the
2849 documentation describes which form of wildcard, its
2850 use, and its limitations.
2851 </para>
2852 </section>
2853
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002854</chapter>