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