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