ref-bitbake.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. <!DOCTYPE appendix PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  2. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  3. <appendix id='ref-bitbake'>
  4. <title>Reference: Bitbake</title>
  5. <para>
  6. Bitbake is a program written in Python that interprets the metadata
  7. that makes up Poky. At some point, people wonder what actually happens
  8. when you type <command>bitbake poky-image-sato</command>. This section
  9. aims to give an overview of what happens behind the scenes from a
  10. BitBake perspective.
  11. </para>
  12. <para>
  13. It is worth noting that bitbake aims to be a generic "task" executor
  14. capable of handling complex dependency relationships. As such it has no
  15. real knowledge of what the tasks it is executing actually do. It just
  16. considers a list of tasks with dependencies and handles metadata
  17. consisting of variables in a certain format which get passed to the
  18. tasks.
  19. </para>
  20. <section id='ref-bitbake-parsing'>
  21. <title>Parsing</title>
  22. <para>
  23. The first thing BitBake does is that work out its configuration by
  24. looking for a file called <filename>bitbake.conf</filename>.
  25. Bitbake searches through the <varname>BBPATH</varname> environment
  26. variable looking for a <filename class="directory">conf/</filename>
  27. directory containing a <filename>bitbake.conf</filename> file and
  28. adds the first <filename>bitbake.conf</filename> file found in
  29. <varname>BBPATH</varname> (similar to the PATH environment variable).
  30. For Poky, <filename>bitbake.conf</filename> is found in <filename
  31. class="directory">meta/conf/</filename>.
  32. </para>
  33. <para>
  34. In Poky, <filename>bitbake.conf</filename> lists other configuration
  35. files to include from a <filename class="directory">conf/</filename>
  36. directory below the directories listed in <varname>BBPATH</varname>.
  37. In general the most important configuration file from a user's perspective
  38. is <filename>local.conf</filename>, which contains a users customized
  39. settings for Poky. Other notable configuration files are the distribution
  40. configuration file (set by the <glossterm><link linkend='var-DISTRO'>
  41. DISTRO</link></glossterm> variable) and the machine configuration file
  42. (set by the <glossterm><link linkend='var-MACHINE'>MACHINE</link>
  43. </glossterm> variable). The <glossterm><link linkend='var-DISTRO'>
  44. DISTRO</link></glossterm> and <glossterm><link linkend='var-MACHINE'>
  45. MACHINE</link></glossterm> environment variables are both usually set in
  46. the <filename>local.conf</filename> file. Valid distribution
  47. configuration files are available in the <filename class="directory">
  48. meta/conf/distro/</filename> directory and valid machine configuration
  49. files in the <filename class="directory">meta/conf/machine/</filename>
  50. directory. Within the <filename class="directory">
  51. meta/conf/machine/include/</filename> directory are various <filename>
  52. tune-*.inc</filename> configuration files which provide common
  53. "tuning" settings specific to and shared between particular
  54. architectures and machines.
  55. </para>
  56. <para>
  57. After the parsing of the configuration files some standard classes
  58. are included. In particular, <filename>base.bbclass</filename> is
  59. always included, as will any other classes
  60. specified in the configuration using the <glossterm><link
  61. linkend='var-INHERIT'>INHERIT</link></glossterm>
  62. variable. Class files are searched for in a classes subdirectory
  63. under the paths in <varname>BBPATH</varname> in the same way as
  64. configuration files.
  65. </para>
  66. <para>
  67. After the parsing of the configuration files is complete, the
  68. variable <glossterm><link linkend='var-BBFILES'>BBFILES</link></glossterm>
  69. is set, usually in
  70. <filename>local.conf</filename>, and defines the list of places to search for
  71. <filename class="extension">.bb</filename> files. By
  72. default this specifies the <filename class="directory">meta/packages/
  73. </filename> directory within Poky, but other directories such as
  74. <filename class="directory">meta-extras/</filename> can be included
  75. too. Adding extra content to
  76. <glossterm><link linkend='var-BBFILES'>BBFILES</link></glossterm> is best
  77. acheived through the use of Bitbake
  78. <link linkend='usingpoky-changes-layers'>"layers"</link>.
  79. </para>
  80. <para>
  81. Bitbake parses each <filename class="extension">.bb</filename> file in
  82. <glossterm><link linkend='var-BBFILES'>BBFILES</link></glossterm> and
  83. stores the values of various variables. In summary, for each
  84. <filename class="extension">.bb</filename>
  85. file the configuration + base class of variables are set, followed
  86. by the data in the <filename class="extension">.bb</filename> file
  87. itself, followed by any inherit commands that
  88. <filename class="extension">.bb</filename> file might contain.
  89. </para>
  90. <para>
  91. Parsing <filename class="extension">.bb</filename> files is a time
  92. consuming process, so a cache is kept to speed up subsequent parsing.
  93. This cache is invalid if the timestamp of the <filename class="extension">.bb</filename>
  94. file itself has changed, or if the timestamps of any of the include,
  95. configuration or class files the <filename class="extension">.bb</filename>
  96. file depends on have changed.
  97. </para>
  98. </section>
  99. <section id='ref-bitbake-providers'>
  100. <title>Preferences and Providers</title>
  101. <para>
  102. Once all the <filename class="extension">.bb</filename> files have been
  103. parsed, BitBake will proceed to build "poky-image-sato" (or whatever was
  104. specified on the commandline) and looks for providers of that target.
  105. Once a provider is selected, BitBake resolves all the dependencies for
  106. the target. In the case of "poky-image-sato", it would lead to
  107. <filename>task-base.bb</filename>
  108. which in turn would lead to packages like <application>Contacts</application>,
  109. <application>Dates</application>, <application>BusyBox</application>
  110. and these in turn depend on glibc and the toolchain.
  111. </para>
  112. <para>
  113. Sometimes a target might have multiple providers and a common example
  114. is "virtual/kernel" that is provided by each kernel package. Each machine
  115. will often elect the best provider of its kernel with a line like the
  116. following in the machine configuration file:
  117. </para>
  118. <programlisting><glossterm><link linkend='var-PREFERRED_PROVIDER'>PREFERRED_PROVIDER</link></glossterm>_virtual/kernel = "linux-rp"</programlisting>
  119. <para>
  120. The default <glossterm><link linkend='var-PREFERRED_PROVIDER'>
  121. PREFERRED_PROVIDER</link></glossterm> is the provider with the same name as
  122. the target.
  123. </para>
  124. <para>
  125. Understanding how providers are chosen is complicated by the fact
  126. multiple versions might be present. Bitbake defaults to the highest
  127. version of a provider by default. Version comparisons are made using
  128. the same method as Debian. The <glossterm><link
  129. linkend='var-PREFERRED_VERSION'>PREFERRED_VERSION</link></glossterm>
  130. variable can be used to specify a particular version
  131. (usually in the distro configuration) but the order can
  132. also be influenced by the <glossterm><link
  133. linkend='var-DEFAULT_PREFERENCE'>DEFAULT_PREFERENCE</link></glossterm>
  134. variable. By default files
  135. have a preference of "0". Setting the
  136. <glossterm><link
  137. linkend='var-DEFAULT_PREFERENCE'>DEFAULT_PREFERENCE</link></glossterm> to "-1" will
  138. make a package unlikely to be used unless it was explicitly referenced and
  139. "1" makes it likely the package will be used.
  140. <glossterm><link
  141. linkend='var-PREFERRED_VERSION'>PREFERRED_VERSION</link></glossterm> overrides
  142. any <glossterm><link
  143. linkend='var-DEFAULT_PREFERENCE'>DEFAULT_PREFERENCE</link></glossterm>. <glossterm><link
  144. linkend='var-DEFAULT_PREFERENCE'>DEFAULT_PREFERENCE</link></glossterm>
  145. is often used to mark more
  146. experimental new versions of packages until they've undergone sufficient
  147. testing to be considered stable.
  148. </para>
  149. <para>
  150. The end result is that internally, BitBake has now built a list of
  151. providers for each target it needs in order of priority.
  152. </para>
  153. </section>
  154. <section id='ref-bitbake-dependencies'>
  155. <title>Dependencies</title>
  156. <para>
  157. Each target BitBake builds consists of multiple tasks (e.g. fetch,
  158. unpack, patch, configure, compile etc.). For best performance on
  159. multi-core systems, BitBake considers each task as an independent
  160. entity with a set of dependencies. There are many variables that
  161. are used to signify these dependencies and more information can be found
  162. about these in the <ulink url='http://bitbake.berlios.de/manual/'>
  163. BitBake manual</ulink>. At a basic level it is sufficient to know
  164. that BitBake uses the <glossterm><link
  165. linkend='var-DEPENDS'>DEPENDS</link></glossterm> and
  166. <glossterm><link linkend='var-RDEPENDS'>RDEPENDS</link></glossterm> variables when
  167. calculating dependencies and descriptions of these variables are
  168. available through the links.
  169. </para>
  170. </section>
  171. <section id='ref-bitbake-tasklist'>
  172. <title>The Task List</title>
  173. <para>
  174. Based on the generated list of providers and the dependency information,
  175. BitBake can now calculate exactly which tasks it needs to run and in what
  176. order. The build now starts with BitBake forking off threads up to
  177. the limit set in the <glossterm><link
  178. linkend='var-BB_NUMBER_THREADS'>BB_NUMBER_THREADS</link></glossterm> variable
  179. as long as there are tasks ready to run, i.e. tasks with all their
  180. dependencies met.
  181. </para>
  182. <para>
  183. As each task completes, a timestamp is written to the directory
  184. specified by the <glossterm><link
  185. linkend='var-STAMPS'>STAMPS</link></glossterm> variable (usually
  186. <filename class="directory">build/tmp/stamps/*/</filename>). On
  187. subsequent runs, BitBake looks at the <glossterm><link
  188. linkend='var-STAMPS'>STAMPS</link></glossterm>
  189. directory and will not rerun
  190. tasks its already completed unless a timestamp is found to be invalid.
  191. Currently, invalid timestamps are only considered on a per <filename
  192. class="extension">.bb</filename> file basis so if for example the configure stamp has a timestamp greater than the
  193. compile timestamp for a given target the compile task would rerun but this
  194. has no effect on other providers depending on that target. This could
  195. change or become configurable in future versions of BitBake. Some tasks
  196. are marked as "nostamp" tasks which means no timestamp file will be written
  197. and the task will always rerun.
  198. </para>
  199. <para>Once all the tasks have been completed BitBake exits.</para>
  200. </section>
  201. <section id='ref-bitbake-runtask'>
  202. <title>Running a Task</title>
  203. <para>
  204. It's worth noting what BitBake does to run a task. A task can either
  205. be a shell task or a python task. For shell tasks, BitBake writes a
  206. shell script to <filename>${WORKDIR}/temp/run.do_taskname.pid</filename>
  207. and then executes the script. The generated
  208. shell script contains all the exported variables, and the shell functions
  209. with all variables expanded. Output from the shell script is
  210. sent to the file <filename>${WORKDIR}/temp/log.do_taskname.pid</filename>.
  211. Looking at the
  212. expanded shell functions in the run file and the output in the log files
  213. is a useful debugging technique.
  214. </para>
  215. <para>
  216. Python functions are executed internally to BitBake itself and
  217. logging goes to the controlling terminal. Future versions of BitBake will
  218. write the functions to files in a similar way to shell functions and
  219. logging will also go to the log files in a similar way.
  220. </para>
  221. </section>
  222. <section id='ref-bitbake-commandline'>
  223. <title>Commandline</title>
  224. <para>
  225. To quote from "bitbake --help":
  226. </para>
  227. <screen>Usage: bitbake [options] [package ...]
  228. Executes the specified task (default is 'build') for a given set of BitBake files.
  229. It expects that BBFILES is defined, which is a space separated list of files to
  230. be executed. BBFILES does support wildcards.
  231. Default BBFILES are the .bb files in the current directory.
  232. Options:
  233. --version show program's version number and exit
  234. -h, --help show this help message and exit
  235. -b BUILDFILE, --buildfile=BUILDFILE
  236. execute the task against this .bb file, rather than a
  237. package from BBFILES.
  238. -k, --continue continue as much as possible after an error. While the
  239. target that failed, and those that depend on it,
  240. cannot be remade, the other dependencies of these
  241. targets can be processed all the same.
  242. -a, --tryaltconfigs continue with builds by trying to use alternative
  243. providers where possible.
  244. -f, --force force run of specified cmd, regardless of stamp status
  245. -c CMD, --cmd=CMD Specify task to execute. Note that this only executes
  246. the specified task for the providee and the packages
  247. it depends on, i.e. 'compile' does not implicitly call
  248. stage for the dependencies (IOW: use only if you know
  249. what you are doing). Depending on the base.bbclass a
  250. listtasks tasks is defined and will show available
  251. tasks
  252. -r FILE, --read=FILE read the specified file before bitbake.conf
  253. -v, --verbose output more chit-chat to the terminal
  254. -D, --debug Increase the debug level. You can specify this more
  255. than once.
  256. -n, --dry-run don't execute, just go through the motions
  257. -S, --dump-signatures
  258. don't execute, just dump out the signature
  259. construction information
  260. -p, --parse-only quit after parsing the BB files (developers only)
  261. -d, --disable-psyco disable using the psyco just-in-time compiler (not
  262. recommended)
  263. -s, --show-versions show current and preferred versions of all packages
  264. -e, --environment show the global or per-package environment (this is
  265. what used to be bbread)
  266. -g, --graphviz emit the dependency trees of the specified packages in
  267. the dot syntax
  268. -I EXTRA_ASSUME_PROVIDED, --ignore-deps=EXTRA_ASSUME_PROVIDED
  269. Assume these dependencies don't exist and are already
  270. provided (equivalent to ASSUME_PROVIDED). Useful to
  271. make dependency graphs more appealing
  272. -l DEBUG_DOMAINS, --log-domains=DEBUG_DOMAINS
  273. Show debug logging for the specified logging domains
  274. -P, --profile profile the command and print a report
  275. -u UI, --ui=UI userinterface to use
  276. --revisions-changed Set the exit code depending on whether upstream
  277. floating revisions have changed or not</screen>
  278. </section>
  279. <section id='ref-bitbake-fetchers'>
  280. <title>Fetchers</title>
  281. <para>
  282. As well as the containing the parsing and task/dependency handling
  283. code, bitbake also contains a set of "fetcher" modules which allow
  284. fetching of source code from various types of sources. Example
  285. sources might be from disk with the metadata, from websites, from
  286. remote shell accounts or from SCM systems like cvs/subversion/git.
  287. </para>
  288. <para>
  289. The fetchers are usually triggered by entries in
  290. <glossterm><link linkend='var-SRC_URI'>SRC_URI</link></glossterm>. Information about the
  291. options and formats of entries for specific fetchers can be found in the
  292. <ulink url='http://bitbake.berlios.de/manual/'>BitBake manual</ulink>.
  293. </para>
  294. <para>
  295. One useful feature for certain SCM fetchers is the ability to
  296. "auto-update" when the upstream SCM changes version. Since this
  297. requires certain functionality from the SCM only certain systems
  298. support it, currently Subversion, Bazaar and to a limited extent, Git. It
  299. works using the <glossterm><link linkend='var-SRCREV'>SRCREV</link>
  300. </glossterm> variable. See the <link linkend='platdev-appdev-srcrev'>
  301. developing with an external SCM based project</link> section for more
  302. information.
  303. </para>
  304. </section>
  305. </appendix>
  306. <!--
  307. vim: expandtab tw=80 ts=4 spell spelllang=en_gb
  308. -->