summaryrefslogtreecommitdiffstats
path: root/bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml')
-rw-r--r--bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml910
1 files changed, 910 insertions, 0 deletions
diff --git a/bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml
new file mode 100644
index 0000000000..571424b99f
--- /dev/null
+++ b/bitbake/doc/bitbake-user-manual/bitbake-user-manual-execution.xml
@@ -0,0 +1,910 @@
1<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
2"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
3
4<chapter id="bitbake-user-manual-execution">
5 <title>Execution</title>
6
7 <para>
8 The primary purpose for running BitBake is to produce some kind
9 of output such as a single installable package, a kernel, a software
10 development kit, or even a full, board-specific bootable Linux image,
11 complete with bootloader, kernel, and root filesystem.
12 Of course, you can execute the <filename>bitbake</filename>
13 command with options that cause it to execute single tasks,
14 compile single recipe files, capture or clear data, or simply
15 return information about the execution environment.
16 </para>
17
18 <para>
19 This chapter describes BitBake's execution process from start
20 to finish when you use it to create an image.
21 The execution process is launched using the following command
22 form:
23 <literallayout class='monospaced'>
24 $ bitbake &lt;target&gt;
25 </literallayout>
26 For information on the BitBake command and its options,
27 see
28 "<link linkend='bitbake-user-manual-command'>The BitBake Command</link>"
29 section.
30 <note>
31 <para>
32 Prior to executing BitBake, you should take advantage of available
33 parallel thread execution on your build host by setting the
34 <link linkend='var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename></link>
35 variable in your project's <filename>local.conf</filename>
36 configuration file.
37 </para>
38
39 <para>
40 A common way to determine this value for your build host is to run:
41 <literallayout class='monospaced'>
42 $ grep processor /proc/cpuinfo
43 </literallayout>
44 and count the number of processors displayed. Note that the number of
45 processors will take into account hyper-threading, so that a quad-core
46 build host with hyper-threading will most likely show eight processors,
47 which is the value you would then assign to that variable.
48 </para>
49
50 <para>
51 A possibly simpler solution is that some Linux distributions
52 (e.g. Debian and Ubuntu) provide the <filename>ncpus</filename> command.
53 </para>
54 </note>
55 </para>
56
57 <section id='parsing-the-base-configuration-metadata'>
58 <title>Parsing the Base Configuration Metadata</title>
59
60 <para>
61 The first thing BitBake does is parse base configuration
62 metadata.
63 Base configuration metadata consists of your project's
64 <filename>bblayers.conf</filename> file to determine what
65 layers BitBake needs to recognize, all necessary
66 <filename>layer.conf</filename> files (one from each layer),
67 and <filename>bitbake.conf</filename>.
68 The data itself is of various types:
69 <itemizedlist>
70 <listitem><para><emphasis>Recipes:</emphasis>
71 Details about particular pieces of software.
72 </para></listitem>
73 <listitem><para><emphasis>Class Data:</emphasis>
74 An abstraction of common build information
75 (e.g. how to build a Linux kernel).
76 </para></listitem>
77 <listitem><para><emphasis>Configuration Data:</emphasis>
78 Machine-specific settings, policy decisions,
79 and so forth.
80 Configuration data acts as the glue to bind everything
81 together.</para></listitem>
82 </itemizedlist>
83 </para>
84
85 <para>
86 The <filename>layer.conf</filename> files are used to
87 construct key variables such as
88 <link linkend='var-BBPATH'><filename>BBPATH</filename></link>
89 and
90 <link linkend='var-BBFILES'><filename>BBFILES</filename></link>.
91 <filename>BBPATH</filename> is used to search for
92 configuration and class files under the
93 <filename>conf</filename> and <filename>classes</filename>
94 directories, respectively.
95 <filename>BBFILES</filename> is used to locate both recipe
96 and recipe append files
97 (<filename>.bb</filename> and <filename>.bbappend</filename>).
98 If there is no <filename>bblayers.conf</filename> file,
99 it is assumed the user has set the <filename>BBPATH</filename>
100 and <filename>BBFILES</filename> directly in the environment.
101 </para>
102
103 <para>
104 Next, the <filename>bitbake.conf</filename> file is located
105 using the <filename>BBPATH</filename> variable that was
106 just constructed.
107 The <filename>bitbake.conf</filename> file may also include other
108 configuration files using the
109 <filename>include</filename> or
110 <filename>require</filename> directives.
111 </para>
112
113 <para>
114 Prior to parsing configuration files, Bitbake looks
115 at certain variables, including:
116 <itemizedlist>
117 <listitem><para><link linkend='var-BB_ENV_WHITELIST'><filename>BB_ENV_WHITELIST</filename></link></para></listitem>
118 <listitem><para><link linkend='var-BB_PRESERVE_ENV'><filename>BB_PRESERVE_ENV</filename></link></para></listitem>
119 <listitem><para><link linkend='var-BB_ENV_EXTRAWHITE'><filename>BB_ENV_EXTRAWHITE</filename></link></para></listitem>
120 <listitem><para>
121 <link linkend='var-BITBAKE_UI'><filename>BITBAKE_UI</filename></link>
122 </para></listitem>
123 </itemizedlist>
124 You can find information on how to pass environment variables into the BitBake
125 execution environment in the
126 "<link linkend='passing-information-into-the-build-task-environment'>Passing Information Into the Build Task Environment</link>" section.
127 </para>
128
129 <para>
130 The base configuration metadata is global
131 and therefore affects all recipes and tasks that are executed.
132 </para>
133
134 <para>
135 BitBake first searches the current working directory for an
136 optional <filename>conf/bblayers.conf</filename> configuration file.
137 This file is expected to contain a
138 <link linkend='var-BBLAYERS'><filename>BBLAYERS</filename></link>
139 variable that is a space-delimited list of 'layer' directories.
140 Recall that if BitBake cannot find a <filename>bblayers.conf</filename>
141 file, then it is assumed the user has set the <filename>BBPATH</filename>
142 and <filename>BBFILES</filename> variables directly in the environment.
143 </para>
144
145 <para>
146 For each directory (layer) in this list, a <filename>conf/layer.conf</filename>
147 file is located and parsed with the
148 <link linkend='var-LAYERDIR'><filename>LAYERDIR</filename></link>
149 variable being set to the directory where the layer was found.
150 The idea is these files automatically set up
151 <link linkend='var-BBPATH'><filename>BBPATH</filename></link>
152 and other variables correctly for a given build directory.
153 </para>
154
155 <para>
156 BitBake then expects to find the <filename>conf/bitbake.conf</filename>
157 file somewhere in the user-specified <filename>BBPATH</filename>.
158 That configuration file generally has include directives to pull
159 in any other metadata such as files specific to the architecture,
160 the machine, the local environment, and so forth.
161 </para>
162
163 <para>
164 Only variable definitions and include directives are allowed
165 in BitBake <filename>.conf</filename> files.
166 Some variables directly influence BitBake's behavior.
167 These variables might have been set from the environment
168 depending on the environment variables previously
169 mentioned or set in the configuration files.
170 The
171 "<link linkend='ref-variables-glos'>Variables Glossary</link>"
172 chapter presents a full list of variables.
173 </para>
174
175 <para>
176 After parsing configuration files, BitBake uses its rudimentary
177 inheritance mechanism, which is through class files, to inherit
178 some standard classes.
179 BitBake parses a class when the inherit directive responsible
180 for getting that class is encountered.
181 </para>
182
183 <para>
184 The <filename>base.bbclass</filename> file is always included.
185 Other classes that are specified in the configuration using the
186 <link linkend='var-INHERIT'><filename>INHERIT</filename></link>
187 variable are also included.
188 BitBake searches for class files in a
189 <filename>classes</filename> subdirectory under
190 the paths in <filename>BBPATH</filename> in the same way as
191 configuration files.
192 </para>
193
194 <para>
195 A good way to get an idea of the configuration files and
196 the class files used in your execution environment is to
197 run the following BitBake command:
198 <literallayout class='monospaced'>
199 $ bitbake -e > mybb.log
200 </literallayout>
201 Examining the top of the <filename>mybb.log</filename>
202 shows you the many configuration files and class files
203 used in your execution environment.
204 </para>
205
206 <note>
207 <para>
208 You need to be aware of how BitBake parses curly braces.
209 If a recipe uses a closing curly brace within the function and
210 the character has no leading spaces, BitBake produces a parsing
211 error.
212 If you use a pair of curly braces in a shell function, the
213 closing curly brace must not be located at the start of the line
214 without leading spaces.
215 </para>
216
217 <para>
218 Here is an example that causes BitBake to produce a parsing
219 error:
220 <literallayout class='monospaced'>
221 fakeroot create_shar() {
222 cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
223 usage()
224 {
225 echo "test"
226 ###### The following "}" at the start of the line causes a parsing error ######
227 }
228 EOF
229 }
230 </literallayout>
231 Writing the recipe this way avoids the error:
232 <literallayout class='monospaced'>
233 fakeroot create_shar() {
234 cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
235 usage()
236 {
237 echo "test"
238 ######The following "}" with a leading space at the start of the line avoids the error ######
239 }
240 EOF
241 }
242 </literallayout>
243 </para>
244 </note>
245 </section>
246
247 <section id='locating-and-parsing-recipes'>
248 <title>Locating and Parsing Recipes</title>
249
250 <para>
251 During the configuration phase, BitBake will have set
252 <link linkend='var-BBFILES'><filename>BBFILES</filename></link>.
253 BitBake now uses it to construct a list of recipes to parse,
254 along with any append files (<filename>.bbappend</filename>)
255 to apply.
256 <filename>BBFILES</filename> is a space-separated list of
257 available files and supports wildcards.
258 An example would be:
259 <literallayout class='monospaced'>
260 BBFILES = "/path/to/bbfiles/*.bb /path/to/appends/*.bbappend"
261 </literallayout>
262 BitBake parses each recipe and append file located
263 with <filename>BBFILES</filename> and stores the values of
264 various variables into the datastore.
265 <note>
266 Append files are applied in the order they are encountered in
267 <filename>BBFILES</filename>.
268 </note>
269 For each file, a fresh copy of the base configuration is
270 made, then the recipe is parsed line by line.
271 Any inherit statements cause BitBake to find and
272 then parse class files (<filename>.bbclass</filename>)
273 using
274 <link linkend='var-BBPATH'><filename>BBPATH</filename></link>
275 as the search path.
276 Finally, BitBake parses in order any append files found in
277 <filename>BBFILES</filename>.
278 </para>
279
280 <para>
281 One common convention is to use the recipe filename to define
282 pieces of metadata.
283 For example, in <filename>bitbake.conf</filename> the recipe
284 name and version are used to set the variables
285 <link linkend='var-PN'><filename>PN</filename></link> and
286 <link linkend='var-PV'><filename>PV</filename></link>:
287 <literallayout class='monospaced'>
288 PN = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[0] or 'defaultpkgname'}"
289 PV = "${@bb.parse.BBHandler.vars_from_file(d.getVar('FILE'),d)[1] or '1.0'}"
290 </literallayout>
291 In this example, a recipe called "something_1.2.3.bb" would set
292 <filename>PN</filename> to "something" and
293 <filename>PV</filename> to "1.2.3".
294 </para>
295
296 <para>
297 By the time parsing is complete for a recipe, BitBake
298 has a list of tasks that the recipe defines and a set of
299 data consisting of keys and values as well as
300 dependency information about the tasks.
301 </para>
302
303 <para>
304 BitBake does not need all of this information.
305 It only needs a small subset of the information to make
306 decisions about the recipe.
307 Consequently, BitBake caches the values in which it is
308 interested and does not store the rest of the information.
309 Experience has shown it is faster to re-parse the metadata than to
310 try and write it out to the disk and then reload it.
311 </para>
312
313 <para>
314 Where possible, subsequent BitBake commands reuse this cache of
315 recipe information.
316 The validity of this cache is determined by first computing a
317 checksum of the base configuration data (see
318 <link linkend='var-BB_HASHCONFIG_WHITELIST'><filename>BB_HASHCONFIG_WHITELIST</filename></link>)
319 and then checking if the checksum matches.
320 If that checksum matches what is in the cache and the recipe
321 and class files have not changed, Bitbake is able to use
322 the cache.
323 BitBake then reloads the cached information about the recipe
324 instead of reparsing it from scratch.
325 </para>
326
327 <para>
328 Recipe file collections exist to allow the user to
329 have multiple repositories of
330 <filename>.bb</filename> files that contain the same
331 exact package.
332 For example, one could easily use them to make one's
333 own local copy of an upstream repository, but with
334 custom modifications that one does not want upstream.
335 Here is an example:
336 <literallayout class='monospaced'>
337 BBFILES = "/stuff/openembedded/*/*.bb /stuff/openembedded.modified/*/*.bb"
338 BBFILE_COLLECTIONS = "upstream local"
339 BBFILE_PATTERN_upstream = "^/stuff/openembedded/"
340 BBFILE_PATTERN_local = "^/stuff/openembedded.modified/"
341 BBFILE_PRIORITY_upstream = "5"
342 BBFILE_PRIORITY_local = "10"
343 </literallayout>
344 <note>
345 The layers mechanism is now the preferred method of collecting
346 code.
347 While the collections code remains, its main use is to set layer
348 priorities and to deal with overlap (conflicts) between layers.
349 </note>
350 </para>
351 </section>
352
353 <section id='bb-bitbake-providers'>
354 <title>Providers</title>
355
356 <para>
357 Assuming BitBake has been instructed to execute a target
358 and that all the recipe files have been parsed, BitBake
359 starts to figure out how to build the target.
360 BitBake looks through the <filename>PROVIDES</filename> list
361 for each of the recipes.
362 A <filename>PROVIDES</filename> list is the list of names by which
363 the recipe can be known.
364 Each recipe's <filename>PROVIDES</filename> list is created
365 implicitly through the recipe's
366 <link linkend='var-PN'><filename>PN</filename></link> variable
367 and explicitly through the recipe's
368 <link linkend='var-PROVIDES'><filename>PROVIDES</filename></link>
369 variable, which is optional.
370 </para>
371
372 <para>
373 When a recipe uses <filename>PROVIDES</filename>, that recipe's
374 functionality can be found under an alternative name or names other
375 than the implicit <filename>PN</filename> name.
376 As an example, suppose a recipe named <filename>keyboard_1.0.bb</filename>
377 contained the following:
378 <literallayout class='monospaced'>
379 PROVIDES += "fullkeyboard"
380 </literallayout>
381 The <filename>PROVIDES</filename> list for this recipe becomes
382 "keyboard", which is implicit, and "fullkeyboard", which is explicit.
383 Consequently, the functionality found in
384 <filename>keyboard_1.0.bb</filename> can be found under two
385 different names.
386 </para>
387 </section>
388
389 <section id='bb-bitbake-preferences'>
390 <title>Preferences</title>
391
392 <para>
393 The <filename>PROVIDES</filename> list is only part of the solution
394 for figuring out a target's recipes.
395 Because targets might have multiple providers, BitBake needs
396 to prioritize providers by determining provider preferences.
397 </para>
398
399 <para>
400 A common example in which a target has multiple providers
401 is "virtual/kernel", which is on the
402 <filename>PROVIDES</filename> list for each kernel recipe.
403 Each machine often selects the best kernel provider by using a
404 line similar to the following in the machine configuration file:
405 <literallayout class='monospaced'>
406 PREFERRED_PROVIDER_virtual/kernel = "linux-yocto"
407 </literallayout>
408 The default
409 <link linkend='var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></link>
410 is the provider with the same name as the target.
411 Bitbake iterates through each target it needs to build and
412 resolves them and their dependencies using this process.
413 </para>
414
415 <para>
416 Understanding how providers are chosen is made complicated by the fact
417 that multiple versions might exist for a given provider.
418 BitBake defaults to the highest version of a provider.
419 Version comparisons are made using the same method as Debian.
420 You can use the
421 <link linkend='var-PREFERRED_VERSION'><filename>PREFERRED_VERSION</filename></link>
422 variable to specify a particular version.
423 You can influence the order by using the
424 <link linkend='var-DEFAULT_PREFERENCE'><filename>DEFAULT_PREFERENCE</filename></link>
425 variable.
426 </para>
427
428 <para>
429 By default, files have a preference of "0".
430 Setting <filename>DEFAULT_PREFERENCE</filename> to "-1" makes the
431 recipe unlikely to be used unless it is explicitly referenced.
432 Setting <filename>DEFAULT_PREFERENCE</filename> to "1" makes it
433 likely the recipe is used.
434 <filename>PREFERRED_VERSION</filename> overrides any
435 <filename>DEFAULT_PREFERENCE</filename> setting.
436 <filename>DEFAULT_PREFERENCE</filename> is often used to mark newer
437 and more experimental recipe versions until they have undergone
438 sufficient testing to be considered stable.
439 </para>
440
441 <para>
442 When there are multiple “versions” of a given recipe,
443 BitBake defaults to selecting the most recent
444 version, unless otherwise specified.
445 If the recipe in question has a
446 <link linkend='var-DEFAULT_PREFERENCE'><filename>DEFAULT_PREFERENCE</filename></link>
447 set lower than the other recipes (default is 0), then
448 it will not be selected.
449 This allows the person or persons maintaining
450 the repository of recipe files to specify
451 their preference for the default selected version.
452 Additionally, the user can specify their preferred version.
453 </para>
454
455 <para>
456 If the first recipe is named <filename>a_1.1.bb</filename>, then the
457 <link linkend='var-PN'><filename>PN</filename></link> variable
458 will be set to “a”, and the
459 <link linkend='var-PV'><filename>PV</filename></link>
460 variable will be set to 1.1.
461 </para>
462
463 <para>
464 Thus, if a recipe named <filename>a_1.2.bb</filename> exists, BitBake
465 will choose 1.2 by default.
466 However, if you define the following variable in a
467 <filename>.conf</filename> file that BitBake parses, you
468 can change that preference:
469 <literallayout class='monospaced'>
470 PREFERRED_VERSION_a = "1.1"
471 </literallayout>
472 </para>
473
474 <note>
475 <para>
476 It is common for a recipe to provide two versions -- a stable,
477 numbered (and preferred) version, and a version that is
478 automatically checked out from a source code repository that
479 is considered more "bleeding edge" but can be selected only
480 explicitly.
481 </para>
482
483 <para>
484 For example, in the OpenEmbedded codebase, there is a standard,
485 versioned recipe file for BusyBox,
486 <filename>busybox_1.22.1.bb</filename>,
487 but there is also a Git-based version,
488 <filename>busybox_git.bb</filename>, which explicitly contains the line
489 <literallayout class='monospaced'>
490 DEFAULT_PREFERENCE = "-1"
491 </literallayout>
492 to ensure that the numbered, stable version is always preferred
493 unless the developer selects otherwise.
494 </para>
495 </note>
496 </section>
497
498 <section id='bb-bitbake-dependencies'>
499 <title>Dependencies</title>
500
501 <para>
502 Each target BitBake builds consists of multiple tasks such as
503 <filename>fetch</filename>, <filename>unpack</filename>,
504 <filename>patch</filename>, <filename>configure</filename>,
505 and <filename>compile</filename>.
506 For best performance on multi-core systems, BitBake considers each
507 task as an independent
508 entity with its own set of dependencies.
509 </para>
510
511 <para>
512 Dependencies are defined through several variables.
513 You can find information about variables BitBake uses in
514 the <link linkend='ref-variables-glos'>Variables Glossary</link>
515 near the end of this manual.
516 At a basic level, it is sufficient to know that BitBake uses the
517 <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link> and
518 <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link> variables when
519 calculating dependencies.
520 </para>
521
522 <para>
523 For more information on how BitBake handles dependencies, see the
524 "<link linkend='dependencies'>Dependencies</link>" section.
525 </para>
526 </section>
527
528 <section id='ref-bitbake-tasklist'>
529 <title>The Task List</title>
530
531 <para>
532 Based on the generated list of providers and the dependency information,
533 BitBake can now calculate exactly what tasks it needs to run and in what
534 order it needs to run them.
535 The
536 "<link linkend='executing-tasks'>Executing Tasks</link>" section has more
537 information on how BitBake chooses which task to execute next.
538 </para>
539
540 <para>
541 The build now starts with BitBake forking off threads up to the limit set in the
542 <link linkend='var-BB_NUMBER_THREADS'><filename>BB_NUMBER_THREADS</filename></link>
543 variable.
544 BitBake continues to fork threads as long as there are tasks ready to run,
545 those tasks have all their dependencies met, and the thread threshold has not been
546 exceeded.
547 </para>
548
549 <para>
550 It is worth noting that you can greatly speed up the build time by properly setting
551 the <filename>BB_NUMBER_THREADS</filename> variable.
552 </para>
553
554 <para>
555 As each task completes, a timestamp is written to the directory specified by the
556 <link linkend='var-STAMP'><filename>STAMP</filename></link> variable.
557 On subsequent runs, BitBake looks in the build directory within
558 <filename>tmp/stamps</filename> and does not rerun
559 tasks that are already completed unless a timestamp is found to be invalid.
560 Currently, invalid timestamps are only considered on a per
561 recipe file basis.
562 So, for example, if the configure stamp has a timestamp greater than the
563 compile timestamp for a given target, then the compile task would rerun.
564 Running the compile task again, however, has no effect on other providers
565 that depend on that target.
566 </para>
567
568 <para>
569 The exact format of the stamps is partly configurable.
570 In modern versions of BitBake, a hash is appended to the
571 stamp so that if the configuration changes, the stamp becomes
572 invalid and the task is automatically rerun.
573 This hash, or signature used, is governed by the signature policy
574 that is configured (see the
575 "<link linkend='checksums'>Checksums (Signatures)</link>"
576 section for information).
577 It is also possible to append extra metadata to the stamp using
578 the "stamp-extra-info" task flag.
579 For example, OpenEmbedded uses this flag to make some tasks machine-specific.
580 </para>
581
582 <note>
583 Some tasks are marked as "nostamp" tasks.
584 No timestamp file is created when these tasks are run.
585 Consequently, "nostamp" tasks are always rerun.
586 </note>
587
588 <para>
589 For more information on tasks, see the
590 "<link linkend='tasks'>Tasks</link>" section.
591 </para>
592 </section>
593
594 <section id='executing-tasks'>
595 <title>Executing Tasks</title>
596
597 <para>
598 Tasks can be either a shell task or a Python task.
599 For shell tasks, BitBake writes a shell script to
600 <filename>${</filename><link linkend='var-T'><filename>T</filename></link><filename>}/run.do_taskname.pid</filename>
601 and then executes the script.
602 The generated shell script contains all the exported variables,
603 and the shell functions with all variables expanded.
604 Output from the shell script goes to the file
605 <filename>${T}/log.do_taskname.pid</filename>.
606 Looking at the expanded shell functions in the run file and
607 the output in the log files is a useful debugging technique.
608 </para>
609
610 <para>
611 For Python tasks, BitBake executes the task internally and logs
612 information to the controlling terminal.
613 Future versions of BitBake will write the functions to files
614 similar to the way shell tasks are handled.
615 Logging will be handled in a way similar to shell tasks as well.
616 </para>
617
618 <para>
619 The order in which BitBake runs the tasks is controlled by its
620 task scheduler.
621 It is possible to configure the scheduler and define custom
622 implementations for specific use cases.
623 For more information, see these variables that control the
624 behavior:
625 <itemizedlist>
626 <listitem><para>
627 <link linkend='var-BB_SCHEDULER'><filename>BB_SCHEDULER</filename></link>
628 </para></listitem>
629 <listitem><para>
630 <link linkend='var-BB_SCHEDULERS'><filename>BB_SCHEDULERS</filename></link>
631 </para></listitem>
632 </itemizedlist>
633 It is possible to have functions run before and after a task's main
634 function.
635 This is done using the "prefuncs" and "postfuncs" flags of the task
636 that lists the functions to run.
637 </para>
638 </section>
639
640 <section id='checksums'>
641 <title>Checksums (Signatures)</title>
642
643 <para>
644 A checksum is a unique signature of a task's inputs.
645 The signature of a task can be used to determine if a task
646 needs to be run.
647 Because it is a change in a task's inputs that triggers running
648 the task, BitBake needs to detect all the inputs to a given task.
649 For shell tasks, this turns out to be fairly easy because
650 BitBake generates a "run" shell script for each task and
651 it is possible to create a checksum that gives you a good idea of when
652 the task's data changes.
653 </para>
654
655 <para>
656 To complicate the problem, some things should not be included in
657 the checksum.
658 First, there is the actual specific build path of a given task -
659 the working directory.
660 It does not matter if the working directory changes because it should not
661 affect the output for target packages.
662 The simplistic approach for excluding the working directory is to set
663 it to some fixed value and create the checksum for the "run" script.
664 BitBake goes one step better and uses the
665 <link linkend='var-BB_HASHBASE_WHITELIST'><filename>BB_HASHBASE_WHITELIST</filename></link>
666 variable to define a list of variables that should never be included
667 when generating the signatures.
668 </para>
669
670 <para>
671 Another problem results from the "run" scripts containing functions that
672 might or might not get called.
673 The incremental build solution contains code that figures out dependencies
674 between shell functions.
675 This code is used to prune the "run" scripts down to the minimum set,
676 thereby alleviating this problem and making the "run" scripts much more
677 readable as a bonus.
678 </para>
679
680 <para>
681 So far we have solutions for shell scripts.
682 What about Python tasks?
683 The same approach applies even though these tasks are more difficult.
684 The process needs to figure out what variables a Python function accesses
685 and what functions it calls.
686 Again, the incremental build solution contains code that first figures out
687 the variable and function dependencies, and then creates a checksum for the data
688 used as the input to the task.
689 </para>
690
691 <para>
692 Like the working directory case, situations exist where dependencies
693 should be ignored.
694 For these cases, you can instruct the build process to ignore a dependency
695 by using a line like the following:
696 <literallayout class='monospaced'>
697 PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
698 </literallayout>
699 This example ensures that the <filename>PACKAGE_ARCHS</filename> variable does not
700 depend on the value of <filename>MACHINE</filename>, even if it does reference it.
701 </para>
702
703 <para>
704 Equally, there are cases where we need to add dependencies BitBake
705 is not able to find.
706 You can accomplish this by using a line like the following:
707 <literallayout class='monospaced'>
708 PACKAGE_ARCHS[vardeps] = "MACHINE"
709 </literallayout>
710 This example explicitly adds the <filename>MACHINE</filename> variable as a
711 dependency for <filename>PACKAGE_ARCHS</filename>.
712 </para>
713
714 <para>
715 Consider a case with in-line Python, for example, where BitBake is not
716 able to figure out dependencies.
717 When running in debug mode (i.e. using <filename>-DDD</filename>), BitBake
718 produces output when it discovers something for which it cannot figure out
719 dependencies.
720 </para>
721
722 <para>
723 Thus far, this section has limited discussion to the direct inputs into a task.
724 Information based on direct inputs is referred to as the "basehash" in the
725 code.
726 However, there is still the question of a task's indirect inputs - the
727 things that were already built and present in the build directory.
728 The checksum (or signature) for a particular task needs to add the hashes
729 of all the tasks on which the particular task depends.
730 Choosing which dependencies to add is a policy decision.
731 However, the effect is to generate a master checksum that combines the basehash
732 and the hashes of the task's dependencies.
733 </para>
734
735 <para>
736 At the code level, there are a variety of ways both the basehash and the
737 dependent task hashes can be influenced.
738 Within the BitBake configuration file, we can give BitBake some extra information
739 to help it construct the basehash.
740 The following statement effectively results in a list of global variable
741 dependency excludes - variables never included in any checksum.
742 This example uses variables from OpenEmbedded to help illustrate
743 the concept:
744 <literallayout class='monospaced'>
745 BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \
746 SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
747 USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
748 PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
749 CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
750 </literallayout>
751 The previous example excludes the work directory, which is part of
752 <filename>TMPDIR</filename>.
753 </para>
754
755 <para>
756 The rules for deciding which hashes of dependent tasks to include through
757 dependency chains are more complex and are generally accomplished with a
758 Python function.
759 The code in <filename>meta/lib/oe/sstatesig.py</filename> shows two examples
760 of this and also illustrates how you can insert your own policy into the system
761 if so desired.
762 This file defines the two basic signature generators OpenEmbedded Core
763 uses: "OEBasic" and "OEBasicHash".
764 By default, there is a dummy "noop" signature handler enabled in BitBake.
765 This means that behavior is unchanged from previous versions.
766 <filename>OE-Core</filename> uses the "OEBasicHash" signature handler by default
767 through this setting in the <filename>bitbake.conf</filename> file:
768 <literallayout class='monospaced'>
769 BB_SIGNATURE_HANDLER ?= "OEBasicHash"
770 </literallayout>
771 The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename> is the same as the
772 "OEBasic" version but adds the task hash to the stamp files.
773 This results in any metadata change that changes the task hash, automatically
774 causing the task to be run again.
775 This removes the need to bump
776 <link linkend='var-PR'><filename>PR</filename></link>
777 values, and changes to metadata automatically ripple across the build.
778 </para>
779
780 <para>
781 It is also worth noting that the end result of these signature generators is to
782 make some dependency and hash information available to the build.
783 This information includes:
784 <itemizedlist>
785 <listitem><para><filename>BB_BASEHASH_task-&lt;taskname&gt;</filename>:
786 The base hashes for each task in the recipe.
787 </para></listitem>
788 <listitem><para><filename>BB_BASEHASH_&lt;filename:taskname&gt;</filename>:
789 The base hashes for each dependent task.
790 </para></listitem>
791 <listitem><para><filename>BBHASHDEPS_&lt;filename:taskname&gt;</filename>:
792 The task dependencies for each task.
793 </para></listitem>
794 <listitem><para><filename>BB_TASKHASH</filename>:
795 The hash of the currently running task.
796 </para></listitem>
797 </itemizedlist>
798 </para>
799
800 <para>
801 It is worth noting that BitBake's "-S" option lets you
802 debug Bitbake's processing of signatures.
803 The options passed to -S allow different debugging modes
804 to be used, either using BitBake's own debug functions
805 or possibly those defined in the metadata/signature handler
806 itself.
807 The simplest parameter to pass is "none", which causes a
808 set of signature information to be written out into
809 <filename>STAMP_DIR</filename>
810 corresponding to the targets specified.
811 The other currently available parameter is "printdiff",
812 which causes BitBake to try to establish the closest
813 signature match it can (e.g. in the sstate cache) and then
814 run <filename>bitbake-diffsigs</filename> over the matches
815 to determine the stamps and delta where these two
816 stamp trees diverge.
817 <note>
818 It is likely that future versions of BitBake will
819 provide other signature handlers triggered through
820 additional "-S" parameters.
821 </note>
822 </para>
823
824 <para>
825 You can find more information on checksum metadata in the
826 "<link linkend='task-checksums-and-setscene'>Task Checksums and Setscene</link>"
827 section.
828 </para>
829 </section>
830
831 <section id='setscene'>
832 <title>Setscene</title>
833
834 <para>
835 The setscene process enables BitBake to handle "pre-built" artifacts.
836 The ability to handle and reuse these artifacts allows BitBake
837 the luxury of not having to build something from scratch every time.
838 Instead, BitBake can use, when possible, existing build artifacts.
839 </para>
840
841 <para>
842 BitBake needs to have reliable data indicating whether or not an
843 artifact is compatible.
844 Signatures, described in the previous section, provide an ideal
845 way of representing whether an artifact is compatible.
846 If a signature is the same, an object can be reused.
847 </para>
848
849 <para>
850 If an object can be reused, the problem then becomes how to
851 replace a given task or set of tasks with the pre-built artifact.
852 BitBake solves the problem with the "setscene" process.
853 </para>
854
855 <para>
856 When BitBake is asked to build a given target, before building anything,
857 it first asks whether cached information is available for any of the
858 targets it's building, or any of the intermediate targets.
859 If cached information is available, BitBake uses this information instead of
860 running the main tasks.
861 </para>
862
863 <para>
864 BitBake first calls the function defined by the
865 <link linkend='var-BB_HASHCHECK_FUNCTION'><filename>BB_HASHCHECK_FUNCTION</filename></link>
866 variable with a list of tasks and corresponding
867 hashes it wants to build.
868 This function is designed to be fast and returns a list
869 of the tasks for which it believes in can obtain artifacts.
870 </para>
871
872 <para>
873 Next, for each of the tasks that were returned as possibilities,
874 BitBake executes a setscene version of the task that the possible
875 artifact covers.
876 Setscene versions of a task have the string "_setscene" appended to the
877 task name.
878 So, for example, the task with the name <filename>xxx</filename> has
879 a setscene task named <filename>xxx_setscene</filename>.
880 The setscene version of the task executes and provides the necessary
881 artifacts returning either success or failure.
882 </para>
883
884 <para>
885 As previously mentioned, an artifact can cover more than one task.
886 For example, it is pointless to obtain a compiler if you
887 already have the compiled binary.
888 To handle this, BitBake calls the
889 <link linkend='var-BB_SETSCENE_DEPVALID'><filename>BB_SETSCENE_DEPVALID</filename></link>
890 function for each successful setscene task to know whether or not it needs
891 to obtain the dependencies of that task.
892 </para>
893
894 <para>
895 Finally, after all the setscene tasks have executed, BitBake calls the
896 function listed in
897 <link linkend='var-BB_SETSCENE_VERIFY_FUNCTION'><filename>BB_SETSCENE_VERIFY_FUNCTION</filename></link>
898 with the list of tasks BitBake thinks has been "covered".
899 The metadata can then ensure that this list is correct and can
900 inform BitBake that it wants specific tasks to be run regardless
901 of the setscene result.
902 </para>
903
904 <para>
905 You can find more information on setscene metadata in the
906 "<link linkend='task-checksums-and-setscene'>Task Checksums and Setscene</link>"
907 section.
908 </para>
909 </section>
910</chapter>