ref-bitbake.xml 23 KB

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