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