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