technical-details.xml 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957
  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='technical-details'>
  5. <title>Technical Details</title>
  6. <para>
  7. This chapter provides technical details for various parts of the
  8. Yocto Project.
  9. Currently, topics include Yocto Project components,
  10. cross-toolchain generation, shared state (sstate) cache,
  11. x32, Wayland support, and Licenses.
  12. </para>
  13. <section id='usingpoky-components'>
  14. <title>Yocto Project Components</title>
  15. <para>
  16. The
  17. <link linkend='bitbake-term'>BitBake</link>
  18. task executor together with various types of configuration files form
  19. the OpenEmbedded Core.
  20. This section overviews these components by describing their use and
  21. how they interact.
  22. </para>
  23. <para>
  24. BitBake handles the parsing and execution of the data files.
  25. The data itself is of various types:
  26. <itemizedlist>
  27. <listitem><para><emphasis>Recipes:</emphasis> Provides details
  28. about particular pieces of software.
  29. </para></listitem>
  30. <listitem><para><emphasis>Class Data:</emphasis> Abstracts
  31. common build information (e.g. how to build a Linux kernel).
  32. </para></listitem>
  33. <listitem><para><emphasis>Configuration Data:</emphasis> Defines
  34. machine-specific settings, policy decisions, and so forth.
  35. Configuration data acts as the glue to bind everything
  36. together.
  37. </para></listitem>
  38. </itemizedlist>
  39. </para>
  40. <para>
  41. BitBake knows how to combine multiple data sources together and refers
  42. to each data source as a layer.
  43. For information on layers, see the
  44. "<ulink url='&YOCTO_DOCS_DEV_URL;#understanding-and-creating-layers'>Understanding and
  45. Creating Layers</ulink>" section of the Yocto Project Development
  46. Tasks Manual.
  47. </para>
  48. <para>
  49. Following are some brief details on these core components.
  50. For additional information on how these components interact during
  51. a build, see the
  52. "<ulink url='&YOCTO_DOCS_OVERVIEW_URL;#development-concepts'>Development Concepts</ulink>"
  53. section in the Yocto Project Overview Manual.
  54. </para>
  55. <section id='usingpoky-components-bitbake'>
  56. <title>BitBake</title>
  57. <para>
  58. BitBake is the tool at the heart of the OpenEmbedded build system
  59. and is responsible for parsing the
  60. <link linkend='metadata'>Metadata</link>,
  61. generating a list of tasks from it, and then executing those tasks.
  62. </para>
  63. <para>
  64. This section briefly introduces BitBake.
  65. If you want more information on BitBake, see the
  66. <ulink url='&YOCTO_DOCS_BB_URL;#bitbake-user-manual'>BitBake User Manual</ulink>.
  67. </para>
  68. <para>
  69. To see a list of the options BitBake supports, use either of
  70. the following commands:
  71. <literallayout class='monospaced'>
  72. $ bitbake -h
  73. $ bitbake --help
  74. </literallayout>
  75. </para>
  76. <para>
  77. The most common usage for BitBake is <filename>bitbake <replaceable>packagename</replaceable></filename>, where
  78. <filename>packagename</filename> is the name of the package you want to build
  79. (referred to as the "target" in this manual).
  80. The target often equates to the first part of a recipe's filename
  81. (e.g. "foo" for a recipe named
  82. <filename>foo_1.3.0-r0.bb</filename>).
  83. So, to process the <filename>matchbox-desktop_1.2.3.bb</filename> recipe file, you
  84. might type the following:
  85. <literallayout class='monospaced'>
  86. $ bitbake matchbox-desktop
  87. </literallayout>
  88. Several different versions of <filename>matchbox-desktop</filename> might exist.
  89. BitBake chooses the one selected by the distribution configuration.
  90. You can get more details about how BitBake chooses between different
  91. target versions and providers in the
  92. "<ulink url='&YOCTO_DOCS_BB_URL;#bb-bitbake-preferences'>Preferences</ulink>"
  93. section of the BitBake User Manual.
  94. </para>
  95. <para>
  96. BitBake also tries to execute any dependent tasks first.
  97. So for example, before building <filename>matchbox-desktop</filename>, BitBake
  98. would build a cross compiler and <filename>glibc</filename> if they had not already
  99. been built.
  100. </para>
  101. <para>
  102. A useful BitBake option to consider is the <filename>-k</filename> or
  103. <filename>--continue</filename> option.
  104. This option instructs BitBake to try and continue processing the job
  105. as long as possible even after encountering an error.
  106. When an error occurs, the target that
  107. failed and those that depend on it cannot be remade.
  108. However, when you use this option other dependencies can still be
  109. processed.
  110. </para>
  111. </section>
  112. <section id='usingpoky-components-metadata'>
  113. <title>Metadata (Recipes)</title>
  114. <para>
  115. Files that have the <filename>.bb</filename> suffix are "recipes"
  116. files.
  117. In general, a recipe contains information about a single piece of
  118. software.
  119. This information includes the location from which to download the
  120. unaltered source, any source patches to be applied to that source
  121. (if needed), which special configuration options to apply,
  122. how to compile the source files, and how to package the compiled
  123. output.
  124. </para>
  125. <para>
  126. The term "package" is sometimes used to refer to recipes. However,
  127. since the word "package" is used for the packaged output from the OpenEmbedded
  128. build system (i.e. <filename>.ipk</filename> or <filename>.deb</filename> files),
  129. this document avoids using the term "package" when referring to recipes.
  130. </para>
  131. </section>
  132. <section id='metadata-virtual-providers'>
  133. <title>Metadata (Virtual Providers)</title>
  134. <para>
  135. Prior to the build, if you know that several different recipes
  136. provide the same functionality, you can use a virtual provider
  137. (i.e. <filename>virtual/*</filename>) as a placeholder for the
  138. actual provider.
  139. The actual provider would be determined at build
  140. time.
  141. In this case, you should add <filename>virtual/*</filename>
  142. to <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>,
  143. rather than listing the specified provider.
  144. You would select the actual provider by setting the
  145. <link linkend='var-PREFERRED_PROVIDER'><filename>PREFERRED_PROVIDER</filename></link>
  146. variable (i.e. <filename>PREFERRED_PROVIDER_virtual/*</filename>)
  147. in the build's configuration file (e.g.
  148. <filename>poky/build/conf/local.conf</filename>).
  149. <note>
  150. Any recipe that PROVIDES a <filename>virtual/*</filename> item
  151. that is ultimately not selected through
  152. <filename>PREFERRED_PROVIDER</filename> does not get built.
  153. Preventing these recipes from building is usually the desired
  154. behavior since this mechanism's purpose is to select between
  155. mutually exclusive alternative providers.
  156. </note>
  157. </para>
  158. <para>
  159. The following lists specific examples of virtual providers:
  160. <itemizedlist>
  161. <listitem><para>
  162. <filename>virtual/mesa</filename>:
  163. Provides <filename>gbm.pc</filename>.
  164. </para></listitem>
  165. <listitem><para>
  166. <filename>virtual/egl</filename>:
  167. Provides <filename>egl.pc</filename> and possibly
  168. <filename>wayland-egl.pc</filename>.
  169. </para></listitem>
  170. <listitem><para>
  171. <filename>virtual/libgl</filename>:
  172. Provides <filename>gl.pc</filename> (i.e. libGL).
  173. </para></listitem>
  174. <listitem><para>
  175. <filename>virtual/libgles1</filename>:
  176. Provides <filename>glesv1_cm.pc</filename>
  177. (i.e. libGLESv1_CM).
  178. </para></listitem>
  179. <listitem><para>
  180. <filename>virtual/libgles2</filename>:
  181. Provides <filename>glesv2.pc</filename> (i.e. libGLESv2).
  182. </para></listitem>
  183. </itemizedlist>
  184. </para>
  185. </section>
  186. <section id='usingpoky-components-classes'>
  187. <title>Classes</title>
  188. <para>
  189. Class files (<filename>.bbclass</filename>) contain information that
  190. is useful to share between
  191. <link linkend='metadata'>Metadata</link> files.
  192. An example is the
  193. <link linkend='ref-classes-autotools'><filename>autotools</filename></link>
  194. class, which contains common settings for any application that
  195. Autotools uses.
  196. The "<link linkend='ref-classes'>Classes</link>" chapter provides
  197. details about classes and how to use them.
  198. </para>
  199. </section>
  200. <section id='usingpoky-components-configuration'>
  201. <title>Configuration</title>
  202. <para>
  203. The configuration files (<filename>.conf</filename>) define various configuration variables
  204. that govern the OpenEmbedded build process.
  205. These files fall into several areas that define machine configuration options,
  206. distribution configuration options, compiler tuning options, general common configuration
  207. options, and user configuration options in <filename>local.conf</filename>, which is found
  208. in the
  209. <link linkend='build-directory'>Build Directory</link>.
  210. </para>
  211. </section>
  212. </section>
  213. <section id="cross-development-toolchain-generation">
  214. <title>Cross-Development Toolchain Generation</title>
  215. <para>
  216. The Yocto Project does most of the work for you when it comes to
  217. creating
  218. <link linkend='cross-development-toolchain'>cross-development toolchains</link>.
  219. This section provides some technical background on how
  220. cross-development toolchains are created and used.
  221. For more information on toolchains, you can also see the
  222. <ulink url='&YOCTO_DOCS_SDK_URL;'>Yocto Project Application Development and the Extensible Software Development Kit (eSDK)</ulink>
  223. manual.
  224. </para>
  225. <para>
  226. In the Yocto Project development environment, cross-development
  227. toolchains are used to build the image and applications that run on the
  228. target hardware.
  229. With just a few commands, the OpenEmbedded build system creates
  230. these necessary toolchains for you.
  231. </para>
  232. <para>
  233. The following figure shows a high-level build environment regarding
  234. toolchain construction and use.
  235. </para>
  236. <para>
  237. <imagedata fileref="figures/cross-development-toolchains.png" width="8in" depth="6in" align="center" />
  238. </para>
  239. <para>
  240. Most of the work occurs on the Build Host.
  241. This is the machine used to build images and generally work within the
  242. the Yocto Project environment.
  243. When you run BitBake to create an image, the OpenEmbedded build system
  244. uses the host <filename>gcc</filename> compiler to bootstrap a
  245. cross-compiler named <filename>gcc-cross</filename>.
  246. The <filename>gcc-cross</filename> compiler is what BitBake uses to
  247. compile source files when creating the target image.
  248. You can think of <filename>gcc-cross</filename> simply as an
  249. automatically generated cross-compiler that is used internally within
  250. BitBake only.
  251. <note>
  252. The extensible SDK does not use
  253. <filename>gcc-cross-canadian</filename> since this SDK
  254. ships a copy of the OpenEmbedded build system and the sysroot
  255. within it contains <filename>gcc-cross</filename>.
  256. </note>
  257. </para>
  258. <para>
  259. The chain of events that occurs when <filename>gcc-cross</filename> is
  260. bootstrapped is as follows:
  261. <literallayout class='monospaced'>
  262. gcc -> binutils-cross -> gcc-cross-initial -> linux-libc-headers -> glibc-initial -> glibc -> gcc-cross -> gcc-runtime
  263. </literallayout>
  264. <itemizedlist>
  265. <listitem><para><filename>gcc</filename>:
  266. The build host's GNU Compiler Collection (GCC).
  267. </para></listitem>
  268. <listitem><para><filename>binutils-cross</filename>:
  269. The bare minimum binary utilities needed in order to run
  270. the <filename>gcc-cross-initial</filename> phase of the
  271. bootstrap operation.
  272. </para></listitem>
  273. <listitem><para><filename>gcc-cross-initial</filename>:
  274. An early stage of the bootstrap process for creating
  275. the cross-compiler.
  276. This stage builds enough of the <filename>gcc-cross</filename>,
  277. the C library, and other pieces needed to finish building the
  278. final cross-compiler in later stages.
  279. This tool is a "native" package (i.e. it is designed to run on
  280. the build host).
  281. </para></listitem>
  282. <listitem><para><filename>linux-libc-headers</filename>:
  283. Headers needed for the cross-compiler.
  284. </para></listitem>
  285. <listitem><para><filename>glibc-initial</filename>:
  286. An initial version of the Embedded GLIBC needed to bootstrap
  287. <filename>glibc</filename>.
  288. </para></listitem>
  289. <listitem><para><filename>gcc-cross</filename>:
  290. The final stage of the bootstrap process for the
  291. cross-compiler.
  292. This stage results in the actual cross-compiler that
  293. BitBake uses when it builds an image for a targeted
  294. device.
  295. <note>
  296. If you are replacing this cross compiler toolchain
  297. with a custom version, you must replace
  298. <filename>gcc-cross</filename>.
  299. </note>
  300. This tool is also a "native" package (i.e. it is
  301. designed to run on the build host).
  302. </para></listitem>
  303. <listitem><para><filename>gcc-runtime</filename>:
  304. Runtime libraries resulting from the toolchain bootstrapping
  305. process.
  306. This tool produces a binary that consists of the
  307. runtime libraries need for the targeted device.
  308. </para></listitem>
  309. </itemizedlist>
  310. </para>
  311. <para>
  312. You can use the OpenEmbedded build system to build an installer for
  313. the relocatable SDK used to develop applications.
  314. When you run the installer, it installs the toolchain, which contains
  315. the development tools (e.g., the
  316. <filename>gcc-cross-canadian</filename>),
  317. <filename>binutils-cross-canadian</filename>, and other
  318. <filename>nativesdk-*</filename> tools,
  319. which are tools native to the SDK (i.e. native to
  320. <link linkend='var-SDK_ARCH'><filename>SDK_ARCH</filename></link>),
  321. you need to cross-compile and test your software.
  322. The figure shows the commands you use to easily build out this
  323. toolchain.
  324. This cross-development toolchain is built to execute on the
  325. <link linkend='var-SDKMACHINE'><filename>SDKMACHINE</filename></link>,
  326. which might or might not be the same
  327. machine as the Build Host.
  328. <note>
  329. If your target architecture is supported by the Yocto Project,
  330. you can take advantage of pre-built images that ship with the
  331. Yocto Project and already contain cross-development toolchain
  332. installers.
  333. </note>
  334. </para>
  335. <para>
  336. Here is the bootstrap process for the relocatable toolchain:
  337. <literallayout class='monospaced'>
  338. gcc -> binutils-crosssdk -> gcc-crosssdk-initial -> linux-libc-headers ->
  339. glibc-initial -> nativesdk-glibc -> gcc-crosssdk -> gcc-cross-canadian
  340. </literallayout>
  341. <itemizedlist>
  342. <listitem><para><filename>gcc</filename>:
  343. The build host's GNU Compiler Collection (GCC).
  344. </para></listitem>
  345. <listitem><para><filename>binutils-crosssdk</filename>:
  346. The bare minimum binary utilities needed in order to run
  347. the <filename>gcc-crosssdk-initial</filename> phase of the
  348. bootstrap operation.
  349. </para></listitem>
  350. <listitem><para><filename>gcc-crosssdk-initial</filename>:
  351. An early stage of the bootstrap process for creating
  352. the cross-compiler.
  353. This stage builds enough of the
  354. <filename>gcc-crosssdk</filename> and supporting pieces so that
  355. the final stage of the bootstrap process can produce the
  356. finished cross-compiler.
  357. This tool is a "native" binary that runs on the build host.
  358. </para></listitem>
  359. <listitem><para><filename>linux-libc-headers</filename>:
  360. Headers needed for the cross-compiler.
  361. </para></listitem>
  362. <listitem><para><filename>glibc-initial</filename>:
  363. An initial version of the Embedded GLIBC needed to bootstrap
  364. <filename>nativesdk-glibc</filename>.
  365. </para></listitem>
  366. <listitem><para><filename>nativesdk-glibc</filename>:
  367. The Embedded GLIBC needed to bootstrap the
  368. <filename>gcc-crosssdk</filename>.
  369. </para></listitem>
  370. <listitem><para><filename>gcc-crosssdk</filename>:
  371. The final stage of the bootstrap process for the
  372. relocatable cross-compiler.
  373. The <filename>gcc-crosssdk</filename> is a transitory compiler
  374. and never leaves the build host.
  375. Its purpose is to help in the bootstrap process to create the
  376. eventual relocatable <filename>gcc-cross-canadian</filename>
  377. compiler, which is relocatable.
  378. This tool is also a "native" package (i.e. it is
  379. designed to run on the build host).
  380. </para></listitem>
  381. <listitem><para><filename>gcc-cross-canadian</filename>:
  382. The final relocatable cross-compiler.
  383. When run on the
  384. <link linkend='var-SDKMACHINE'><filename>SDKMACHINE</filename></link>,
  385. this tool
  386. produces executable code that runs on the target device.
  387. Only one cross-canadian compiler is produced per architecture
  388. since they can be targeted at different processor optimizations
  389. using configurations passed to the compiler through the
  390. compile commands.
  391. This circumvents the need for multiple compilers and thus
  392. reduces the size of the toolchains.
  393. </para></listitem>
  394. </itemizedlist>
  395. </para>
  396. <note>
  397. For information on advantages gained when building a
  398. cross-development toolchain installer, see the
  399. "<ulink url='&YOCTO_DOCS_SDK_URL;#sdk-building-an-sdk-installer'>Building an SDK Installer</ulink>"
  400. section in the Yocto Project Application Development and the
  401. Extensible Software Development Kit (eSDK) manual.
  402. </note>
  403. </section>
  404. <section id="shared-state-cache">
  405. <title>Shared State Cache</title>
  406. <para>
  407. By design, the OpenEmbedded build system builds everything from scratch unless
  408. BitBake can determine that parts do not need to be rebuilt.
  409. Fundamentally, building from scratch is attractive as it means all parts are
  410. built fresh and there is no possibility of stale data causing problems.
  411. When developers hit problems, they typically default back to building from scratch
  412. so they know the state of things from the start.
  413. </para>
  414. <para>
  415. Building an image from scratch is both an advantage and a disadvantage to the process.
  416. As mentioned in the previous paragraph, building from scratch ensures that
  417. everything is current and starts from a known state.
  418. However, building from scratch also takes much longer as it generally means
  419. rebuilding things that do not necessarily need to be rebuilt.
  420. </para>
  421. <para>
  422. The Yocto Project implements shared state code that supports incremental builds.
  423. The implementation of the shared state code answers the following questions that
  424. were fundamental roadblocks within the OpenEmbedded incremental build support system:
  425. <itemizedlist>
  426. <listitem><para>What pieces of the system have changed and what pieces have
  427. not changed?</para></listitem>
  428. <listitem><para>How are changed pieces of software removed and replaced?</para></listitem>
  429. <listitem><para>How are pre-built components that do not need to be rebuilt from scratch
  430. used when they are available?</para></listitem>
  431. </itemizedlist>
  432. </para>
  433. <para>
  434. For the first question, the build system detects changes in the "inputs" to a given task by
  435. creating a checksum (or signature) of the task's inputs.
  436. If the checksum changes, the system assumes the inputs have changed and the task needs to be
  437. rerun.
  438. For the second question, the shared state (sstate) code tracks which tasks add which output
  439. to the build process.
  440. This means the output from a given task can be removed, upgraded or otherwise manipulated.
  441. The third question is partly addressed by the solution for the second question
  442. assuming the build system can fetch the sstate objects from remote locations and
  443. install them if they are deemed to be valid.
  444. </para>
  445. <note>
  446. The OpenEmbedded build system does not maintain
  447. <link linkend='var-PR'><filename>PR</filename></link> information
  448. as part of the shared state packages.
  449. Consequently, considerations exist that affect maintaining shared
  450. state feeds.
  451. For information on how the OpenEmbedded build system
  452. works with packages and can
  453. track incrementing <filename>PR</filename> information, see the
  454. "<ulink url='&YOCTO_DOCS_DEV_URL;#automatically-incrementing-a-binary-package-revision-number'>Automatically Incrementing a Binary Package Revision Number</ulink>"
  455. section in the Yocto Project Development Tasks Manual.
  456. </note>
  457. <para>
  458. The rest of this section goes into detail about the overall incremental build
  459. architecture, the checksums (signatures), shared state, and some tips and tricks.
  460. </para>
  461. <section id='overall-architecture'>
  462. <title>Overall Architecture</title>
  463. <para>
  464. When determining what parts of the system need to be built, BitBake
  465. works on a per-task basis rather than a per-recipe basis.
  466. You might wonder why using a per-task basis is preferred over a per-recipe basis.
  467. To help explain, consider having the IPK packaging backend enabled and then switching to DEB.
  468. In this case, the
  469. <link linkend='ref-tasks-install'><filename>do_install</filename></link>
  470. and
  471. <link linkend='ref-tasks-package'><filename>do_package</filename></link>
  472. task outputs are still valid.
  473. However, with a per-recipe approach, the build would not include the
  474. <filename>.deb</filename> files.
  475. Consequently, you would have to invalidate the whole build and rerun it.
  476. Rerunning everything is not the best solution.
  477. Also, in this case, the core must be "taught" much about specific tasks.
  478. This methodology does not scale well and does not allow users to easily add new tasks
  479. in layers or as external recipes without touching the packaged-staging core.
  480. </para>
  481. </section>
  482. <section id='checksums'>
  483. <title>Checksums (Signatures)</title>
  484. <para>
  485. The shared state code uses a checksum, which is a unique signature of a task's
  486. inputs, to determine if a task needs to be run again.
  487. Because it is a change in a task's inputs that triggers a rerun, the process
  488. needs to detect all the inputs to a given task.
  489. For shell tasks, this turns out to be fairly easy because
  490. the build process generates a "run" shell script for each task and
  491. it is possible to create a checksum that gives you a good idea of when
  492. the task's data changes.
  493. </para>
  494. <para>
  495. To complicate the problem, there are things that should not be
  496. included in the checksum.
  497. First, there is the actual specific build path of a given task -
  498. the <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>.
  499. It does not matter if the work directory changes because it should
  500. not affect the output for target packages.
  501. Also, the build process has the objective of making native
  502. or cross packages relocatable.
  503. <note>
  504. Both native and cross packages run on the build host.
  505. However, cross packages generate output for the target
  506. architecture.
  507. </note>
  508. The checksum therefore needs to exclude
  509. <filename>WORKDIR</filename>.
  510. The simplistic approach for excluding the work directory is to set
  511. <filename>WORKDIR</filename> to some fixed value and create the
  512. checksum for the "run" script.
  513. </para>
  514. <para>
  515. Another problem results from the "run" scripts containing functions that
  516. might or might not get called.
  517. The incremental build solution contains code that figures out dependencies
  518. between shell functions.
  519. This code is used to prune the "run" scripts down to the minimum set,
  520. thereby alleviating this problem and making the "run" scripts much more
  521. readable as a bonus.
  522. </para>
  523. <para>
  524. So far we have solutions for shell scripts.
  525. What about Python tasks?
  526. The same approach applies even though these tasks are more difficult.
  527. The process needs to figure out what variables a Python function accesses
  528. and what functions it calls.
  529. Again, the incremental build solution contains code that first figures out
  530. the variable and function dependencies, and then creates a checksum for the data
  531. used as the input to the task.
  532. </para>
  533. <para>
  534. Like the <filename>WORKDIR</filename> case, situations exist where dependencies
  535. should be ignored.
  536. For these cases, you can instruct the build process to ignore a dependency
  537. by using a line like the following:
  538. <literallayout class='monospaced'>
  539. PACKAGE_ARCHS[vardepsexclude] = "MACHINE"
  540. </literallayout>
  541. This example ensures that the
  542. <link linkend='var-PACKAGE_ARCHS'><filename>PACKAGE_ARCHS</filename></link>
  543. variable does not
  544. depend on the value of
  545. <link linkend='var-MACHINE'><filename>MACHINE</filename></link>,
  546. even if it does reference it.
  547. </para>
  548. <para>
  549. Equally, there are cases where we need to add dependencies BitBake is not able to find.
  550. You can accomplish this by using a line like the following:
  551. <literallayout class='monospaced'>
  552. PACKAGE_ARCHS[vardeps] = "MACHINE"
  553. </literallayout>
  554. This example explicitly adds the <filename>MACHINE</filename> variable as a
  555. dependency for <filename>PACKAGE_ARCHS</filename>.
  556. </para>
  557. <para>
  558. Consider a case with in-line Python, for example, where BitBake is not
  559. able to figure out dependencies.
  560. When running in debug mode (i.e. using <filename>-DDD</filename>), BitBake
  561. produces output when it discovers something for which it cannot figure out
  562. dependencies.
  563. The Yocto Project team has currently not managed to cover those dependencies
  564. in detail and is aware of the need to fix this situation.
  565. </para>
  566. <para>
  567. Thus far, this section has limited discussion to the direct inputs into a task.
  568. Information based on direct inputs is referred to as the "basehash" in the
  569. code.
  570. However, there is still the question of a task's indirect inputs - the
  571. things that were already built and present in the
  572. <link linkend='build-directory'>Build Directory</link>.
  573. The checksum (or signature) for a particular task needs to add the hashes
  574. of all the tasks on which the particular task depends.
  575. Choosing which dependencies to add is a policy decision.
  576. However, the effect is to generate a master checksum that combines the basehash
  577. and the hashes of the task's dependencies.
  578. </para>
  579. <para>
  580. At the code level, there are a variety of ways both the basehash and the
  581. dependent task hashes can be influenced.
  582. Within the BitBake configuration file, we can give BitBake some extra information
  583. to help it construct the basehash.
  584. The following statement effectively results in a list of global variable
  585. dependency excludes - variables never included in any checksum:
  586. <literallayout class='monospaced'>
  587. BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH DL_DIR \
  588. SSTATE_DIR THISDIR FILESEXTRAPATHS FILE_DIRNAME HOME LOGNAME SHELL TERM \
  589. USER FILESPATH STAGING_DIR_HOST STAGING_DIR_TARGET COREBASE PRSERV_HOST \
  590. PRSERV_DUMPDIR PRSERV_DUMPFILE PRSERV_LOCKDOWN PARALLEL_MAKE \
  591. CCACHE_DIR EXTERNAL_TOOLCHAIN CCACHE CCACHE_DISABLE LICENSE_PATH SDKPKGSUFFIX"
  592. </literallayout>
  593. The previous example excludes
  594. <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>
  595. since that variable is actually constructed as a path within
  596. <link linkend='var-TMPDIR'><filename>TMPDIR</filename></link>, which is on
  597. the whitelist.
  598. </para>
  599. <para>
  600. The rules for deciding which hashes of dependent tasks to include through
  601. dependency chains are more complex and are generally accomplished with a
  602. Python function.
  603. The code in <filename>meta/lib/oe/sstatesig.py</filename> shows two examples
  604. of this and also illustrates how you can insert your own policy into the system
  605. if so desired.
  606. This file defines the two basic signature generators
  607. <link linkend='oe-core'>OE-Core</link> uses: "OEBasic" and
  608. "OEBasicHash".
  609. By default, there is a dummy "noop" signature handler enabled in BitBake.
  610. This means that behavior is unchanged from previous versions.
  611. OE-Core uses the "OEBasicHash" signature handler by default
  612. through this setting in the <filename>bitbake.conf</filename> file:
  613. <literallayout class='monospaced'>
  614. BB_SIGNATURE_HANDLER ?= "OEBasicHash"
  615. </literallayout>
  616. The "OEBasicHash" <filename>BB_SIGNATURE_HANDLER</filename> is the same as the
  617. "OEBasic" version but adds the task hash to the stamp files.
  618. This results in any
  619. <link linkend='metadata'>Metadata</link>
  620. change that changes the task hash, automatically
  621. causing the task to be run again.
  622. This removes the need to bump <link linkend='var-PR'><filename>PR</filename></link>
  623. values, and changes to Metadata automatically ripple across the build.
  624. </para>
  625. <para>
  626. It is also worth noting that the end result of these signature generators is to
  627. make some dependency and hash information available to the build.
  628. This information includes:
  629. <itemizedlist>
  630. <listitem><para><filename>BB_BASEHASH_task-</filename><replaceable>taskname</replaceable>:
  631. The base hashes for each task in the recipe.
  632. </para></listitem>
  633. <listitem><para><filename>BB_BASEHASH_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
  634. The base hashes for each dependent task.
  635. </para></listitem>
  636. <listitem><para><filename>BBHASHDEPS_</filename><replaceable>filename</replaceable><filename>:</filename><replaceable>taskname</replaceable>:
  637. The task dependencies for each task.
  638. </para></listitem>
  639. <listitem><para><filename>BB_TASKHASH</filename>:
  640. The hash of the currently running task.
  641. </para></listitem>
  642. </itemizedlist>
  643. </para>
  644. </section>
  645. <section id='shared-state'>
  646. <title>Shared State</title>
  647. <para>
  648. Checksums and dependencies, as discussed in the previous section, solve half the
  649. problem of supporting a shared state.
  650. The other part of the problem is being able to use checksum information during the build
  651. and being able to reuse or rebuild specific components.
  652. </para>
  653. <para>
  654. The
  655. <link linkend='ref-classes-sstate'><filename>sstate</filename></link>
  656. class is a relatively generic implementation of how to "capture"
  657. a snapshot of a given task.
  658. The idea is that the build process does not care about the source of a task's output.
  659. Output could be freshly built or it could be downloaded and unpacked from
  660. somewhere - the build process does not need to worry about its origin.
  661. </para>
  662. <para>
  663. There are two types of output, one is just about creating a directory
  664. in <link linkend='var-WORKDIR'><filename>WORKDIR</filename></link>.
  665. A good example is the output of either
  666. <link linkend='ref-tasks-install'><filename>do_install</filename></link>
  667. or
  668. <link linkend='ref-tasks-package'><filename>do_package</filename></link>.
  669. The other type of output occurs when a set of data is merged into a shared directory
  670. tree such as the sysroot.
  671. </para>
  672. <para>
  673. The Yocto Project team has tried to keep the details of the
  674. implementation hidden in <filename>sstate</filename> class.
  675. From a user's perspective, adding shared state wrapping to a task
  676. is as simple as this
  677. <link linkend='ref-tasks-deploy'><filename>do_deploy</filename></link>
  678. example taken from the
  679. <link linkend='ref-classes-deploy'><filename>deploy</filename></link>
  680. class:
  681. <literallayout class='monospaced'>
  682. DEPLOYDIR = "${WORKDIR}/deploy-${PN}"
  683. SSTATETASKS += "do_deploy"
  684. do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"
  685. do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"
  686. python do_deploy_setscene () {
  687. sstate_setscene(d)
  688. }
  689. addtask do_deploy_setscene
  690. do_deploy[dirs] = "${DEPLOYDIR} ${B}"
  691. </literallayout>
  692. The following list explains the previous example:
  693. <itemizedlist>
  694. <listitem><para>
  695. Adding "do_deploy" to <filename>SSTATETASKS</filename>
  696. adds some required sstate-related processing, which is
  697. implemented in the
  698. <link linkend='ref-classes-sstate'><filename>sstate</filename></link>
  699. class, to before and after the
  700. <link linkend='ref-tasks-deploy'><filename>do_deploy</filename></link>
  701. task.
  702. </para></listitem>
  703. <listitem><para>
  704. The
  705. <filename>do_deploy[sstate-inputdirs] = "${DEPLOYDIR}"</filename>
  706. declares that <filename>do_deploy</filename> places its
  707. output in <filename>${DEPLOYDIR}</filename> when run
  708. normally (i.e. when not using the sstate cache).
  709. This output becomes the input to the shared state cache.
  710. </para></listitem>
  711. <listitem><para>
  712. The
  713. <filename>do_deploy[sstate-outputdirs] = "${DEPLOY_DIR_IMAGE}"</filename>
  714. line causes the contents of the shared state cache to be
  715. copied to <filename>${DEPLOY_DIR_IMAGE}</filename>.
  716. <note>
  717. If <filename>do_deploy</filename> is not already in
  718. the shared state cache or if its input checksum
  719. (signature) has changed from when the output was
  720. cached, the task will be run to populate the shared
  721. state cache, after which the contents of the shared
  722. state cache is copied to
  723. <filename>${DEPLOY_DIR_IMAGE}</filename>.
  724. If <filename>do_deploy</filename> is in the shared
  725. state cache and its signature indicates that the
  726. cached output is still valid (i.e. if no
  727. relevant task inputs have changed), then the contents
  728. of the shared state cache will be copied directly to
  729. <filename>${DEPLOY_DIR_IMAGE}</filename> by the
  730. <filename>do_deploy_setscene</filename> task instead,
  731. skipping the <filename>do_deploy</filename> task.
  732. </note>
  733. </para></listitem>
  734. <listitem><para>
  735. The following task definition is glue logic needed to make
  736. the previous settings effective:
  737. <literallayout class='monospaced'>
  738. python do_deploy_setscene () {
  739. sstate_setscene(d)
  740. }
  741. addtask do_deploy_setscene
  742. </literallayout>
  743. <filename>sstate_setscene()</filename> takes the flags
  744. above as input and accelerates the
  745. <filename>do_deploy</filename> task through the
  746. shared state cache if possible.
  747. If the task was accelerated,
  748. <filename>sstate_setscene()</filename> returns True.
  749. Otherwise, it returns False, and the normal
  750. <filename>do_deploy</filename> task runs.
  751. For more information, see the
  752. "<ulink url='&YOCTO_DOCS_BB_URL;#setscene'>setscene</ulink>"
  753. section in the BitBake User Manual.
  754. </para></listitem>
  755. <listitem><para>
  756. The <filename>do_deploy[dirs] = "${DEPLOYDIR} ${B}"</filename>
  757. line creates <filename>${DEPLOYDIR}</filename> and
  758. <filename>${B}</filename> before the
  759. <filename>do_deploy</filename> task runs, and also sets
  760. the current working directory of
  761. <filename>do_deploy</filename> to
  762. <filename>${B}</filename>.
  763. For more information, see the
  764. "<ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'>Variable Flags</ulink>"
  765. section in the BitBake User Manual.
  766. <note>
  767. In cases where
  768. <filename>sstate-inputdirs</filename> and
  769. <filename>sstate-outputdirs</filename> would be the
  770. same, you can use
  771. <filename>sstate-plaindirs</filename>.
  772. For example, to preserve the
  773. <filename>${PKGD}</filename> and
  774. <filename>${PKGDEST}</filename> output from the
  775. <link linkend='ref-tasks-package'><filename>do_package</filename></link>
  776. task, use the following:
  777. <literallayout class='monospaced'>
  778. do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
  779. </literallayout>
  780. </note>
  781. </para></listitem>
  782. <listitem><para>
  783. <filename>sstate-inputdirs</filename> and
  784. <filename>sstate-outputdirs</filename> can also be used
  785. with multiple directories.
  786. For example, the following declares
  787. <filename>PKGDESTWORK</filename> and
  788. <filename>SHLIBWORK</filename> as shared state
  789. input directories, which populates the shared state
  790. cache, and <filename>PKGDATA_DIR</filename> and
  791. <filename>SHLIBSDIR</filename> as the corresponding
  792. shared state output directories:
  793. <literallayout class='monospaced'>
  794. do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
  795. do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
  796. </literallayout>
  797. </para></listitem>
  798. <listitem><para>
  799. These methods also include the ability to take a lockfile
  800. when manipulating shared state directory structures,
  801. for cases where file additions or removals are sensitive:
  802. <literallayout class='monospaced'>
  803. do_package[sstate-lockfile] = "${PACKAGELOCK}"
  804. </literallayout>
  805. </para></listitem>
  806. </itemizedlist>
  807. </para>
  808. <!--
  809. <para>
  810. In this example, we add some extra flags to the task, a name field ("deploy"), an
  811. input directory where the task sends data, and the output
  812. directory where the data from the task should eventually be copied.
  813. We also add a <filename>_setscene</filename> variant of the task and add the task
  814. name to the <filename>SSTATETASKS</filename> list.
  815. </para>
  816. <para>
  817. If you have a directory whose contents you need to preserve, you can do this with
  818. a line like the following:
  819. <literallayout class='monospaced'>
  820. do_package[sstate-plaindirs] = "${PKGD} ${PKGDEST}"
  821. </literallayout>
  822. This method, as well as the following example, also works for multiple directories.
  823. <literallayout class='monospaced'>
  824. do_package[sstate-inputdirs] = "${PKGDESTWORK} ${SHLIBSWORKDIR}"
  825. do_package[sstate-outputdirs] = "${PKGDATA_DIR} ${SHLIBSDIR}"
  826. do_package[sstate-lockfile] = "${PACKAGELOCK}"
  827. </literallayout>
  828. These methods also include the ability to take a lockfile when manipulating
  829. shared state directory structures since some cases are sensitive to file
  830. additions or removals.
  831. </para>
  832. -->
  833. <para>
  834. Behind the scenes, the shared state code works by looking in
  835. <link linkend='var-SSTATE_DIR'><filename>SSTATE_DIR</filename></link> and
  836. <link linkend='var-SSTATE_MIRRORS'><filename>SSTATE_MIRRORS</filename></link>
  837. for shared state files.
  838. Here is an example:
  839. <literallayout class='monospaced'>
  840. SSTATE_MIRRORS ?= "\
  841. file://.* http://someserver.tld/share/sstate/PATH;downloadfilename=PATH \n \
  842. file://.* file:///some/local/dir/sstate/PATH"
  843. </literallayout>
  844. <note>
  845. The shared state directory (<filename>SSTATE_DIR</filename>) is
  846. organized into two-character subdirectories, where the subdirectory
  847. names are based on the first two characters of the hash.
  848. If the shared state directory structure for a mirror has the
  849. same structure as <filename>SSTATE_DIR</filename>, you must
  850. specify "PATH" as part of the URI to enable the build system
  851. to map to the appropriate subdirectory.
  852. </note>
  853. </para>
  854. <para>
  855. The shared state package validity can be detected just by looking at the
  856. filename since the filename contains the task checksum (or signature) as
  857. described earlier in this section.
  858. If a valid shared state package is found, the build process downloads it
  859. and uses it to accelerate the task.
  860. </para>
  861. <para>
  862. The build processes use the <filename>*_setscene</filename> tasks
  863. for the task acceleration phase.
  864. BitBake goes through this phase before the main execution code and tries
  865. to accelerate any tasks for which it can find shared state packages.
  866. If a shared state package for a task is available, the shared state
  867. package is used.
  868. This means the task and any tasks on which it is dependent are not
  869. executed.
  870. </para>
  871. <para>
  872. As a real world example, the aim is when building an IPK-based image,
  873. only the
  874. <link linkend='ref-tasks-package_write_ipk'><filename>do_package_write_ipk</filename></link>
  875. tasks would have their
  876. shared state packages fetched and extracted.
  877. Since the sysroot is not used, it would never get extracted.
  878. This is another reason why a task-based approach is preferred over a
  879. recipe-based approach, which would have to install the output from every task.
  880. </para>
  881. </section>
  882. <section id='tips-and-tricks'>
  883. <title>Tips and Tricks</title>
  884. <para>
  885. The code in the build system that supports incremental builds is not
  886. simple code.
  887. This section presents some tips and tricks that help you work around
  888. issues related to shared state code.
  889. </para>
  890. <section id='debugging'>
  891. <title>Debugging</title>
  892. <para>
  893. Seeing what metadata went into creating the input signature
  894. of a shared state (sstate) task can be a useful debugging aid.
  895. This information is available in signature information
  896. (<filename>siginfo</filename>) files in
  897. <link linkend='var-SSTATE_DIR'><filename>SSTATE_DIR</filename></link>.
  898. For information on how to view and interpret information in
  899. <filename>siginfo</filename> files, see the
  900. "<link linkend='usingpoky-viewing-task-variable-dependencies'>Viewing Task Variable Dependencies</link>"
  901. section.
  902. </para>
  903. </section>
  904. <section id='invalidating-shared-state'>
  905. <title>Invalidating Shared State</title>
  906. <para>
  907. The OpenEmbedded build system uses checksums and shared state
  908. cache to avoid unnecessarily rebuilding tasks.
  909. Collectively, this scheme is known as "shared state code."
  910. </para>
  911. <para>
  912. As with all schemes, this one has some drawbacks.
  913. It is possible that you could make implicit changes to your
  914. code that the checksum calculations do not take into
  915. account.
  916. These implicit changes affect a task's output but do not trigger
  917. the shared state code into rebuilding a recipe.
  918. Consider an example during which a tool changes its output.
  919. Assume that the output of <filename>rpmdeps</filename> changes.
  920. The result of the change should be that all the
  921. <filename>package</filename> and
  922. <filename>package_write_rpm</filename> shared state cache
  923. items become invalid.
  924. However, because the change to the output is
  925. external to the code and therefore implicit,
  926. the associated shared state cache items do not become
  927. invalidated.
  928. In this case, the build process uses the cached items rather
  929. than running the task again.
  930. Obviously, these types of implicit changes can cause problems.
  931. </para>
  932. <para>
  933. To avoid these problems during the build, you need to
  934. understand the effects of any changes you make.
  935. Realize that changes you make directly to a function
  936. are automatically factored into the checksum calculation.
  937. Thus, these explicit changes invalidate the associated area of
  938. shared state cache.
  939. However, you need to be aware of any implicit changes that
  940. are not obvious changes to the code and could affect the output
  941. of a given task.
  942. </para>
  943. <para>
  944. When you identify an implicit change, you can easily take steps
  945. to invalidate the cache and force the tasks to run.
  946. The steps you can take are as simple as changing a function's
  947. comments in the source code.
  948. For example, to invalidate package shared state files, change
  949. the comment statements of
  950. <link linkend='ref-tasks-package'><filename>do_package</filename></link>
  951. or the comments of one of the functions it calls.
  952. Even though the change is purely cosmetic, it causes the
  953. checksum to be recalculated and forces the OpenEmbedded build
  954. system to run the task again.
  955. </para>
  956. <note>
  957. For an example of a commit that makes a cosmetic change to
  958. invalidate shared state, see this
  959. <ulink url='&YOCTO_GIT_URL;/cgit.cgi/poky/commit/meta/classes/package.bbclass?id=737f8bbb4f27b4837047cb9b4fbfe01dfde36d54'>commit</ulink>.
  960. </note>
  961. </section>
  962. </section>
  963. </section>
  964. <section id='automatically-added-runtime-dependencies'>
  965. <title>Automatically Added Runtime Dependencies</title>
  966. <para>
  967. The OpenEmbedded build system automatically adds common types of
  968. runtime dependencies between packages, which means that you do not
  969. need to explicitly declare the packages using
  970. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>.
  971. Three automatic mechanisms exist (<filename>shlibdeps</filename>,
  972. <filename>pcdeps</filename>, and <filename>depchains</filename>) that
  973. handle shared libraries, package configuration (pkg-config) modules,
  974. and <filename>-dev</filename> and <filename>-dbg</filename> packages,
  975. respectively.
  976. For other types of runtime dependencies, you must manually declare
  977. the dependencies.
  978. <itemizedlist>
  979. <listitem><para>
  980. <filename>shlibdeps</filename>:
  981. During the
  982. <link linkend='ref-tasks-package'><filename>do_package</filename></link>
  983. task of each recipe, all shared libraries installed by the
  984. recipe are located.
  985. For each shared library, the package that contains the shared
  986. library is registered as providing the shared library.
  987. More specifically, the package is registered as providing the
  988. <ulink url='https://en.wikipedia.org/wiki/Soname'>soname</ulink>
  989. of the library.
  990. The resulting shared-library-to-package mapping
  991. is saved globally in
  992. <link linkend='var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></link>
  993. by the
  994. <link linkend='ref-tasks-packagedata'><filename>do_packagedata</filename></link>
  995. task.</para>
  996. <para>Simultaneously, all executables and shared libraries
  997. installed by the recipe are inspected to see what shared
  998. libraries they link against.
  999. For each shared library dependency that is found,
  1000. <filename>PKGDATA_DIR</filename> is queried to
  1001. see if some package (likely from a different recipe) contains
  1002. the shared library.
  1003. If such a package is found, a runtime dependency is added from
  1004. the package that depends on the shared library to the package
  1005. that contains the library.</para>
  1006. <para>The automatically added runtime dependency also includes
  1007. a version restriction.
  1008. This version restriction specifies that at least the current
  1009. version of the package that provides the shared library must be
  1010. used, as if
  1011. "<replaceable>package</replaceable> (>= <replaceable>version</replaceable>)"
  1012. had been added to
  1013. <link linkend='var-RDEPENDS'><filename>RDEPENDS</filename></link>.
  1014. This forces an upgrade of the package containing the shared
  1015. library when installing the package that depends on the
  1016. library, if needed.</para>
  1017. <para>If you want to avoid a package being registered as
  1018. providing a particular shared library (e.g. because the library
  1019. is for internal use only), then add the library to
  1020. <link linkend='var-PRIVATE_LIBS'><filename>PRIVATE_LIBS</filename></link>
  1021. inside the package's recipe.
  1022. </para></listitem>
  1023. <listitem><para>
  1024. <filename>pcdeps</filename>:
  1025. During the
  1026. <link linkend='ref-tasks-package'><filename>do_package</filename></link>
  1027. task of each recipe, all pkg-config modules
  1028. (<filename>*.pc</filename> files) installed by the recipe are
  1029. located.
  1030. For each module, the package that contains the module is
  1031. registered as providing the module.
  1032. The resulting module-to-package mapping is saved globally in
  1033. <link linkend='var-PKGDATA_DIR'><filename>PKGDATA_DIR</filename></link>
  1034. by the
  1035. <link linkend='ref-tasks-packagedata'><filename>do_packagedata</filename></link>
  1036. task.</para>
  1037. <para>Simultaneously, all pkg-config modules installed by the
  1038. recipe are inspected to see what other pkg-config modules they
  1039. depend on.
  1040. A module is seen as depending on another module if it contains
  1041. a "Requires:" line that specifies the other module.
  1042. For each module dependency,
  1043. <filename>PKGDATA_DIR</filename> is queried to see if some
  1044. package contains the module.
  1045. If such a package is found, a runtime dependency is added from
  1046. the package that depends on the module to the package that
  1047. contains the module.
  1048. <note>
  1049. The <filename>pcdeps</filename> mechanism most often infers
  1050. dependencies between <filename>-dev</filename> packages.
  1051. </note>
  1052. </para></listitem>
  1053. <listitem><para>
  1054. <filename>depchains</filename>:
  1055. If a package <filename>foo</filename> depends on a package
  1056. <filename>bar</filename>, then <filename>foo-dev</filename>
  1057. and <filename>foo-dbg</filename> are also made to depend on
  1058. <filename>bar-dev</filename> and <filename>bar-dbg</filename>,
  1059. respectively.
  1060. Taking the <filename>-dev</filename> packages as an example,
  1061. the <filename>bar-dev</filename> package might provide
  1062. headers and shared library symlinks needed by
  1063. <filename>foo-dev</filename>, which shows the need
  1064. for a dependency between the packages.</para>
  1065. <para>The dependencies added by <filename>depchains</filename>
  1066. are in the form of
  1067. <link linkend='var-RRECOMMENDS'><filename>RRECOMMENDS</filename></link>.
  1068. <note>
  1069. By default, <filename>foo-dev</filename> also has an
  1070. <filename>RDEPENDS</filename>-style dependency on
  1071. <filename>foo</filename>, because the default value of
  1072. <filename>RDEPENDS_${PN}-dev</filename> (set in
  1073. <filename>bitbake.conf</filename>) includes
  1074. "${PN}".
  1075. </note></para>
  1076. <para>To ensure that the dependency chain is never broken,
  1077. <filename>-dev</filename> and <filename>-dbg</filename>
  1078. packages are always generated by default, even if the packages
  1079. turn out to be empty.
  1080. See the
  1081. <link linkend='var-ALLOW_EMPTY'><filename>ALLOW_EMPTY</filename></link>
  1082. variable for more information.
  1083. </para></listitem>
  1084. </itemizedlist>
  1085. </para>
  1086. <para>
  1087. The <filename>do_package</filename> task depends on the
  1088. <link linkend='ref-tasks-packagedata'><filename>do_packagedata</filename></link>
  1089. task of each recipe in
  1090. <link linkend='var-DEPENDS'><filename>DEPENDS</filename></link>
  1091. through use of a
  1092. <filename>[</filename><ulink url='&YOCTO_DOCS_BB_URL;#variable-flags'><filename>deptask</filename></ulink><filename>]</filename>
  1093. declaration, which guarantees that the required
  1094. shared-library/module-to-package mapping information will be available
  1095. when needed as long as <filename>DEPENDS</filename> has been
  1096. correctly set.
  1097. </para>
  1098. </section>
  1099. <section id='fakeroot-and-pseudo'>
  1100. <title>Fakeroot and Pseudo</title>
  1101. <para>
  1102. Some tasks are easier to implement when allowed to perform certain
  1103. operations that are normally reserved for the root user.
  1104. For example, the
  1105. <link linkend='ref-tasks-install'><filename>do_install</filename></link>
  1106. task benefits from being able to set the UID and GID of installed files
  1107. to arbitrary values.
  1108. </para>
  1109. <para>
  1110. One approach to allowing tasks to perform root-only operations
  1111. would be to require BitBake to run as root.
  1112. However, this method is cumbersome and has security issues.
  1113. The approach that is actually used is to run tasks that benefit from
  1114. root privileges in a "fake" root environment.
  1115. Within this environment, the task and its child processes believe that
  1116. they are running as the root user, and see an internally consistent
  1117. view of the filesystem.
  1118. As long as generating the final output (e.g. a package or an image)
  1119. does not require root privileges, the fact that some earlier steps ran
  1120. in a fake root environment does not cause problems.
  1121. </para>
  1122. <para>
  1123. The capability to run tasks in a fake root environment is known as
  1124. "fakeroot", which is derived from the BitBake keyword/variable
  1125. flag that requests a fake root environment for a task.
  1126. In current versions of the OpenEmbedded build system,
  1127. the program that implements fakeroot is known as Pseudo.
  1128. </para>
  1129. <para>
  1130. Pseudo overrides system calls through the
  1131. <filename>LD_PRELOAD</filename> mechanism to give the
  1132. illusion of running as root.
  1133. To keep track of "fake" file ownership and permissions resulting from
  1134. operations that require root permissions, an sqlite3
  1135. database is used.
  1136. This database is stored in
  1137. <filename>${</filename><link linkend='var-WORKDIR'><filename>WORKDIR</filename></link><filename>}/pseudo/files.db</filename>
  1138. for individual recipes.
  1139. Storing the database in a file as opposed to in memory
  1140. gives persistence between tasks, and even between builds.
  1141. <note><title>Caution</title>
  1142. If you add your own task that manipulates the same files or
  1143. directories as a fakeroot task, then that task should also run
  1144. under fakeroot.
  1145. Otherwise, the task will not be able to run root-only operations,
  1146. and will not see the fake file ownership and permissions set by the
  1147. other task.
  1148. You should also add a dependency on
  1149. <filename>virtual/fakeroot-native:do_populate_sysroot</filename>,
  1150. giving the following:
  1151. <literallayout class='monospaced'>
  1152. fakeroot do_mytask () {
  1153. ...
  1154. }
  1155. do_mytask[depends] += "virtual/fakeroot-native:do_populate_sysroot"
  1156. </literallayout>
  1157. </note>
  1158. For more information, see the
  1159. <ulink url='&YOCTO_DOCS_BB_URL;#var-FAKEROOT'><filename>FAKEROOT*</filename></ulink>
  1160. variables in the BitBake User Manual.
  1161. You can also reference this
  1162. <ulink url='http://www.ibm.com/developerworks/opensource/library/os-aapseudo1/index.html'>Pseudo</ulink>
  1163. article.
  1164. </para>
  1165. </section>
  1166. <section id='wic-plug-ins-interface'>
  1167. <title>Wic Plug-Ins Interface</title>
  1168. <para>
  1169. You can extend and specialize Wic functionality by using
  1170. Wic plug-ins.
  1171. This section explains the Wic plug-in interface.
  1172. For information on using Wic in general, see the
  1173. "<ulink url='&YOCTO_DOCS_DEV_URL;#creating-partitioned-images-using-wic'>Creating Partitioned Images Using Wic</ulink>"
  1174. section in the Yocto Project Development Tasks Manual.
  1175. <note>
  1176. Wic plug-ins consist of "source" and "imager" plug-ins.
  1177. Imager plug-ins are beyond the scope of this section.
  1178. </note>
  1179. </para>
  1180. <para>
  1181. Source plug-ins provide a mechanism to customize partition
  1182. content during the Wic image generation process.
  1183. You can use source plug-ins to map values that you specify
  1184. using <filename>--source</filename> commands in kickstart
  1185. files (i.e. <filename>*.wks</filename>) to a plug-in
  1186. implementation used to populate a given partition.
  1187. <note>
  1188. If you use plug-ins that have build-time dependencies
  1189. (e.g. native tools, bootloaders, and so forth)
  1190. when building a Wic image, you need to specify those
  1191. dependencies using the
  1192. <link linkend='var-WKS_FILE_DEPENDS'><filename>WKS_FILE_DEPENDS</filename></link>
  1193. variable.
  1194. </note>
  1195. </para>
  1196. <para>
  1197. Source plug-ins are subclasses defined in plug-in files.
  1198. As shipped, the Yocto Project provides several plug-in
  1199. files.
  1200. You can see the source plug-in files that ship with the
  1201. Yocto Project
  1202. <ulink url='&YOCTO_GIT_URL;/cgit/cgit.cgi/poky/tree/scripts/lib/wic/plugins/source'>here</ulink>.
  1203. Each of these plug-in files contain source plug-ins that
  1204. are designed to populate a specific Wic image partition.
  1205. </para>
  1206. <para>
  1207. Source plug-ins are subclasses of the
  1208. <filename>SourcePlugin</filename> class, which is
  1209. defined in the
  1210. <filename>poky/scripts/lib/wic/pluginbase.py</filename>
  1211. file.
  1212. For example, the <filename>BootimgEFIPlugin</filename>
  1213. source plug-in found in the
  1214. <filename>bootimg-efi.py</filename> file is a subclass of
  1215. the <filename>SourcePlugin</filename> class, which is found
  1216. in the <filename>pluginbase.py</filename> file.
  1217. </para>
  1218. <para>
  1219. You can also implement source plug-ins in a layer outside
  1220. of the Source Repositories (external layer).
  1221. To do so, be sure that your plug-in files are located in
  1222. a directory whose path is
  1223. <filename>scripts/lib/wic/plugins/source/</filename>
  1224. within your external layer.
  1225. When the plug-in files are located there, the source
  1226. plug-ins they contain are made available to Wic.
  1227. </para>
  1228. <para>
  1229. When the Wic implementation needs to invoke a
  1230. partition-specific implementation, it looks for the plug-in
  1231. with the same name as the <filename>--source</filename>
  1232. parameter used in the kickstart file given to that
  1233. partition.
  1234. For example, if the partition is set up using the following
  1235. command in a kickstart file:
  1236. <literallayout class='monospaced'>
  1237. part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
  1238. </literallayout>
  1239. The methods defined as class members of the matching
  1240. source plug-in (i.e. <filename>bootimg-pcbios</filename>)
  1241. in the <filename>bootimg-pcbios.py</filename> plug-in file
  1242. are used.
  1243. </para>
  1244. <para>
  1245. To be more concrete, here is the corresponding plug-in
  1246. definition from the <filename>bootimg-pcbios.py</filename>
  1247. file for the previous command along with an example
  1248. method called by the Wic implementation when it needs to
  1249. prepare a partition using an implementation-specific
  1250. function:
  1251. <literallayout class='monospaced'>
  1252. bootimg-pcbios.py
  1253. .
  1254. .
  1255. .
  1256. class BootimgPcbiosPlugin(SourcePlugin):
  1257. """
  1258. Create MBR boot partition and install syslinux on it.
  1259. """
  1260. name = 'bootimg-pcbios'
  1261. .
  1262. .
  1263. .
  1264. @classmethod
  1265. def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
  1266. oe_builddir, bootimg_dir, kernel_dir,
  1267. rootfs_dir, native_sysroot):
  1268. """
  1269. Called to do the actual content population for a partition i.e. it
  1270. 'prepares' the partition to be incorporated into the image.
  1271. In this case, prepare content for legacy bios boot partition.
  1272. """
  1273. .
  1274. .
  1275. .
  1276. </literallayout>
  1277. If a subclass (plug-in) itself does not implement a
  1278. particular function, Wic locates and uses the default
  1279. version in the superclass.
  1280. It is for this reason that all source plug-ins are derived
  1281. from the <filename>SourcePlugin</filename> class.
  1282. </para>
  1283. <para>
  1284. The <filename>SourcePlugin</filename> class defined in
  1285. the <filename>pluginbase.py</filename> file defines
  1286. a set of methods that source plug-ins can implement or
  1287. override.
  1288. Any plug-ins (subclass of
  1289. <filename>SourcePlugin</filename>) that do not implement
  1290. a particular method inherit the implementation of the
  1291. method from the <filename>SourcePlugin</filename> class.
  1292. For more information, see the
  1293. <filename>SourcePlugin</filename> class in the
  1294. <filename>pluginbase.py</filename> file for details:
  1295. </para>
  1296. <para>
  1297. The following list describes the methods implemented in the
  1298. <filename>SourcePlugin</filename> class:
  1299. <itemizedlist>
  1300. <listitem><para>
  1301. <emphasis><filename>do_prepare_partition()</filename>:</emphasis>
  1302. Called to populate a partition with actual content.
  1303. In other words, the method prepares the final
  1304. partition image that is incorporated into the
  1305. disk image.
  1306. </para></listitem>
  1307. <listitem><para>
  1308. <emphasis><filename>do_configure_partition()</filename>:</emphasis>
  1309. Called before
  1310. <filename>do_prepare_partition()</filename> to
  1311. create custom configuration files for a partition
  1312. (e.g. syslinux or grub configuration files).
  1313. </para></listitem>
  1314. <listitem><para>
  1315. <emphasis><filename>do_install_disk()</filename>:</emphasis>
  1316. Called after all partitions have been prepared and
  1317. assembled into a disk image.
  1318. This method provides a hook to allow finalization
  1319. of a disk image (e.g. writing an MBR).
  1320. </para></listitem>
  1321. <listitem><para>
  1322. <emphasis><filename>do_stage_partition()</filename>:</emphasis>
  1323. Special content-staging hook called before
  1324. <filename>do_prepare_partition()</filename>.
  1325. This method is normally empty.</para>
  1326. <para>Typically, a partition just uses the passed-in
  1327. parameters (e.g. the unmodified value of
  1328. <filename>bootimg_dir</filename>).
  1329. However, in some cases, things might need to be
  1330. more tailored.
  1331. As an example, certain files might additionally
  1332. need to be taken from
  1333. <filename>bootimg_dir + /boot</filename>.
  1334. This hook allows those files to be staged in a
  1335. customized fashion.
  1336. <note>
  1337. <filename>get_bitbake_var()</filename>
  1338. allows you to access non-standard variables
  1339. that you might want to use for this
  1340. behavior.
  1341. </note>
  1342. </para></listitem>
  1343. </itemizedlist>
  1344. </para>
  1345. <para>
  1346. You can extend the source plug-in mechanism.
  1347. To add more hooks, create more source plug-in methods
  1348. within <filename>SourcePlugin</filename> and the
  1349. corresponding derived subclasses.
  1350. The code that calls the plug-in methods uses the
  1351. <filename>plugin.get_source_plugin_methods()</filename>
  1352. function to find the method or methods needed by the call.
  1353. Retrieval of those methods is accomplished by filling up
  1354. a dict with keys that contain the method names of interest.
  1355. On success, these will be filled in with the actual
  1356. methods.
  1357. See the Wic implementation for examples and details.
  1358. </para>
  1359. </section>
  1360. <section id="wayland">
  1361. <title>Wayland</title>
  1362. <para>
  1363. <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)'>Wayland</ulink>
  1364. is a computer display server protocol that
  1365. provides a method for compositing window managers to communicate
  1366. directly with applications and video hardware and expects them to
  1367. communicate with input hardware using other libraries.
  1368. Using Wayland with supporting targets can result in better control
  1369. over graphics frame rendering than an application might otherwise
  1370. achieve.
  1371. </para>
  1372. <para>
  1373. The Yocto Project provides the Wayland protocol libraries and the
  1374. reference
  1375. <ulink url='http://en.wikipedia.org/wiki/Wayland_(display_server_protocol)#Weston'>Weston</ulink>
  1376. compositor as part of its release.
  1377. This section describes what you need to do to implement Wayland and
  1378. use the compositor when building an image for a supporting target.
  1379. </para>
  1380. <section id="wayland-support">
  1381. <title>Support</title>
  1382. <para>
  1383. The Wayland protocol libraries and the reference Weston compositor
  1384. ship as integrated packages in the <filename>meta</filename> layer
  1385. of the
  1386. <link linkend='source-directory'>Source Directory</link>.
  1387. Specifically, you can find the recipes that build both Wayland
  1388. and Weston at <filename>meta/recipes-graphics/wayland</filename>.
  1389. </para>
  1390. <para>
  1391. You can build both the Wayland and Weston packages for use only
  1392. with targets that accept the
  1393. <ulink url='http://dri.freedesktop.org/wiki/'>Mesa 3D and Direct Rendering Infrastructure</ulink>,
  1394. which is also known as Mesa DRI.
  1395. This implies that you cannot build and use the packages if your
  1396. target uses, for example, the
  1397. <trademark class='registered'>Intel</trademark> Embedded Media and
  1398. Graphics Driver (<trademark class='registered'>Intel</trademark>
  1399. EMGD) that overrides Mesa DRI.
  1400. </para>
  1401. <note>
  1402. Due to lack of EGL support, Weston 1.0.3 will not run directly on
  1403. the emulated QEMU hardware.
  1404. However, this version of Weston will run under X emulation without
  1405. issues.
  1406. </note>
  1407. </section>
  1408. <section id="enabling-wayland-in-an-image">
  1409. <title>Enabling Wayland in an Image</title>
  1410. <para>
  1411. To enable Wayland, you need to enable it to be built and enable
  1412. it to be included in the image.
  1413. </para>
  1414. <section id="enable-building">
  1415. <title>Building</title>
  1416. <para>
  1417. To cause Mesa to build the <filename>wayland-egl</filename>
  1418. platform and Weston to build Wayland with Kernel Mode
  1419. Setting
  1420. (<ulink url='https://wiki.archlinux.org/index.php/Kernel_Mode_Setting'>KMS</ulink>)
  1421. support, include the "wayland" flag in the
  1422. <link linkend="var-DISTRO_FEATURES"><filename>DISTRO_FEATURES</filename></link>
  1423. statement in your <filename>local.conf</filename> file:
  1424. <literallayout class='monospaced'>
  1425. DISTRO_FEATURES_append = " wayland"
  1426. </literallayout>
  1427. </para>
  1428. <note>
  1429. If X11 has been enabled elsewhere, Weston will build Wayland
  1430. with X11 support
  1431. </note>
  1432. </section>
  1433. <section id="enable-installation-in-an-image">
  1434. <title>Installing</title>
  1435. <para>
  1436. To install the Wayland feature into an image, you must
  1437. include the following
  1438. <link linkend='var-CORE_IMAGE_EXTRA_INSTALL'><filename>CORE_IMAGE_EXTRA_INSTALL</filename></link>
  1439. statement in your <filename>local.conf</filename> file:
  1440. <literallayout class='monospaced'>
  1441. CORE_IMAGE_EXTRA_INSTALL += "wayland weston"
  1442. </literallayout>
  1443. </para>
  1444. </section>
  1445. </section>
  1446. <section id="running-weston">
  1447. <title>Running Weston</title>
  1448. <para>
  1449. To run Weston inside X11, enabling it as described earlier and
  1450. building a Sato image is sufficient.
  1451. If you are running your image under Sato, a Weston Launcher appears
  1452. in the "Utility" category.
  1453. </para>
  1454. <para>
  1455. Alternatively, you can run Weston through the command-line
  1456. interpretor (CLI), which is better suited for development work.
  1457. To run Weston under the CLI, you need to do the following after
  1458. your image is built:
  1459. <orderedlist>
  1460. <listitem><para>Run these commands to export
  1461. <filename>XDG_RUNTIME_DIR</filename>:
  1462. <literallayout class='monospaced'>
  1463. mkdir -p /tmp/$USER-weston
  1464. chmod 0700 /tmp/$USER-weston
  1465. export XDG_RUNTIME_DIR=/tmp/$USER-weston
  1466. </literallayout></para></listitem>
  1467. <listitem><para>Launch Weston in the shell:
  1468. <literallayout class='monospaced'>
  1469. weston
  1470. </literallayout></para></listitem>
  1471. </orderedlist>
  1472. </para>
  1473. </section>
  1474. </section>
  1475. <section id="licenses">
  1476. <title>Licenses</title>
  1477. <para>
  1478. This section describes the mechanism by which the OpenEmbedded build system
  1479. tracks changes to licensing text.
  1480. The section also describes how to enable commercially licensed recipes,
  1481. which by default are disabled.
  1482. </para>
  1483. <para>
  1484. For information that can help you maintain compliance with various open
  1485. source licensing during the lifecycle of the product, see the
  1486. "<ulink url='&YOCTO_DOCS_DEV_URL;#maintaining-open-source-license-compliance-during-your-products-lifecycle'>Maintaining Open Source License Compliance During Your Project's Lifecycle</ulink>"
  1487. section in the Yocto Project Development Tasks Manual.
  1488. </para>
  1489. <section id="usingpoky-configuring-LIC_FILES_CHKSUM">
  1490. <title>Tracking License Changes</title>
  1491. <para>
  1492. The license of an upstream project might change in the future.
  1493. In order to prevent these changes going unnoticed, the
  1494. <filename><link linkend='var-LIC_FILES_CHKSUM'>LIC_FILES_CHKSUM</link></filename>
  1495. variable tracks changes to the license text. The checksums are validated at the end of the
  1496. configure step, and if the checksums do not match, the build will fail.
  1497. </para>
  1498. <section id="usingpoky-specifying-LIC_FILES_CHKSUM">
  1499. <title>Specifying the <filename>LIC_FILES_CHKSUM</filename> Variable</title>
  1500. <para>
  1501. The <filename>LIC_FILES_CHKSUM</filename>
  1502. variable contains checksums of the license text in the source
  1503. code for the recipe.
  1504. Following is an example of how to specify
  1505. <filename>LIC_FILES_CHKSUM</filename>:
  1506. <literallayout class='monospaced'>
  1507. LIC_FILES_CHKSUM = "file://COPYING;md5=xxxx \
  1508. file://licfile1.txt;beginline=5;endline=29;md5=yyyy \
  1509. file://licfile2.txt;endline=50;md5=zzzz \
  1510. ..."
  1511. </literallayout>
  1512. <note><title>Notes</title>
  1513. <itemizedlist>
  1514. <listitem><para>
  1515. When using "beginline" and "endline", realize that
  1516. line numbering begins with one and not zero.
  1517. Also, the included lines are inclusive (i.e. lines
  1518. five through and including 29 in the previous
  1519. example for <filename>licfile1.txt</filename>).
  1520. </para></listitem>
  1521. <listitem><para>
  1522. When a license check fails, the selected license
  1523. text is included as part of the QA message.
  1524. Using this output, you can determine the exact
  1525. start and finish for the needed license text.
  1526. </para></listitem>
  1527. </itemizedlist>
  1528. </note>
  1529. </para>
  1530. <para>
  1531. The build system uses the
  1532. <filename><link linkend='var-S'>S</link></filename> variable as
  1533. the default directory when searching files listed in
  1534. <filename>LIC_FILES_CHKSUM</filename>.
  1535. The previous example employs the default directory.
  1536. </para>
  1537. <para>
  1538. Consider this next example:
  1539. <literallayout class='monospaced'>
  1540. LIC_FILES_CHKSUM = "file://src/ls.c;beginline=5;endline=16;\
  1541. md5=bb14ed3c4cda583abc85401304b5cd4e"
  1542. LIC_FILES_CHKSUM = "file://${WORKDIR}/license.html;md5=5c94767cedb5d6987c902ac850ded2c6"
  1543. </literallayout>
  1544. </para>
  1545. <para>
  1546. The first line locates a file in
  1547. <filename>${S}/src/ls.c</filename> and isolates lines five
  1548. through 16 as license text.
  1549. The second line refers to a file in
  1550. <filename><link linkend='var-WORKDIR'>WORKDIR</link></filename>.
  1551. </para>
  1552. <para>
  1553. Note that <filename>LIC_FILES_CHKSUM</filename> variable is
  1554. mandatory for all recipes, unless the
  1555. <filename>LICENSE</filename> variable is set to "CLOSED".
  1556. </para>
  1557. </section>
  1558. <section id="usingpoky-LIC_FILES_CHKSUM-explanation-of-syntax">
  1559. <title>Explanation of Syntax</title>
  1560. <para>
  1561. As mentioned in the previous section, the
  1562. <filename>LIC_FILES_CHKSUM</filename> variable lists all the
  1563. important files that contain the license text for the source code.
  1564. It is possible to specify a checksum for an entire file, or a specific section of a
  1565. file (specified by beginning and ending line numbers with the "beginline" and "endline"
  1566. parameters, respectively).
  1567. The latter is useful for source files with a license notice header,
  1568. README documents, and so forth.
  1569. If you do not use the "beginline" parameter, then it is assumed that the text begins on the
  1570. first line of the file.
  1571. Similarly, if you do not use the "endline" parameter, it is assumed that the license text
  1572. ends with the last line of the file.
  1573. </para>
  1574. <para>
  1575. The "md5" parameter stores the md5 checksum of the license text.
  1576. If the license text changes in any way as compared to this parameter
  1577. then a mismatch occurs.
  1578. This mismatch triggers a build failure and notifies the developer.
  1579. Notification allows the developer to review and address the license text changes.
  1580. Also note that if a mismatch occurs during the build, the correct md5
  1581. checksum is placed in the build log and can be easily copied to the recipe.
  1582. </para>
  1583. <para>
  1584. There is no limit to how many files you can specify using the
  1585. <filename>LIC_FILES_CHKSUM</filename> variable.
  1586. Generally, however, every project requires a few specifications for license tracking.
  1587. Many projects have a "COPYING" file that stores the license information for all the source
  1588. code files.
  1589. This practice allows you to just track the "COPYING" file as long as it is kept up to date.
  1590. </para>
  1591. <tip>
  1592. If you specify an empty or invalid "md5" parameter, BitBake returns an md5 mis-match
  1593. error and displays the correct "md5" parameter value during the build.
  1594. The correct parameter is also captured in the build log.
  1595. </tip>
  1596. <tip>
  1597. If the whole file contains only license text, you do not need to use the "beginline" and
  1598. "endline" parameters.
  1599. </tip>
  1600. </section>
  1601. </section>
  1602. <section id="enabling-commercially-licensed-recipes">
  1603. <title>Enabling Commercially Licensed Recipes</title>
  1604. <para>
  1605. By default, the OpenEmbedded build system disables
  1606. components that have commercial or other special licensing
  1607. requirements.
  1608. Such requirements are defined on a
  1609. recipe-by-recipe basis through the
  1610. <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
  1611. variable definition in the affected recipe.
  1612. For instance, the
  1613. <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
  1614. recipe contains the following statement:
  1615. <literallayout class='monospaced'>
  1616. LICENSE_FLAGS = "commercial"
  1617. </literallayout>
  1618. Here is a slightly more complicated example that contains both an
  1619. explicit recipe name and version (after variable expansion):
  1620. <literallayout class='monospaced'>
  1621. LICENSE_FLAGS = "license_${PN}_${PV}"
  1622. </literallayout>
  1623. In order for a component restricted by a <filename>LICENSE_FLAGS</filename>
  1624. definition to be enabled and included in an image, it
  1625. needs to have a matching entry in the global
  1626. <link linkend='var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></link>
  1627. variable, which is a variable
  1628. typically defined in your <filename>local.conf</filename> file.
  1629. For example, to enable
  1630. the <filename>poky/meta/recipes-multimedia/gstreamer/gst-plugins-ugly</filename>
  1631. package, you could add either the string
  1632. "commercial_gst-plugins-ugly" or the more general string
  1633. "commercial" to <filename>LICENSE_FLAGS_WHITELIST</filename>.
  1634. See the
  1635. "<link linkend='license-flag-matching'>License Flag Matching</link>" section
  1636. for a full explanation of how <filename>LICENSE_FLAGS</filename> matching works.
  1637. Here is the example:
  1638. <literallayout class='monospaced'>
  1639. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly"
  1640. </literallayout>
  1641. Likewise, to additionally enable the package built from the recipe containing
  1642. <filename>LICENSE_FLAGS = "license_${PN}_${PV}"</filename>, and assuming
  1643. that the actual recipe name was <filename>emgd_1.10.bb</filename>,
  1644. the following string would enable that package as well as
  1645. the original <filename>gst-plugins-ugly</filename> package:
  1646. <literallayout class='monospaced'>
  1647. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly license_emgd_1.10"
  1648. </literallayout>
  1649. As a convenience, you do not need to specify the complete license string
  1650. in the whitelist for every package.
  1651. You can use an abbreviated form, which consists
  1652. of just the first portion or portions of the license string before
  1653. the initial underscore character or characters.
  1654. A partial string will match
  1655. any license that contains the given string as the first
  1656. portion of its license.
  1657. For example, the following
  1658. whitelist string will also match both of the packages
  1659. previously mentioned as well as any other packages that have
  1660. licenses starting with "commercial" or "license".
  1661. <literallayout class='monospaced'>
  1662. LICENSE_FLAGS_WHITELIST = "commercial license"
  1663. </literallayout>
  1664. </para>
  1665. <section id="license-flag-matching">
  1666. <title>License Flag Matching</title>
  1667. <para>
  1668. License flag matching allows you to control what recipes the
  1669. OpenEmbedded build system includes in the build.
  1670. Fundamentally, the build system attempts to match
  1671. <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
  1672. strings found in recipes against
  1673. <link linkend='var-LICENSE_FLAGS_WHITELIST'><filename>LICENSE_FLAGS_WHITELIST</filename></link>
  1674. strings found in the whitelist.
  1675. A match causes the build system to include a recipe in the
  1676. build, while failure to find a match causes the build system to
  1677. exclude a recipe.
  1678. </para>
  1679. <para>
  1680. In general, license flag matching is simple.
  1681. However, understanding some concepts will help you
  1682. correctly and effectively use matching.
  1683. </para>
  1684. <para>
  1685. Before a flag
  1686. defined by a particular recipe is tested against the
  1687. contents of the whitelist, the expanded string
  1688. <filename>_${PN}</filename> is appended to the flag.
  1689. This expansion makes each <filename>LICENSE_FLAGS</filename>
  1690. value recipe-specific.
  1691. After expansion, the string is then matched against the
  1692. whitelist.
  1693. Thus, specifying
  1694. <filename>LICENSE_FLAGS = "commercial"</filename>
  1695. in recipe "foo", for example, results in the string
  1696. <filename>"commercial_foo"</filename>.
  1697. And, to create a match, that string must appear in the
  1698. whitelist.
  1699. </para>
  1700. <para>
  1701. Judicious use of the <filename>LICENSE_FLAGS</filename>
  1702. strings and the contents of the
  1703. <filename>LICENSE_FLAGS_WHITELIST</filename> variable
  1704. allows you a lot of flexibility for including or excluding
  1705. recipes based on licensing.
  1706. For example, you can broaden the matching capabilities by
  1707. using license flags string subsets in the whitelist.
  1708. <note>When using a string subset, be sure to use the part of
  1709. the expanded string that precedes the appended underscore
  1710. character (e.g. <filename>usethispart_1.3</filename>,
  1711. <filename>usethispart_1.4</filename>, and so forth).
  1712. </note>
  1713. For example, simply specifying the string "commercial" in
  1714. the whitelist matches any expanded
  1715. <filename>LICENSE_FLAGS</filename> definition that starts with
  1716. the string "commercial" such as "commercial_foo" and
  1717. "commercial_bar", which are the strings the build system
  1718. automatically generates for hypothetical recipes named
  1719. "foo" and "bar" assuming those recipes simply specify the
  1720. following:
  1721. <literallayout class='monospaced'>
  1722. LICENSE_FLAGS = "commercial"
  1723. </literallayout>
  1724. Thus, you can choose to exhaustively
  1725. enumerate each license flag in the whitelist and
  1726. allow only specific recipes into the image, or
  1727. you can use a string subset that causes a broader range of
  1728. matches to allow a range of recipes into the image.
  1729. </para>
  1730. <para>
  1731. This scheme works even if the
  1732. <filename>LICENSE_FLAGS</filename> string already
  1733. has <filename>_${PN}</filename> appended.
  1734. For example, the build system turns the license flag
  1735. "commercial_1.2_foo" into "commercial_1.2_foo_foo" and would
  1736. match both the general "commercial" and the specific
  1737. "commercial_1.2_foo" strings found in the whitelist, as
  1738. expected.
  1739. </para>
  1740. <para>
  1741. Here are some other scenarios:
  1742. <itemizedlist>
  1743. <listitem><para>You can specify a versioned string in the
  1744. recipe such as "commercial_foo_1.2" in a "foo" recipe.
  1745. The build system expands this string to
  1746. "commercial_foo_1.2_foo".
  1747. Combine this license flag with a whitelist that has
  1748. the string "commercial" and you match the flag along
  1749. with any other flag that starts with the string
  1750. "commercial".</para></listitem>
  1751. <listitem><para>Under the same circumstances, you can
  1752. use "commercial_foo" in the whitelist and the
  1753. build system not only matches "commercial_foo_1.2" but
  1754. also matches any license flag with the string
  1755. "commercial_foo", regardless of the version.
  1756. </para></listitem>
  1757. <listitem><para>You can be very specific and use both the
  1758. package and version parts in the whitelist (e.g.
  1759. "commercial_foo_1.2") to specifically match a
  1760. versioned recipe.</para></listitem>
  1761. </itemizedlist>
  1762. </para>
  1763. </section>
  1764. <section id="other-variables-related-to-commercial-licenses">
  1765. <title>Other Variables Related to Commercial Licenses</title>
  1766. <para>
  1767. Other helpful variables related to commercial
  1768. license handling exist and are defined in the
  1769. <filename>poky/meta/conf/distro/include/default-distrovars.inc</filename> file:
  1770. <literallayout class='monospaced'>
  1771. COMMERCIAL_AUDIO_PLUGINS ?= ""
  1772. COMMERCIAL_VIDEO_PLUGINS ?= ""
  1773. </literallayout>
  1774. If you want to enable these components, you can do so by making sure you have
  1775. statements similar to the following
  1776. in your <filename>local.conf</filename> configuration file:
  1777. <literallayout class='monospaced'>
  1778. COMMERCIAL_AUDIO_PLUGINS = "gst-plugins-ugly-mad \
  1779. gst-plugins-ugly-mpegaudioparse"
  1780. COMMERCIAL_VIDEO_PLUGINS = "gst-plugins-ugly-mpeg2dec \
  1781. gst-plugins-ugly-mpegstream gst-plugins-bad-mpegvideoparse"
  1782. LICENSE_FLAGS_WHITELIST = "commercial_gst-plugins-ugly commercial_gst-plugins-bad commercial_qmmp"
  1783. </literallayout>
  1784. Of course, you could also create a matching whitelist
  1785. for those components using the more general "commercial"
  1786. in the whitelist, but that would also enable all the
  1787. other packages with
  1788. <link linkend='var-LICENSE_FLAGS'><filename>LICENSE_FLAGS</filename></link>
  1789. containing "commercial", which you may or may not want:
  1790. <literallayout class='monospaced'>
  1791. LICENSE_FLAGS_WHITELIST = "commercial"
  1792. </literallayout>
  1793. </para>
  1794. <para>
  1795. Specifying audio and video plug-ins as part of the
  1796. <filename>COMMERCIAL_AUDIO_PLUGINS</filename> and
  1797. <filename>COMMERCIAL_VIDEO_PLUGINS</filename> statements
  1798. (along with the enabling
  1799. <filename>LICENSE_FLAGS_WHITELIST</filename>) includes the
  1800. plug-ins or components into built images, thus adding
  1801. support for media formats or components.
  1802. </para>
  1803. </section>
  1804. </section>
  1805. </section>
  1806. </chapter>
  1807. <!--
  1808. vim: expandtab tw=80 ts=4
  1809. -->