bitbake-user-manual-execution.xml 48 KB

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