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