blob: 17f4c54b9cdab457097af2affc73adc240868f65 [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[<!ENTITY % poky SYSTEM "../poky.ent"> %poky; ] >
4
5<chapter id='ref-bitbake'>
6
7 <title>BitBake</title>
8
9 <para>
10 BitBake is a program written in Python that interprets the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011 <link linkend='metadata'>Metadata</link> used by
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012 the OpenEmbedded build system.
13 At some point, developers wonder what actually happens when you enter:
14 <literallayout class='monospaced'>
15 $ bitbake core-image-sato
16 </literallayout>
17 </para>
18
19 <para>
20 This chapter provides an overview of what happens behind the scenes from BitBake's perspective.
21 </para>
22
23 <note>
24 BitBake strives to be a generic "task" executor that is capable of handling complex dependency relationships.
25 As such, it has no real knowledge of what the tasks being executed actually do.
26 BitBake just considers a list of tasks with dependencies and handles
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027 <link linkend='metadata'>Metadata</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028 consisting of variables in a certain format that get passed to the tasks.
29 </note>
30
31 <section id='ref-bitbake-parsing'>
32 <title>Parsing</title>
33
34 <para>
35 BitBake parses configuration files, classes, and <filename>.bb</filename> files.
36 </para>
37
38 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039 The first thing BitBake does is look for the
40 <filename>bitbake.conf</filename> file.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041 This file resides in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042 <link linkend='source-directory'>Source Directory</link>
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 within the <filename>meta/conf/</filename> directory.
44 BitBake finds it by examining its
45 <link linkend='var-BBPATH'><filename>BBPATH</filename></link> environment
46 variable and looking for the <filename>meta/conf/</filename>
47 directory.
48 </para>
49
50 <para>
51 The <filename>bitbake.conf</filename> file lists other configuration
52 files to include from a <filename>conf/</filename>
53 directory below the directories listed in <filename>BBPATH</filename>.
54 In general, the most important configuration file from a user's perspective
55 is <filename>local.conf</filename>, which contains a user's customized
56 settings for the OpenEmbedded build environment.
57 Other notable configuration files are the distribution
58 configuration file (set by the
59 <filename><link linkend='var-DISTRO'>DISTRO</link></filename> variable)
60 and the machine configuration file
61 (set by the
62 <filename><link linkend='var-MACHINE'>MACHINE</link></filename> variable).
63 The <filename>DISTRO</filename> and <filename>MACHINE</filename> BitBake environment
64 variables are both usually set in
65 the <filename>local.conf</filename> file.
66 Valid distribution
67 configuration files are available in the <filename>meta/conf/distro/</filename> directory
68 and valid machine configuration
69 files in the <filename>meta/conf/machine/</filename> directory.
70 Within the <filename>meta/conf/machine/include/</filename>
71 directory are various <filename>tune-*.inc</filename> configuration files that provide common
72 "tuning" settings specific to and shared between particular architectures and machines.
73 </para>
74
75 <para>
76 After the parsing of the configuration files, some standard classes are included.
77 The <filename>base.bbclass</filename> file is always included.
78 Other classes that are specified in the configuration using the
79 <filename><link linkend='var-INHERIT'>INHERIT</link></filename>
80 variable are also included.
81 Class files are searched for in a <filename>classes</filename> subdirectory
82 under the paths in <filename>BBPATH</filename> in the same way as
83 configuration files.
84 </para>
85
86 <para>
87 After classes are included, the variable
88 <filename><link linkend='var-BBFILES'>BBFILES</link></filename>
89 is set, usually in
90 <filename>local.conf</filename>, and defines the list of places to search for
91 <filename>.bb</filename> files.
92 By default, the <filename>BBFILES</filename> variable specifies the
93 <filename>meta/recipes-*/</filename> directory within Poky.
94 Adding extra content to <filename>BBFILES</filename> is best achieved through the use of
95 BitBake layers as described in the
Brad Bishopd7bf8c12018-02-25 22:55:05 -050096 "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and Creating Layers</ulink>"
97 section of the Yocto Project Development Tasks Manual.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050098 </para>
99
100 <para>
101 BitBake parses each <filename>.bb</filename> file in <filename>BBFILES</filename> and
102 stores the values of various variables.
103 In summary, for each <filename>.bb</filename>
104 file the configuration plus the base class of variables are set, followed
105 by the data in the <filename>.bb</filename> file
106 itself, followed by any inherit commands that
107 <filename>.bb</filename> file might contain.
108 </para>
109
110 <para>
111 Because parsing <filename>.bb</filename> files is a time
112 consuming process, a cache is kept to speed up subsequent parsing.
113 This cache is invalid if the timestamp of the <filename>.bb</filename>
114 file itself changes, or if the timestamps of any of the include,
115 configuration files or class files on which the
116 <filename>.bb</filename> file depends change.
117 </para>
118
119 <note>
120 <para>
121 You need to be aware of how BitBake parses curly braces.
122 If a recipe uses a closing curly brace within the function and
123 the character has no leading spaces, BitBake produces a parsing
124 error.
125 If you use a pair of curly brace in a shell function, the
126 closing curly brace must not be located at the start of the line
127 without leading spaces.
128 </para>
129
130 <para>
131 Here is an example that causes BitBake to produce a parsing
132 error:
133 <literallayout class='monospaced'>
134 fakeroot create_shar() {
135 cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
136 usage()
137 {
138 echo "test"
139 ###### The following "}" at the start of the line causes a parsing error ######
140 }
141 EOF
142 }
143 </literallayout>
144 Writing the recipe this way avoids the error:
145 <literallayout class='monospaced'>
146 fakeroot create_shar() {
147 cat &lt;&lt; "EOF" &gt; ${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh
148 usage()
149 {
150 echo "test"
151 ######The following "}" with a leading space at the start of the line avoids the error ######
152 }
153 EOF
154 }
155 </literallayout>
156 </para>
157 </note>
158 </section>
159
160 <section id='ref-bitbake-providers'>
161 <title>Preferences and Providers</title>
162
163 <para>
164 Once all the <filename>.bb</filename> files have been
165 parsed, BitBake starts to build the target (<filename>core-image-sato</filename>
166 in the previous section's example) and looks for providers of that target.
167 Once a provider is selected, BitBake resolves all the dependencies for
168 the target.
169 In the case of <filename>core-image-sato</filename>, it would lead to
170 <filename>packagegroup-core-x11-sato</filename>,
171 which in turn leads to recipes like <filename>matchbox-terminal</filename>,
172 <filename>pcmanfm</filename> and <filename>gthumb</filename>.
173 These recipes in turn depend on <filename>glibc</filename> and the toolchain.
174 </para>
175
176 <para>
177 Sometimes a target might have multiple providers.
178 A common example is "virtual/kernel", which is provided by each kernel package.
179 Each machine often selects the best kernel provider by using a line similar to the
180 following in the machine configuration file:
181 </para>
182
183 <literallayout class='monospaced'>
184 PREFERRED_PROVIDER_virtual/kernel = "linux-yocto"
185 </literallayout>
186
187 <para>
188 The default <filename><link linkend='var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</link></filename>
189 is the provider with the same name as the target.
190 </para>
191
192 <para>
193 Understanding how providers are chosen is made complicated by the fact
194 that multiple versions might exist.
195 BitBake defaults to the highest version of a provider.
196 Version comparisons are made using the same method as Debian.
197 You can use the
198 <filename><link linkend='var-PREFERRED_VERSION'>PREFERRED_VERSION</link></filename>
199 variable to specify a particular version (usually in the distro configuration).
200 You can influence the order by using the
201 <filename><link linkend='var-DEFAULT_PREFERENCE'>DEFAULT_PREFERENCE</link></filename>
202 variable.
203 By default, files have a preference of "0".
204 Setting the <filename>DEFAULT_PREFERENCE</filename> to "-1" makes the
205 package unlikely to be used unless it is explicitly referenced.
206 Setting the <filename>DEFAULT_PREFERENCE</filename> to "1" makes it likely the package is used.
207 <filename>PREFERRED_VERSION</filename> overrides any <filename>DEFAULT_PREFERENCE</filename> setting.
208 <filename>DEFAULT_PREFERENCE</filename> is often used to mark newer and more experimental package
209 versions until they have undergone sufficient testing to be considered stable.
210 </para>
211
212 <para>
213 In summary, BitBake has created a list of providers, which is prioritized, for each target.
214 </para>
215 </section>
216
217 <section id='ref-bitbake-dependencies'>
218 <title>Dependencies</title>
219
220 <para>
221 Each target BitBake builds consists of multiple tasks such as
222 <filename>fetch</filename>, <filename>unpack</filename>,
223 <filename>patch</filename>, <filename>configure</filename>,
224 and <filename>compile</filename>.
225 For best performance on multi-core systems, BitBake considers each task as an independent
226 entity with its own set of dependencies.
227 </para>
228
229 <para>
230 Dependencies are defined through several variables.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500231 You can find information about variables BitBake uses in the
232 BitBake documentation, which is found in the
233 <filename>bitbake/doc/manual</filename> directory within the
234 <link linkend='source-directory'>Source Directory</link>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235 At a basic level, it is sufficient to know that BitBake uses the
236 <filename><link linkend='var-DEPENDS'>DEPENDS</link></filename> and
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500237 <filename><link linkend='var-RDEPENDS'>RDEPENDS</link></filename>
238 variables when calculating dependencies.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239 </para>
240 </section>
241
242 <section id='ref-bitbake-tasklist'>
243 <title>The Task List</title>
244
245 <para>
246 Based on the generated list of providers and the dependency information,
247 BitBake can now calculate exactly what tasks it needs to run and in what
248 order it needs to run them.
249 The build now starts with BitBake forking off threads up to the limit set in the
250 <filename><link linkend='var-BB_NUMBER_THREADS'>BB_NUMBER_THREADS</link></filename> variable.
251 BitBake continues to fork threads as long as there are tasks ready to run,
252 those tasks have all their dependencies met, and the thread threshold has not been
253 exceeded.
254 </para>
255
256 <para>
257 It is worth noting that you can greatly speed up the build time by properly setting
258 the <filename>BB_NUMBER_THREADS</filename> variable.
259 See the
260 "<ulink url='&YOCTO_DOCS_QS_URL;#qs-building-images'>Building Images</ulink>"
261 section in the Yocto Project Quick Start for more information.
262 </para>
263
264 <para>
265 As each task completes, a timestamp is written to the directory specified by the
266 <filename><link linkend='var-STAMP'>STAMP</link></filename> variable.
267 On subsequent runs, BitBake looks within the <filename>build/tmp/stamps</filename>
268 directory and does not rerun
269 tasks that are already completed unless a timestamp is found to be invalid.
270 Currently, invalid timestamps are only considered on a per
271 <filename>.bb</filename> file basis.
272 So, for example, if the configure stamp has a timestamp greater than the
273 compile timestamp for a given target, then the compile task would rerun.
274 Running the compile task again, however, has no effect on other providers
275 that depend on that target.
276 This behavior could change or become configurable in future versions of BitBake.
277 </para>
278
279 <note>
280 Some tasks are marked as "nostamp" tasks.
281 No timestamp file is created when these tasks are run.
282 Consequently, "nostamp" tasks are always rerun.
283 </note>
284 </section>
285
286 <section id='ref-bitbake-runtask'>
287 <title>Running a Task</title>
288
289 <para>
290 Tasks can either be a shell task or a Python task.
291 For shell tasks, BitBake writes a shell script to
292 <filename>${WORKDIR}/temp/run.do_taskname.pid</filename> and then executes the script.
293 The generated shell script contains all the exported variables, and the shell functions
294 with all variables expanded.
295 Output from the shell script goes to the file <filename>${WORKDIR}/temp/log.do_taskname.pid</filename>.
296 Looking at the expanded shell functions in the run file and the output in the log files
297 is a useful debugging technique.
298 </para>
299
300 <para>
301 For Python tasks, BitBake executes the task internally and logs information to the
302 controlling terminal.
303 Future versions of BitBake will write the functions to files similar to the way
304 shell tasks are handled.
305 Logging will be handled in a way similar to shell tasks as well.
306 </para>
307
308 <para>
309 Once all the tasks have been completed BitBake exits.
310 </para>
311
312 <para>
313 When running a task, BitBake tightly controls the execution environment
314 of the build tasks to make sure unwanted contamination from the build machine
315 cannot influence the build.
316 Consequently, if you do want something to get passed into the build
317 task's environment, you must take a few steps:
318 <orderedlist>
319 <listitem><para>Tell BitBake to load what you want from the environment
320 into the data store.
321 You can do so through the <filename>BB_ENV_EXTRAWHITE</filename>
322 variable.
323 For example, assume you want to prevent the build system from
324 accessing your <filename>$HOME/.ccache</filename> directory.
325 The following command tells BitBake to load
326 <filename>CCACHE_DIR</filename> from the environment into the data
327 store:
328 <literallayout class='monospaced'>
329 export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE CCACHE_DIR"
330 </literallayout></para></listitem>
331 <listitem><para>Tell BitBake to export what you have loaded into the
332 environment store to the task environment of every running task.
333 Loading something from the environment into the data store
334 (previous step) only makes it available in the datastore.
335 To export it to the task environment of every running task,
336 use a command similar to the following in your
337 <filename>local.conf</filename> or distro configuration file:
338 <literallayout class='monospaced'>
339 export CCACHE_DIR
340 </literallayout></para></listitem>
341 </orderedlist>
342 </para>
343
344 <note>
345 A side effect of the previous steps is that BitBake records the variable
346 as a dependency of the build process in things like the shared state
347 checksums.
348 If doing so results in unnecessary rebuilds of tasks, you can whitelist the
349 variable so that the shared state code ignores the dependency when it creates
350 checksums.
351 For information on this process, see the <filename>BB_HASHBASE_WHITELIST</filename>
352 example in the "<link linkend='checksums'>Checksums (Signatures)</link>" section.
353 </note>
354 </section>
355
356 <section id='ref-bitbake-commandline'>
357 <title>BitBake Command Line</title>
358
359 <para>
360 Following is the BitBake help output:
361 </para>
362
363 <screen>
364$ bitbake --help
365Usage: bitbake [options] [recipename/target ...]
366
367 Executes the specified task (default is 'build') for a given set of target recipes (.bb files).
368 It is assumed there is a conf/bblayers.conf available in cwd or in BBPATH which
369 will provide the layer, BBFILES and other configuration information.
370
371Options:
372 --version show program's version number and exit
373 -h, --help show this help message and exit
374 -b BUILDFILE, --buildfile=BUILDFILE
375 Execute tasks from a specific .bb recipe directly.
376 WARNING: Does not handle any dependencies from other
377 recipes.
378 -k, --continue Continue as much as possible after an error. While the
379 target that failed and anything depending on it cannot
380 be built, as much as possible will be built before
381 stopping.
382 -a, --tryaltconfigs Continue with builds by trying to use alternative
383 providers where possible.
384 -f, --force Force the specified targets/task to run (invalidating
385 any existing stamp file).
386 -c CMD, --cmd=CMD Specify the task to execute. The exact options
387 available depend on the metadata. Some examples might
388 be 'compile' or 'populate_sysroot' or 'listtasks' may
389 give a list of the tasks available.
390 -C INVALIDATE_STAMP, --clear-stamp=INVALIDATE_STAMP
391 Invalidate the stamp for the specified task such as
392 'compile' and then run the default task for the
393 specified target(s).
394 -r PREFILE, --read=PREFILE
395 Read the specified file before bitbake.conf.
396 -R POSTFILE, --postread=POSTFILE
397 Read the specified file after bitbake.conf.
398 -v, --verbose Output more log message data to the terminal.
399 -D, --debug Increase the debug level. You can specify this more
400 than once.
401 -n, --dry-run Don't execute, just go through the motions.
402 -S, --dump-signatures
403 Don't execute, just dump out the signature
404 construction information.
405 -p, --parse-only Quit after parsing the BB recipes.
406 -s, --show-versions Show current and preferred versions of all recipes.
407 -e, --environment Show the global or per-package environment complete
408 with information about where variables were
409 set/changed.
410 -g, --graphviz Save dependency tree information for the specified
411 targets in the dot syntax.
412 -I EXTRA_ASSUME_PROVIDED, --ignore-deps=EXTRA_ASSUME_PROVIDED
413 Assume these dependencies don't exist and are already
414 provided (equivalent to ASSUME_PROVIDED). Useful to
415 make dependency graphs more appealing
416 -l DEBUG_DOMAINS, --log-domains=DEBUG_DOMAINS
417 Show debug logging for the specified logging domains
418 -P, --profile Profile the command and save reports.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500419 -u UI, --ui=UI The user interface to use (e.g. knotty and taskexp).
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420 -t SERVERTYPE, --servertype=SERVERTYPE
421 Choose which server to use, process or xmlrpc.
422 --revisions-changed Set the exit code depending on whether upstream
423 floating revisions have changed or not.
424 --server-only Run bitbake without a UI, only starting a server
425 (cooker) process.
426 -B BIND, --bind=BIND The name/address for the bitbake server to bind to.
427 --no-setscene Do not run any setscene tasks. sstate will be ignored
428 and everything needed, built.
429 --remote-server=REMOTE_SERVER
430 Connect to the specified server.
431 -m, --kill-server Terminate the remote server.
432 --observe-only Connect to a server as an observing-only client.
433 </screen>
434 </section>
435
436 <section id='ref-bitbake-fetchers'>
437 <title>Fetchers</title>
438
439 <para>
440 BitBake also contains a set of "fetcher" modules that allow
441 retrieval of source code from various types of sources.
442 For example, BitBake can get source code from a disk with the metadata, from websites,
443 from remote shell accounts, or from Source Code Management (SCM) systems
444 like <filename>cvs/subversion/git</filename>.
445 </para>
446
447 <para>
448 Fetchers are usually triggered by entries in
449 <filename><link linkend='var-SRC_URI'>SRC_URI</link></filename>.
450 You can find information about the options and formats of entries for specific
451 fetchers in the BitBake manual located in the
452 <filename>bitbake/doc/manual</filename> directory of the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500453 <link linkend='source-directory'>Source Directory</link>.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500454 </para>
455
456 <para>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500457 One useful feature for certain Source Code Manager (SCM) fetchers
458 is the ability to "auto-update" when the upstream SCM changes
459 version.
460 Since this ability requires certain functionality from the SCM,
461 not all systems support it.
462 Currently Subversion, Bazaar and to a limited extent, Git support
463 the ability to "auto-update".
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500464 This feature works using the <filename><link linkend='var-SRCREV'>SRCREV</link></filename>
465 variable.
466 See the
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500467 "<ulink url='&YOCTO_DOCS_DEV_URL;#platdev-appdev-srcrev'>Using an External SCM</ulink>"
468 section in the Yocto Project Development Tasks Manual for more
469 information.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500470 </para>
471
472 </section>
473
474</chapter>
475<!--
476vim: expandtab tw=80 ts=4 spell spelllang=en_gb
477-->