| Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK | 
|  | 2 |  | 
|  | 3 | Working with Packages | 
|  | 4 | ********************* | 
|  | 5 |  | 
|  | 6 | This section describes a few tasks that involve packages: | 
|  | 7 |  | 
|  | 8 | -  :ref:`dev-manual/packages:excluding packages from an image` | 
|  | 9 |  | 
|  | 10 | -  :ref:`dev-manual/packages:incrementing a package version` | 
|  | 11 |  | 
|  | 12 | -  :ref:`dev-manual/packages:handling optional module packaging` | 
|  | 13 |  | 
|  | 14 | -  :ref:`dev-manual/packages:using runtime package management` | 
|  | 15 |  | 
|  | 16 | -  :ref:`dev-manual/packages:generating and using signed packages` | 
|  | 17 |  | 
|  | 18 | -  :ref:`Setting up and running package test | 
|  | 19 | (ptest) <dev-manual/packages:testing packages with ptest>` | 
|  | 20 |  | 
|  | 21 | -  :ref:`dev-manual/packages:creating node package manager (npm) packages` | 
|  | 22 |  | 
|  | 23 | -  :ref:`dev-manual/packages:adding custom metadata to packages` | 
|  | 24 |  | 
|  | 25 | Excluding Packages from an Image | 
|  | 26 | ================================ | 
|  | 27 |  | 
|  | 28 | You might find it necessary to prevent specific packages from being | 
|  | 29 | installed into an image. If so, you can use several variables to direct | 
|  | 30 | the build system to essentially ignore installing recommended packages | 
|  | 31 | or to not install a package at all. | 
|  | 32 |  | 
|  | 33 | The following list introduces variables you can use to prevent packages | 
|  | 34 | from being installed into your image. Each of these variables only works | 
|  | 35 | with IPK and RPM package types, not for Debian packages. | 
|  | 36 | Also, you can use these variables from your ``local.conf`` file | 
|  | 37 | or attach them to a specific image recipe by using a recipe name | 
|  | 38 | override. For more detail on the variables, see the descriptions in the | 
|  | 39 | Yocto Project Reference Manual's glossary chapter. | 
|  | 40 |  | 
|  | 41 | -  :term:`BAD_RECOMMENDATIONS`: | 
|  | 42 | Use this variable to specify "recommended-only" packages that you do | 
|  | 43 | not want installed. | 
|  | 44 |  | 
|  | 45 | -  :term:`NO_RECOMMENDATIONS`: | 
|  | 46 | Use this variable to prevent all "recommended-only" packages from | 
|  | 47 | being installed. | 
|  | 48 |  | 
|  | 49 | -  :term:`PACKAGE_EXCLUDE`: | 
|  | 50 | Use this variable to prevent specific packages from being installed | 
|  | 51 | regardless of whether they are "recommended-only" or not. You need to | 
|  | 52 | realize that the build process could fail with an error when you | 
|  | 53 | prevent the installation of a package whose presence is required by | 
|  | 54 | an installed package. | 
|  | 55 |  | 
|  | 56 | Incrementing a Package Version | 
|  | 57 | ============================== | 
|  | 58 |  | 
|  | 59 | This section provides some background on how binary package versioning | 
|  | 60 | is accomplished and presents some of the services, variables, and | 
|  | 61 | terminology involved. | 
|  | 62 |  | 
|  | 63 | In order to understand binary package versioning, you need to consider | 
|  | 64 | the following: | 
|  | 65 |  | 
|  | 66 | -  Binary Package: The binary package that is eventually built and | 
|  | 67 | installed into an image. | 
|  | 68 |  | 
|  | 69 | -  Binary Package Version: The binary package version is composed of two | 
|  | 70 | components --- a version and a revision. | 
|  | 71 |  | 
|  | 72 | .. note:: | 
|  | 73 |  | 
|  | 74 | Technically, a third component, the "epoch" (i.e. :term:`PE`) is involved | 
|  | 75 | but this discussion for the most part ignores :term:`PE`. | 
|  | 76 |  | 
|  | 77 | The version and revision are taken from the | 
|  | 78 | :term:`PV` and | 
|  | 79 | :term:`PR` variables, respectively. | 
|  | 80 |  | 
|  | 81 | -  :term:`PV`: The recipe version. :term:`PV` represents the version of the | 
|  | 82 | software being packaged. Do not confuse :term:`PV` with the binary | 
|  | 83 | package version. | 
|  | 84 |  | 
|  | 85 | -  :term:`PR`: The recipe revision. | 
|  | 86 |  | 
|  | 87 | -  :term:`SRCPV`: The OpenEmbedded | 
|  | 88 | build system uses this string to help define the value of :term:`PV` when | 
|  | 89 | the source code revision needs to be included in it. | 
|  | 90 |  | 
|  | 91 | -  :yocto_wiki:`PR Service </PR_Service>`: A | 
|  | 92 | network-based service that helps automate keeping package feeds | 
|  | 93 | compatible with existing package manager applications such as RPM, | 
|  | 94 | APT, and OPKG. | 
|  | 95 |  | 
|  | 96 | Whenever the binary package content changes, the binary package version | 
|  | 97 | must change. Changing the binary package version is accomplished by | 
|  | 98 | changing or "bumping" the :term:`PR` and/or :term:`PV` values. Increasing these | 
|  | 99 | values occurs one of two ways: | 
|  | 100 |  | 
|  | 101 | -  Automatically using a Package Revision Service (PR Service). | 
|  | 102 |  | 
|  | 103 | -  Manually incrementing the :term:`PR` and/or :term:`PV` variables. | 
|  | 104 |  | 
|  | 105 | Given a primary challenge of any build system and its users is how to | 
|  | 106 | maintain a package feed that is compatible with existing package manager | 
|  | 107 | applications such as RPM, APT, and OPKG, using an automated system is | 
|  | 108 | much preferred over a manual system. In either system, the main | 
|  | 109 | requirement is that binary package version numbering increases in a | 
|  | 110 | linear fashion and that there is a number of version components that | 
|  | 111 | support that linear progression. For information on how to ensure | 
|  | 112 | package revisioning remains linear, see the | 
|  | 113 | ":ref:`dev-manual/packages:automatically incrementing a package version number`" | 
|  | 114 | section. | 
|  | 115 |  | 
|  | 116 | The following three sections provide related information on the PR | 
|  | 117 | Service, the manual method for "bumping" :term:`PR` and/or :term:`PV`, and on | 
|  | 118 | how to ensure binary package revisioning remains linear. | 
|  | 119 |  | 
|  | 120 | Working With a PR Service | 
|  | 121 | ------------------------- | 
|  | 122 |  | 
|  | 123 | As mentioned, attempting to maintain revision numbers in the | 
|  | 124 | :term:`Metadata` is error prone, inaccurate, | 
|  | 125 | and causes problems for people submitting recipes. Conversely, the PR | 
|  | 126 | Service automatically generates increasing numbers, particularly the | 
|  | 127 | revision field, which removes the human element. | 
|  | 128 |  | 
|  | 129 | .. note:: | 
|  | 130 |  | 
|  | 131 | For additional information on using a PR Service, you can see the | 
|  | 132 | :yocto_wiki:`PR Service </PR_Service>` wiki page. | 
|  | 133 |  | 
|  | 134 | The Yocto Project uses variables in order of decreasing priority to | 
|  | 135 | facilitate revision numbering (i.e. | 
|  | 136 | :term:`PE`, | 
|  | 137 | :term:`PV`, and | 
|  | 138 | :term:`PR` for epoch, version, and | 
|  | 139 | revision, respectively). The values are highly dependent on the policies | 
|  | 140 | and procedures of a given distribution and package feed. | 
|  | 141 |  | 
|  | 142 | Because the OpenEmbedded build system uses | 
|  | 143 | ":ref:`signatures <overview-manual/concepts:checksums (signatures)>`", which are | 
|  | 144 | unique to a given build, the build system knows when to rebuild | 
|  | 145 | packages. All the inputs into a given task are represented by a | 
|  | 146 | signature, which can trigger a rebuild when different. Thus, the build | 
|  | 147 | system itself does not rely on the :term:`PR`, :term:`PV`, and :term:`PE` numbers to | 
|  | 148 | trigger a rebuild. The signatures, however, can be used to generate | 
|  | 149 | these values. | 
|  | 150 |  | 
|  | 151 | The PR Service works with both ``OEBasic`` and ``OEBasicHash`` | 
|  | 152 | generators. The value of :term:`PR` bumps when the checksum changes and the | 
|  | 153 | different generator mechanisms change signatures under different | 
|  | 154 | circumstances. | 
|  | 155 |  | 
|  | 156 | As implemented, the build system includes values from the PR Service | 
|  | 157 | into the :term:`PR` field as an addition using the form "``.x``" so ``r0`` | 
|  | 158 | becomes ``r0.1``, ``r0.2`` and so forth. This scheme allows existing | 
|  | 159 | :term:`PR` values to be used for whatever reasons, which include manual | 
|  | 160 | :term:`PR` bumps, should it be necessary. | 
|  | 161 |  | 
|  | 162 | By default, the PR Service is not enabled or running. Thus, the packages | 
|  | 163 | generated are just "self consistent". The build system adds and removes | 
|  | 164 | packages and there are no guarantees about upgrade paths but images will | 
|  | 165 | be consistent and correct with the latest changes. | 
|  | 166 |  | 
|  | 167 | The simplest form for a PR Service is for a single host development system | 
|  | 168 | that builds the package feed (building system). For this scenario, you can | 
|  | 169 | enable a local PR Service by setting :term:`PRSERV_HOST` in your | 
|  | 170 | ``local.conf`` file in the :term:`Build Directory`:: | 
|  | 171 |  | 
|  | 172 | PRSERV_HOST = "localhost:0" | 
|  | 173 |  | 
|  | 174 | Once the service is started, packages will automatically | 
|  | 175 | get increasing :term:`PR` values and BitBake takes care of starting and | 
|  | 176 | stopping the server. | 
|  | 177 |  | 
|  | 178 | If you have a more complex setup where multiple host development systems | 
|  | 179 | work against a common, shared package feed, you have a single PR Service | 
|  | 180 | running and it is connected to each building system. For this scenario, | 
|  | 181 | you need to start the PR Service using the ``bitbake-prserv`` command:: | 
|  | 182 |  | 
|  | 183 | bitbake-prserv --host ip --port port --start | 
|  | 184 |  | 
|  | 185 | In addition to | 
|  | 186 | hand-starting the service, you need to update the ``local.conf`` file of | 
|  | 187 | each building system as described earlier so each system points to the | 
|  | 188 | server and port. | 
|  | 189 |  | 
|  | 190 | It is also recommended you use build history, which adds some sanity | 
|  | 191 | checks to binary package versions, in conjunction with the server that | 
|  | 192 | is running the PR Service. To enable build history, add the following to | 
|  | 193 | each building system's ``local.conf`` file:: | 
|  | 194 |  | 
|  | 195 | # It is recommended to activate "buildhistory" for testing the PR service | 
|  | 196 | INHERIT += "buildhistory" | 
|  | 197 | BUILDHISTORY_COMMIT = "1" | 
|  | 198 |  | 
|  | 199 | For information on build | 
|  | 200 | history, see the | 
|  | 201 | ":ref:`dev-manual/build-quality:maintaining build output quality`" section. | 
|  | 202 |  | 
|  | 203 | .. note:: | 
|  | 204 |  | 
|  | 205 | The OpenEmbedded build system does not maintain :term:`PR` information as | 
|  | 206 | part of the shared state (sstate) packages. If you maintain an sstate | 
|  | 207 | feed, it's expected that either all your building systems that | 
|  | 208 | contribute to the sstate feed use a shared PR Service, or you do not | 
|  | 209 | run a PR Service on any of your building systems. Having some systems | 
|  | 210 | use a PR Service while others do not leads to obvious problems. | 
|  | 211 |  | 
|  | 212 | For more information on shared state, see the | 
|  | 213 | ":ref:`overview-manual/concepts:shared state cache`" | 
|  | 214 | section in the Yocto Project Overview and Concepts Manual. | 
|  | 215 |  | 
|  | 216 | Manually Bumping PR | 
|  | 217 | ------------------- | 
|  | 218 |  | 
|  | 219 | The alternative to setting up a PR Service is to manually "bump" the | 
|  | 220 | :term:`PR` variable. | 
|  | 221 |  | 
|  | 222 | If a committed change results in changing the package output, then the | 
|  | 223 | value of the :term:`PR` variable needs to be increased (or "bumped") as part of | 
|  | 224 | that commit. For new recipes you should add the :term:`PR` variable and set | 
|  | 225 | its initial value equal to "r0", which is the default. Even though the | 
|  | 226 | default value is "r0", the practice of adding it to a new recipe makes | 
|  | 227 | it harder to forget to bump the variable when you make changes to the | 
|  | 228 | recipe in future. | 
|  | 229 |  | 
| Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 230 | Usually, version increases occur only to binary packages. However, if | 
|  | 231 | for some reason :term:`PV` changes but does not increase, you can increase | 
|  | 232 | the :term:`PE` variable (Package Epoch). The :term:`PE` variable defaults to | 
|  | 233 | "0". | 
|  | 234 |  | 
|  | 235 | Binary package version numbering strives to follow the `Debian Version | 
|  | 236 | Field Policy | 
|  | 237 | Guidelines <https://www.debian.org/doc/debian-policy/ch-controlfields.html>`__. | 
|  | 238 | These guidelines define how versions are compared and what "increasing" | 
|  | 239 | a version means. | 
|  | 240 |  | 
|  | 241 | Automatically Incrementing a Package Version Number | 
|  | 242 | --------------------------------------------------- | 
|  | 243 |  | 
|  | 244 | When fetching a repository, BitBake uses the | 
|  | 245 | :term:`SRCREV` variable to determine | 
|  | 246 | the specific source code revision from which to build. You set the | 
|  | 247 | :term:`SRCREV` variable to | 
|  | 248 | :term:`AUTOREV` to cause the | 
|  | 249 | OpenEmbedded build system to automatically use the latest revision of | 
|  | 250 | the software:: | 
|  | 251 |  | 
|  | 252 | SRCREV = "${AUTOREV}" | 
|  | 253 |  | 
|  | 254 | Furthermore, you need to reference :term:`SRCPV` in :term:`PV` in order to | 
|  | 255 | automatically update the version whenever the revision of the source | 
|  | 256 | code changes. Here is an example:: | 
|  | 257 |  | 
|  | 258 | PV = "1.0+git${SRCPV}" | 
|  | 259 |  | 
|  | 260 | The OpenEmbedded build system substitutes :term:`SRCPV` with the following: | 
|  | 261 |  | 
|  | 262 | .. code-block:: none | 
|  | 263 |  | 
|  | 264 | AUTOINC+source_code_revision | 
|  | 265 |  | 
|  | 266 | The build system replaces the ``AUTOINC`` | 
|  | 267 | with a number. The number used depends on the state of the PR Service: | 
|  | 268 |  | 
|  | 269 | -  If PR Service is enabled, the build system increments the number, | 
|  | 270 | which is similar to the behavior of | 
|  | 271 | :term:`PR`. This behavior results in | 
|  | 272 | linearly increasing package versions, which is desirable. Here is an | 
|  | 273 | example: | 
|  | 274 |  | 
|  | 275 | .. code-block:: none | 
|  | 276 |  | 
|  | 277 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | 
|  | 278 | hello-world-git_0.0+git1+dd2f5c3565-r0.0_armv7a-neon.ipk | 
|  | 279 |  | 
|  | 280 | -  If PR Service is not enabled, the build system replaces the | 
|  | 281 | ``AUTOINC`` placeholder with zero (i.e. "0"). This results in | 
|  | 282 | changing the package version since the source revision is included. | 
|  | 283 | However, package versions are not increased linearly. Here is an | 
|  | 284 | example: | 
|  | 285 |  | 
|  | 286 | .. code-block:: none | 
|  | 287 |  | 
|  | 288 | hello-world-git_0.0+git0+b6558dd387-r0.0_armv7a-neon.ipk | 
|  | 289 | hello-world-git_0.0+git0+dd2f5c3565-r0.0_armv7a-neon.ipk | 
|  | 290 |  | 
|  | 291 | In summary, the OpenEmbedded build system does not track the history of | 
|  | 292 | binary package versions for this purpose. ``AUTOINC``, in this case, is | 
|  | 293 | comparable to :term:`PR`. If PR server is not enabled, ``AUTOINC`` in the | 
|  | 294 | package version is simply replaced by "0". If PR server is enabled, the | 
|  | 295 | build system keeps track of the package versions and bumps the number | 
|  | 296 | when the package revision changes. | 
|  | 297 |  | 
|  | 298 | Handling Optional Module Packaging | 
|  | 299 | ================================== | 
|  | 300 |  | 
|  | 301 | Many pieces of software split functionality into optional modules (or | 
|  | 302 | plugins) and the plugins that are built might depend on configuration | 
|  | 303 | options. To avoid having to duplicate the logic that determines what | 
|  | 304 | modules are available in your recipe or to avoid having to package each | 
|  | 305 | module by hand, the OpenEmbedded build system provides functionality to | 
|  | 306 | handle module packaging dynamically. | 
|  | 307 |  | 
|  | 308 | To handle optional module packaging, you need to do two things: | 
|  | 309 |  | 
|  | 310 | -  Ensure the module packaging is actually done. | 
|  | 311 |  | 
|  | 312 | -  Ensure that any dependencies on optional modules from other recipes | 
|  | 313 | are satisfied by your recipe. | 
|  | 314 |  | 
|  | 315 | Making Sure the Packaging is Done | 
|  | 316 | --------------------------------- | 
|  | 317 |  | 
|  | 318 | To ensure the module packaging actually gets done, you use the | 
|  | 319 | ``do_split_packages`` function within the ``populate_packages`` Python | 
|  | 320 | function in your recipe. The ``do_split_packages`` function searches for | 
|  | 321 | a pattern of files or directories under a specified path and creates a | 
|  | 322 | package for each one it finds by appending to the | 
|  | 323 | :term:`PACKAGES` variable and | 
|  | 324 | setting the appropriate values for ``FILES:packagename``, | 
|  | 325 | ``RDEPENDS:packagename``, ``DESCRIPTION:packagename``, and so forth. | 
|  | 326 | Here is an example from the ``lighttpd`` recipe:: | 
|  | 327 |  | 
|  | 328 | python populate_packages:prepend () { | 
|  | 329 | lighttpd_libdir = d.expand('${libdir}') | 
|  | 330 | do_split_packages(d, lighttpd_libdir, '^mod_(.*).so$', | 
|  | 331 | 'lighttpd-module-%s', 'Lighttpd module for %s', | 
|  | 332 | extra_depends='') | 
|  | 333 | } | 
|  | 334 |  | 
|  | 335 | The previous example specifies a number of things in the call to | 
|  | 336 | ``do_split_packages``. | 
|  | 337 |  | 
|  | 338 | -  A directory within the files installed by your recipe through | 
|  | 339 | :ref:`ref-tasks-install` in which to search. | 
|  | 340 |  | 
|  | 341 | -  A regular expression used to match module files in that directory. In | 
|  | 342 | the example, note the parentheses () that mark the part of the | 
|  | 343 | expression from which the module name should be derived. | 
|  | 344 |  | 
|  | 345 | -  A pattern to use for the package names. | 
|  | 346 |  | 
|  | 347 | -  A description for each package. | 
|  | 348 |  | 
|  | 349 | -  An empty string for ``extra_depends``, which disables the default | 
|  | 350 | dependency on the main ``lighttpd`` package. Thus, if a file in | 
|  | 351 | ``${libdir}`` called ``mod_alias.so`` is found, a package called | 
|  | 352 | ``lighttpd-module-alias`` is created for it and the | 
|  | 353 | :term:`DESCRIPTION` is set to | 
|  | 354 | "Lighttpd module for alias". | 
|  | 355 |  | 
|  | 356 | Often, packaging modules is as simple as the previous example. However, | 
|  | 357 | there are more advanced options that you can use within | 
|  | 358 | ``do_split_packages`` to modify its behavior. And, if you need to, you | 
|  | 359 | can add more logic by specifying a hook function that is called for each | 
|  | 360 | package. It is also perfectly acceptable to call ``do_split_packages`` | 
|  | 361 | multiple times if you have more than one set of modules to package. | 
|  | 362 |  | 
|  | 363 | For more examples that show how to use ``do_split_packages``, see the | 
|  | 364 | ``connman.inc`` file in the ``meta/recipes-connectivity/connman/`` | 
|  | 365 | directory of the ``poky`` :ref:`source repository <overview-manual/development-environment:yocto project source repositories>`. You can | 
|  | 366 | also find examples in ``meta/classes-recipe/kernel.bbclass``. | 
|  | 367 |  | 
|  | 368 | Following is a reference that shows ``do_split_packages`` mandatory and | 
|  | 369 | optional arguments:: | 
|  | 370 |  | 
|  | 371 | Mandatory arguments | 
|  | 372 |  | 
|  | 373 | root | 
|  | 374 | The path in which to search | 
|  | 375 | file_regex | 
|  | 376 | Regular expression to match searched files. | 
|  | 377 | Use parentheses () to mark the part of this | 
|  | 378 | expression that should be used to derive the | 
|  | 379 | module name (to be substituted where %s is | 
|  | 380 | used in other function arguments as noted below) | 
|  | 381 | output_pattern | 
|  | 382 | Pattern to use for the package names. Must | 
|  | 383 | include %s. | 
|  | 384 | description | 
|  | 385 | Description to set for each package. Must | 
|  | 386 | include %s. | 
|  | 387 |  | 
|  | 388 | Optional arguments | 
|  | 389 |  | 
|  | 390 | postinst | 
|  | 391 | Postinstall script to use for all packages | 
|  | 392 | (as a string) | 
|  | 393 | recursive | 
|  | 394 | True to perform a recursive search --- default | 
|  | 395 | False | 
|  | 396 | hook | 
|  | 397 | A hook function to be called for every match. | 
|  | 398 | The function will be called with the following | 
|  | 399 | arguments (in the order listed): | 
|  | 400 |  | 
|  | 401 | f | 
|  | 402 | Full path to the file/directory match | 
|  | 403 | pkg | 
|  | 404 | The package name | 
|  | 405 | file_regex | 
|  | 406 | As above | 
|  | 407 | output_pattern | 
|  | 408 | As above | 
|  | 409 | modulename | 
|  | 410 | The module name derived using file_regex | 
|  | 411 | extra_depends | 
|  | 412 | Extra runtime dependencies (RDEPENDS) to be | 
|  | 413 | set for all packages. The default value of None | 
|  | 414 | causes a dependency on the main package | 
|  | 415 | (${PN}) --- if you do not want this, pass empty | 
|  | 416 | string '' for this parameter. | 
|  | 417 | aux_files_pattern | 
|  | 418 | Extra item(s) to be added to FILES for each | 
|  | 419 | package. Can be a single string item or a list | 
|  | 420 | of strings for multiple items. Must include %s. | 
|  | 421 | postrm | 
|  | 422 | postrm script to use for all packages (as a | 
|  | 423 | string) | 
|  | 424 | allow_dirs | 
|  | 425 | True to allow directories to be matched - | 
|  | 426 | default False | 
|  | 427 | prepend | 
|  | 428 | If True, prepend created packages to PACKAGES | 
|  | 429 | instead of the default False which appends them | 
|  | 430 | match_path | 
|  | 431 | match file_regex on the whole relative path to | 
|  | 432 | the root rather than just the filename | 
|  | 433 | aux_files_pattern_verbatim | 
|  | 434 | Extra item(s) to be added to FILES for each | 
|  | 435 | package, using the actual derived module name | 
|  | 436 | rather than converting it to something legal | 
|  | 437 | for a package name. Can be a single string item | 
|  | 438 | or a list of strings for multiple items. Must | 
|  | 439 | include %s. | 
|  | 440 | allow_links | 
|  | 441 | True to allow symlinks to be matched --- default | 
|  | 442 | False | 
|  | 443 | summary | 
|  | 444 | Summary to set for each package. Must include %s; | 
|  | 445 | defaults to description if not set. | 
|  | 446 |  | 
|  | 447 |  | 
|  | 448 |  | 
|  | 449 | Satisfying Dependencies | 
|  | 450 | ----------------------- | 
|  | 451 |  | 
|  | 452 | The second part for handling optional module packaging is to ensure that | 
|  | 453 | any dependencies on optional modules from other recipes are satisfied by | 
|  | 454 | your recipe. You can be sure these dependencies are satisfied by using | 
|  | 455 | the :term:`PACKAGES_DYNAMIC` | 
|  | 456 | variable. Here is an example that continues with the ``lighttpd`` recipe | 
|  | 457 | shown earlier:: | 
|  | 458 |  | 
|  | 459 | PACKAGES_DYNAMIC = "lighttpd-module-.*" | 
|  | 460 |  | 
|  | 461 | The name | 
|  | 462 | specified in the regular expression can of course be anything. In this | 
|  | 463 | example, it is ``lighttpd-module-`` and is specified as the prefix to | 
|  | 464 | ensure that any :term:`RDEPENDS` and | 
|  | 465 | :term:`RRECOMMENDS` on a package | 
|  | 466 | name starting with the prefix are satisfied during build time. If you | 
|  | 467 | are using ``do_split_packages`` as described in the previous section, | 
|  | 468 | the value you put in :term:`PACKAGES_DYNAMIC` should correspond to the name | 
|  | 469 | pattern specified in the call to ``do_split_packages``. | 
|  | 470 |  | 
|  | 471 | Using Runtime Package Management | 
|  | 472 | ================================ | 
|  | 473 |  | 
|  | 474 | During a build, BitBake always transforms a recipe into one or more | 
|  | 475 | packages. For example, BitBake takes the ``bash`` recipe and produces a | 
|  | 476 | number of packages (e.g. ``bash``, ``bash-bashbug``, | 
|  | 477 | ``bash-completion``, ``bash-completion-dbg``, ``bash-completion-dev``, | 
|  | 478 | ``bash-completion-extra``, ``bash-dbg``, and so forth). Not all | 
|  | 479 | generated packages are included in an image. | 
|  | 480 |  | 
|  | 481 | In several situations, you might need to update, add, remove, or query | 
|  | 482 | the packages on a target device at runtime (i.e. without having to | 
|  | 483 | generate a new image). Examples of such situations include: | 
|  | 484 |  | 
|  | 485 | -  You want to provide in-the-field updates to deployed devices (e.g. | 
|  | 486 | security updates). | 
|  | 487 |  | 
|  | 488 | -  You want to have a fast turn-around development cycle for one or more | 
|  | 489 | applications that run on your device. | 
|  | 490 |  | 
|  | 491 | -  You want to temporarily install the "debug" packages of various | 
|  | 492 | applications on your device so that debugging can be greatly improved | 
|  | 493 | by allowing access to symbols and source debugging. | 
|  | 494 |  | 
|  | 495 | -  You want to deploy a more minimal package selection of your device | 
|  | 496 | but allow in-the-field updates to add a larger selection for | 
|  | 497 | customization. | 
|  | 498 |  | 
|  | 499 | In all these situations, you have something similar to a more | 
|  | 500 | traditional Linux distribution in that in-field devices are able to | 
|  | 501 | receive pre-compiled packages from a server for installation or update. | 
|  | 502 | Being able to install these packages on a running, in-field device is | 
|  | 503 | what is termed "runtime package management". | 
|  | 504 |  | 
|  | 505 | In order to use runtime package management, you need a host or server | 
|  | 506 | machine that serves up the pre-compiled packages plus the required | 
|  | 507 | metadata. You also need package manipulation tools on the target. The | 
|  | 508 | build machine is a likely candidate to act as the server. However, that | 
|  | 509 | machine does not necessarily have to be the package server. The build | 
|  | 510 | machine could push its artifacts to another machine that acts as the | 
|  | 511 | server (e.g. Internet-facing). In fact, doing so is advantageous for a | 
|  | 512 | production environment as getting the packages away from the development | 
|  | 513 | system's :term:`Build Directory` prevents accidental overwrites. | 
|  | 514 |  | 
|  | 515 | A simple build that targets just one device produces more than one | 
|  | 516 | package database. In other words, the packages produced by a build are | 
|  | 517 | separated out into a couple of different package groupings based on | 
|  | 518 | criteria such as the target's CPU architecture, the target board, or the | 
|  | 519 | C library used on the target. For example, a build targeting the | 
|  | 520 | ``qemux86`` device produces the following three package databases: | 
|  | 521 | ``noarch``, ``i586``, and ``qemux86``. If you wanted your ``qemux86`` | 
|  | 522 | device to be aware of all the packages that were available to it, you | 
|  | 523 | would need to point it to each of these databases individually. In a | 
|  | 524 | similar way, a traditional Linux distribution usually is configured to | 
|  | 525 | be aware of a number of software repositories from which it retrieves | 
|  | 526 | packages. | 
|  | 527 |  | 
|  | 528 | Using runtime package management is completely optional and not required | 
|  | 529 | for a successful build or deployment in any way. But if you want to make | 
|  | 530 | use of runtime package management, you need to do a couple things above | 
|  | 531 | and beyond the basics. The remainder of this section describes what you | 
|  | 532 | need to do. | 
|  | 533 |  | 
|  | 534 | Build Considerations | 
|  | 535 | -------------------- | 
|  | 536 |  | 
|  | 537 | This section describes build considerations of which you need to be | 
|  | 538 | aware in order to provide support for runtime package management. | 
|  | 539 |  | 
|  | 540 | When BitBake generates packages, it needs to know what format or formats | 
|  | 541 | to use. In your configuration, you use the | 
|  | 542 | :term:`PACKAGE_CLASSES` | 
|  | 543 | variable to specify the format: | 
|  | 544 |  | 
|  | 545 | #. Open the ``local.conf`` file inside your :term:`Build Directory` (e.g. | 
|  | 546 | ``poky/build/conf/local.conf``). | 
|  | 547 |  | 
|  | 548 | #. Select the desired package format as follows:: | 
|  | 549 |  | 
|  | 550 | PACKAGE_CLASSES ?= "package_packageformat" | 
|  | 551 |  | 
|  | 552 | where packageformat can be "ipk", "rpm", | 
|  | 553 | "deb", or "tar" which are the supported package formats. | 
|  | 554 |  | 
|  | 555 | .. note:: | 
|  | 556 |  | 
|  | 557 | Because the Yocto Project supports four different package formats, | 
|  | 558 | you can set the variable with more than one argument. However, the | 
|  | 559 | OpenEmbedded build system only uses the first argument when | 
|  | 560 | creating an image or Software Development Kit (SDK). | 
|  | 561 |  | 
|  | 562 | If you would like your image to start off with a basic package database | 
|  | 563 | containing the packages in your current build as well as to have the | 
|  | 564 | relevant tools available on the target for runtime package management, | 
|  | 565 | you can include "package-management" in the | 
|  | 566 | :term:`IMAGE_FEATURES` | 
|  | 567 | variable. Including "package-management" in this configuration variable | 
|  | 568 | ensures that when the image is assembled for your target, the image | 
|  | 569 | includes the currently-known package databases as well as the | 
|  | 570 | target-specific tools required for runtime package management to be | 
|  | 571 | performed on the target. However, this is not strictly necessary. You | 
|  | 572 | could start your image off without any databases but only include the | 
|  | 573 | required on-target package tool(s). As an example, you could include | 
|  | 574 | "opkg" in your | 
|  | 575 | :term:`IMAGE_INSTALL` variable | 
|  | 576 | if you are using the IPK package format. You can then initialize your | 
|  | 577 | target's package database(s) later once your image is up and running. | 
|  | 578 |  | 
|  | 579 | Whenever you perform any sort of build step that can potentially | 
|  | 580 | generate a package or modify existing package, it is always a good idea | 
|  | 581 | to re-generate the package index after the build by using the following | 
|  | 582 | command:: | 
|  | 583 |  | 
|  | 584 | $ bitbake package-index | 
|  | 585 |  | 
|  | 586 | It might be tempting to build the | 
|  | 587 | package and the package index at the same time with a command such as | 
|  | 588 | the following:: | 
|  | 589 |  | 
|  | 590 | $ bitbake some-package package-index | 
|  | 591 |  | 
|  | 592 | Do not do this as | 
|  | 593 | BitBake does not schedule the package index for after the completion of | 
|  | 594 | the package you are building. Consequently, you cannot be sure of the | 
|  | 595 | package index including information for the package you just built. | 
|  | 596 | Thus, be sure to run the package update step separately after building | 
|  | 597 | any packages. | 
|  | 598 |  | 
|  | 599 | You can use the | 
|  | 600 | :term:`PACKAGE_FEED_ARCHS`, | 
|  | 601 | :term:`PACKAGE_FEED_BASE_PATHS`, | 
|  | 602 | and | 
|  | 603 | :term:`PACKAGE_FEED_URIS` | 
|  | 604 | variables to pre-configure target images to use a package feed. If you | 
|  | 605 | do not define these variables, then manual steps as described in the | 
|  | 606 | subsequent sections are necessary to configure the target. You should | 
|  | 607 | set these variables before building the image in order to produce a | 
|  | 608 | correctly configured image. | 
|  | 609 |  | 
|  | 610 | When your build is complete, your packages reside in the | 
|  | 611 | ``${TMPDIR}/deploy/packageformat`` directory. For example, if | 
|  | 612 | ``${``\ :term:`TMPDIR`\ ``}`` is | 
|  | 613 | ``tmp`` and your selected package type is RPM, then your RPM packages | 
|  | 614 | are available in ``tmp/deploy/rpm``. | 
|  | 615 |  | 
|  | 616 | Host or Server Machine Setup | 
|  | 617 | ---------------------------- | 
|  | 618 |  | 
|  | 619 | Although other protocols are possible, a server using HTTP typically | 
|  | 620 | serves packages. If you want to use HTTP, then set up and configure a | 
|  | 621 | web server such as Apache 2, lighttpd, or Python web server on the | 
|  | 622 | machine serving the packages. | 
|  | 623 |  | 
|  | 624 | To keep things simple, this section describes how to set up a | 
|  | 625 | Python web server to share package feeds from the developer's | 
|  | 626 | machine. Although this server might not be the best for a production | 
|  | 627 | environment, the setup is simple and straight forward. Should you want | 
|  | 628 | to use a different server more suited for production (e.g. Apache 2, | 
|  | 629 | Lighttpd, or Nginx), take the appropriate steps to do so. | 
|  | 630 |  | 
|  | 631 | From within the :term:`Build Directory` where you have built an image based on | 
|  | 632 | your packaging choice (i.e. the :term:`PACKAGE_CLASSES` setting), simply start | 
|  | 633 | the server. The following example assumes a :term:`Build Directory` of ``poky/build`` | 
|  | 634 | and a :term:`PACKAGE_CLASSES` setting of ":ref:`ref-classes-package_rpm`":: | 
|  | 635 |  | 
|  | 636 | $ cd poky/build/tmp/deploy/rpm | 
|  | 637 | $ python3 -m http.server | 
|  | 638 |  | 
|  | 639 | Target Setup | 
|  | 640 | ------------ | 
|  | 641 |  | 
|  | 642 | Setting up the target differs depending on the package management | 
|  | 643 | system. This section provides information for RPM, IPK, and DEB. | 
|  | 644 |  | 
|  | 645 | Using RPM | 
|  | 646 | ~~~~~~~~~ | 
|  | 647 |  | 
|  | 648 | The :wikipedia:`Dandified Packaging <DNF_(software)>` (DNF) performs | 
|  | 649 | runtime package management of RPM packages. In order to use DNF for | 
|  | 650 | runtime package management, you must perform an initial setup on the | 
|  | 651 | target machine for cases where the ``PACKAGE_FEED_*`` variables were not | 
|  | 652 | set as part of the image that is running on the target. This means if | 
|  | 653 | you built your image and did not use these variables as part of the | 
|  | 654 | build and your image is now running on the target, you need to perform | 
|  | 655 | the steps in this section if you want to use runtime package management. | 
|  | 656 |  | 
|  | 657 | .. note:: | 
|  | 658 |  | 
|  | 659 | For information on the ``PACKAGE_FEED_*`` variables, see | 
|  | 660 | :term:`PACKAGE_FEED_ARCHS`, :term:`PACKAGE_FEED_BASE_PATHS`, and | 
|  | 661 | :term:`PACKAGE_FEED_URIS` in the Yocto Project Reference Manual variables | 
|  | 662 | glossary. | 
|  | 663 |  | 
|  | 664 | On the target, you must inform DNF that package databases are available. | 
|  | 665 | You do this by creating a file named | 
|  | 666 | ``/etc/yum.repos.d/oe-packages.repo`` and defining the ``oe-packages``. | 
|  | 667 |  | 
|  | 668 | As an example, assume the target is able to use the following package | 
|  | 669 | databases: ``all``, ``i586``, and ``qemux86`` from a server named | 
|  | 670 | ``my.server``. The specifics for setting up the web server are up to | 
|  | 671 | you. The critical requirement is that the URIs in the target repository | 
|  | 672 | configuration point to the correct remote location for the feeds. | 
|  | 673 |  | 
|  | 674 | .. note:: | 
|  | 675 |  | 
|  | 676 | For development purposes, you can point the web server to the build | 
|  | 677 | system's ``deploy`` directory. However, for production use, it is better to | 
|  | 678 | copy the package directories to a location outside of the build area and use | 
|  | 679 | that location. Doing so avoids situations where the build system | 
|  | 680 | overwrites or changes the ``deploy`` directory. | 
|  | 681 |  | 
|  | 682 | When telling DNF where to look for the package databases, you must | 
|  | 683 | declare individual locations per architecture or a single location used | 
|  | 684 | for all architectures. You cannot do both: | 
|  | 685 |  | 
|  | 686 | -  *Create an Explicit List of Architectures:* Define individual base | 
|  | 687 | URLs to identify where each package database is located: | 
|  | 688 |  | 
|  | 689 | .. code-block:: none | 
|  | 690 |  | 
|  | 691 | [oe-packages] | 
|  | 692 | baseurl=http://my.server/rpm/i586  http://my.server/rpm/qemux86 http://my.server/rpm/all | 
|  | 693 |  | 
|  | 694 | This example | 
|  | 695 | informs DNF about individual package databases for all three | 
|  | 696 | architectures. | 
|  | 697 |  | 
|  | 698 | -  *Create a Single (Full) Package Index:* Define a single base URL that | 
|  | 699 | identifies where a full package database is located:: | 
|  | 700 |  | 
|  | 701 | [oe-packages] | 
|  | 702 | baseurl=http://my.server/rpm | 
|  | 703 |  | 
|  | 704 | This example informs DNF about a single | 
|  | 705 | package database that contains all the package index information for | 
|  | 706 | all supported architectures. | 
|  | 707 |  | 
|  | 708 | Once you have informed DNF where to find the package databases, you need | 
|  | 709 | to fetch them: | 
|  | 710 |  | 
|  | 711 | .. code-block:: none | 
|  | 712 |  | 
|  | 713 | # dnf makecache | 
|  | 714 |  | 
|  | 715 | DNF is now able to find, install, and | 
|  | 716 | upgrade packages from the specified repository or repositories. | 
|  | 717 |  | 
|  | 718 | .. note:: | 
|  | 719 |  | 
|  | 720 | See the `DNF documentation <https://dnf.readthedocs.io/en/latest/>`__ for | 
|  | 721 | additional information. | 
|  | 722 |  | 
|  | 723 | Using IPK | 
|  | 724 | ~~~~~~~~~ | 
|  | 725 |  | 
|  | 726 | The ``opkg`` application performs runtime package management of IPK | 
|  | 727 | packages. You must perform an initial setup for ``opkg`` on the target | 
|  | 728 | machine if the | 
|  | 729 | :term:`PACKAGE_FEED_ARCHS`, | 
|  | 730 | :term:`PACKAGE_FEED_BASE_PATHS`, | 
|  | 731 | and | 
|  | 732 | :term:`PACKAGE_FEED_URIS` | 
|  | 733 | variables have not been set or the target image was built before the | 
|  | 734 | variables were set. | 
|  | 735 |  | 
|  | 736 | The ``opkg`` application uses configuration files to find available | 
|  | 737 | package databases. Thus, you need to create a configuration file inside | 
|  | 738 | the ``/etc/opkg/`` directory, which informs ``opkg`` of any repository | 
|  | 739 | you want to use. | 
|  | 740 |  | 
|  | 741 | As an example, suppose you are serving packages from a ``ipk/`` | 
|  | 742 | directory containing the ``i586``, ``all``, and ``qemux86`` databases | 
|  | 743 | through an HTTP server named ``my.server``. On the target, create a | 
|  | 744 | configuration file (e.g. ``my_repo.conf``) inside the ``/etc/opkg/`` | 
|  | 745 | directory containing the following: | 
|  | 746 |  | 
|  | 747 | .. code-block:: none | 
|  | 748 |  | 
|  | 749 | src/gz all http://my.server/ipk/all | 
|  | 750 | src/gz i586 http://my.server/ipk/i586 | 
|  | 751 | src/gz qemux86 http://my.server/ipk/qemux86 | 
|  | 752 |  | 
|  | 753 | Next, instruct ``opkg`` to fetch the | 
|  | 754 | repository information: | 
|  | 755 |  | 
|  | 756 | .. code-block:: none | 
|  | 757 |  | 
|  | 758 | # opkg update | 
|  | 759 |  | 
|  | 760 | The ``opkg`` application is now able to find, install, and upgrade packages | 
|  | 761 | from the specified repository. | 
|  | 762 |  | 
|  | 763 | Using DEB | 
|  | 764 | ~~~~~~~~~ | 
|  | 765 |  | 
|  | 766 | The ``apt`` application performs runtime package management of DEB | 
|  | 767 | packages. This application uses a source list file to find available | 
|  | 768 | package databases. You must perform an initial setup for ``apt`` on the | 
|  | 769 | target machine if the | 
|  | 770 | :term:`PACKAGE_FEED_ARCHS`, | 
|  | 771 | :term:`PACKAGE_FEED_BASE_PATHS`, | 
|  | 772 | and | 
|  | 773 | :term:`PACKAGE_FEED_URIS` | 
|  | 774 | variables have not been set or the target image was built before the | 
|  | 775 | variables were set. | 
|  | 776 |  | 
|  | 777 | To inform ``apt`` of the repository you want to use, you might create a | 
|  | 778 | list file (e.g. ``my_repo.list``) inside the | 
|  | 779 | ``/etc/apt/sources.list.d/`` directory. As an example, suppose you are | 
|  | 780 | serving packages from a ``deb/`` directory containing the ``i586``, | 
|  | 781 | ``all``, and ``qemux86`` databases through an HTTP server named | 
|  | 782 | ``my.server``. The list file should contain: | 
|  | 783 |  | 
|  | 784 | .. code-block:: none | 
|  | 785 |  | 
|  | 786 | deb http://my.server/deb/all ./ | 
|  | 787 | deb http://my.server/deb/i586 ./ | 
|  | 788 | deb http://my.server/deb/qemux86 ./ | 
|  | 789 |  | 
|  | 790 | Next, instruct the ``apt`` application | 
|  | 791 | to fetch the repository information: | 
|  | 792 |  | 
|  | 793 | .. code-block:: none | 
|  | 794 |  | 
|  | 795 | $ sudo apt update | 
|  | 796 |  | 
|  | 797 | After this step, | 
|  | 798 | ``apt`` is able to find, install, and upgrade packages from the | 
|  | 799 | specified repository. | 
|  | 800 |  | 
|  | 801 | Generating and Using Signed Packages | 
|  | 802 | ==================================== | 
|  | 803 |  | 
|  | 804 | In order to add security to RPM packages used during a build, you can | 
|  | 805 | take steps to securely sign them. Once a signature is verified, the | 
|  | 806 | OpenEmbedded build system can use the package in the build. If security | 
|  | 807 | fails for a signed package, the build system stops the build. | 
|  | 808 |  | 
|  | 809 | This section describes how to sign RPM packages during a build and how | 
|  | 810 | to use signed package feeds (repositories) when doing a build. | 
|  | 811 |  | 
|  | 812 | Signing RPM Packages | 
|  | 813 | -------------------- | 
|  | 814 |  | 
|  | 815 | To enable signing RPM packages, you must set up the following | 
|  | 816 | configurations in either your ``local.config`` or ``distro.config`` | 
|  | 817 | file:: | 
|  | 818 |  | 
|  | 819 | # Inherit sign_rpm.bbclass to enable signing functionality | 
|  | 820 | INHERIT += " sign_rpm" | 
|  | 821 | # Define the GPG key that will be used for signing. | 
|  | 822 | RPM_GPG_NAME = "key_name" | 
|  | 823 | # Provide passphrase for the key | 
|  | 824 | RPM_GPG_PASSPHRASE = "passphrase" | 
|  | 825 |  | 
|  | 826 | .. note:: | 
|  | 827 |  | 
|  | 828 | Be sure to supply appropriate values for both `key_name` and | 
|  | 829 | `passphrase`. | 
|  | 830 |  | 
|  | 831 | Aside from the ``RPM_GPG_NAME`` and ``RPM_GPG_PASSPHRASE`` variables in | 
|  | 832 | the previous example, two optional variables related to signing are available: | 
|  | 833 |  | 
|  | 834 | -  *GPG_BIN:* Specifies a ``gpg`` binary/wrapper that is executed | 
|  | 835 | when the package is signed. | 
|  | 836 |  | 
|  | 837 | -  *GPG_PATH:* Specifies the ``gpg`` home directory used when the | 
|  | 838 | package is signed. | 
|  | 839 |  | 
|  | 840 | Processing Package Feeds | 
|  | 841 | ------------------------ | 
|  | 842 |  | 
|  | 843 | In addition to being able to sign RPM packages, you can also enable | 
|  | 844 | signed package feeds for IPK and RPM packages. | 
|  | 845 |  | 
|  | 846 | The steps you need to take to enable signed package feed use are similar | 
|  | 847 | to the steps used to sign RPM packages. You must define the following in | 
|  | 848 | your ``local.config`` or ``distro.config`` file:: | 
|  | 849 |  | 
|  | 850 | INHERIT += "sign_package_feed" | 
|  | 851 | PACKAGE_FEED_GPG_NAME = "key_name" | 
|  | 852 | PACKAGE_FEED_GPG_PASSPHRASE_FILE = "path_to_file_containing_passphrase" | 
|  | 853 |  | 
|  | 854 | For signed package feeds, the passphrase must be specified in a separate file, | 
|  | 855 | which is pointed to by the ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` | 
|  | 856 | variable. Regarding security, keeping a plain text passphrase out of the | 
|  | 857 | configuration is more secure. | 
|  | 858 |  | 
|  | 859 | Aside from the ``PACKAGE_FEED_GPG_NAME`` and | 
|  | 860 | ``PACKAGE_FEED_GPG_PASSPHRASE_FILE`` variables, three optional variables | 
|  | 861 | related to signed package feeds are available: | 
|  | 862 |  | 
|  | 863 | -  *GPG_BIN* Specifies a ``gpg`` binary/wrapper that is executed | 
|  | 864 | when the package is signed. | 
|  | 865 |  | 
|  | 866 | -  *GPG_PATH:* Specifies the ``gpg`` home directory used when the | 
|  | 867 | package is signed. | 
|  | 868 |  | 
|  | 869 | -  *PACKAGE_FEED_GPG_SIGNATURE_TYPE:* Specifies the type of ``gpg`` | 
|  | 870 | signature. This variable applies only to RPM and IPK package feeds. | 
|  | 871 | Allowable values for the ``PACKAGE_FEED_GPG_SIGNATURE_TYPE`` are | 
|  | 872 | "ASC", which is the default and specifies ascii armored, and "BIN", | 
|  | 873 | which specifies binary. | 
|  | 874 |  | 
|  | 875 | Testing Packages With ptest | 
|  | 876 | =========================== | 
|  | 877 |  | 
|  | 878 | A Package Test (ptest) runs tests against packages built by the | 
|  | 879 | OpenEmbedded build system on the target machine. A ptest contains at | 
|  | 880 | least two items: the actual test, and a shell script (``run-ptest``) | 
|  | 881 | that starts the test. The shell script that starts the test must not | 
|  | 882 | contain the actual test --- the script only starts the test. On the other | 
|  | 883 | hand, the test can be anything from a simple shell script that runs a | 
|  | 884 | binary and checks the output to an elaborate system of test binaries and | 
|  | 885 | data files. | 
|  | 886 |  | 
|  | 887 | The test generates output in the format used by Automake:: | 
|  | 888 |  | 
|  | 889 | result: testname | 
|  | 890 |  | 
|  | 891 | where the result can be ``PASS``, ``FAIL``, or ``SKIP``, and | 
|  | 892 | the testname can be any identifying string. | 
|  | 893 |  | 
|  | 894 | For a list of Yocto Project recipes that are already enabled with ptest, | 
|  | 895 | see the :yocto_wiki:`Ptest </Ptest>` wiki page. | 
|  | 896 |  | 
|  | 897 | .. note:: | 
|  | 898 |  | 
|  | 899 | A recipe is "ptest-enabled" if it inherits the :ref:`ref-classes-ptest` | 
|  | 900 | class. | 
|  | 901 |  | 
|  | 902 | Adding ptest to Your Build | 
|  | 903 | -------------------------- | 
|  | 904 |  | 
|  | 905 | To add package testing to your build, add the :term:`DISTRO_FEATURES` and | 
|  | 906 | :term:`EXTRA_IMAGE_FEATURES` variables to your ``local.conf`` file, which | 
|  | 907 | is found in the :term:`Build Directory`:: | 
|  | 908 |  | 
|  | 909 | DISTRO_FEATURES:append = " ptest" | 
|  | 910 | EXTRA_IMAGE_FEATURES += "ptest-pkgs" | 
|  | 911 |  | 
|  | 912 | Once your build is complete, the ptest files are installed into the | 
|  | 913 | ``/usr/lib/package/ptest`` directory within the image, where ``package`` | 
|  | 914 | is the name of the package. | 
|  | 915 |  | 
|  | 916 | Running ptest | 
|  | 917 | ------------- | 
|  | 918 |  | 
|  | 919 | The ``ptest-runner`` package installs a shell script that loops through | 
|  | 920 | all installed ptest test suites and runs them in sequence. Consequently, | 
|  | 921 | you might want to add this package to your image. | 
|  | 922 |  | 
|  | 923 | Getting Your Package Ready | 
|  | 924 | -------------------------- | 
|  | 925 |  | 
|  | 926 | In order to enable a recipe to run installed ptests on target hardware, | 
|  | 927 | you need to prepare the recipes that build the packages you want to | 
|  | 928 | test. Here is what you have to do for each recipe: | 
|  | 929 |  | 
|  | 930 | -  *Be sure the recipe inherits the* :ref:`ref-classes-ptest` *class:* | 
|  | 931 | Include the following line in each recipe:: | 
|  | 932 |  | 
|  | 933 | inherit ptest | 
|  | 934 |  | 
|  | 935 | -  *Create run-ptest:* This script starts your test. Locate the | 
|  | 936 | script where you will refer to it using | 
|  | 937 | :term:`SRC_URI`. Here is an | 
|  | 938 | example that starts a test for ``dbus``:: | 
|  | 939 |  | 
|  | 940 | #!/bin/sh | 
|  | 941 | cd test | 
|  | 942 | make -k runtest-TESTS | 
|  | 943 |  | 
|  | 944 | -  *Ensure dependencies are met:* If the test adds build or runtime | 
|  | 945 | dependencies that normally do not exist for the package (such as | 
|  | 946 | requiring "make" to run the test suite), use the | 
|  | 947 | :term:`DEPENDS` and | 
|  | 948 | :term:`RDEPENDS` variables in | 
|  | 949 | your recipe in order for the package to meet the dependencies. Here | 
|  | 950 | is an example where the package has a runtime dependency on "make":: | 
|  | 951 |  | 
|  | 952 | RDEPENDS:${PN}-ptest += "make" | 
|  | 953 |  | 
|  | 954 | -  *Add a function to build the test suite:* Not many packages support | 
|  | 955 | cross-compilation of their test suites. Consequently, you usually | 
|  | 956 | need to add a cross-compilation function to the package. | 
|  | 957 |  | 
|  | 958 | Many packages based on Automake compile and run the test suite by | 
|  | 959 | using a single command such as ``make check``. However, the host | 
|  | 960 | ``make check`` builds and runs on the same computer, while | 
|  | 961 | cross-compiling requires that the package is built on the host but | 
|  | 962 | executed for the target architecture (though often, as in the case | 
|  | 963 | for ptest, the execution occurs on the host). The built version of | 
|  | 964 | Automake that ships with the Yocto Project includes a patch that | 
|  | 965 | separates building and execution. Consequently, packages that use the | 
|  | 966 | unaltered, patched version of ``make check`` automatically | 
|  | 967 | cross-compiles. | 
|  | 968 |  | 
|  | 969 | Regardless, you still must add a ``do_compile_ptest`` function to | 
|  | 970 | build the test suite. Add a function similar to the following to your | 
|  | 971 | recipe:: | 
|  | 972 |  | 
|  | 973 | do_compile_ptest() { | 
|  | 974 | oe_runmake buildtest-TESTS | 
|  | 975 | } | 
|  | 976 |  | 
|  | 977 | -  *Ensure special configurations are set:* If the package requires | 
|  | 978 | special configurations prior to compiling the test code, you must | 
|  | 979 | insert a ``do_configure_ptest`` function into the recipe. | 
|  | 980 |  | 
|  | 981 | -  *Install the test suite:* The :ref:`ref-classes-ptest` class | 
|  | 982 | automatically copies the file ``run-ptest`` to the target and then runs make | 
|  | 983 | ``install-ptest`` to run the tests. If this is not enough, you need | 
|  | 984 | to create a ``do_install_ptest`` function and make sure it gets | 
|  | 985 | called after the "make install-ptest" completes. | 
|  | 986 |  | 
|  | 987 | Creating Node Package Manager (NPM) Packages | 
|  | 988 | ============================================ | 
|  | 989 |  | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 990 | :wikipedia:`NPM <Npm_(software)>` is a package manager for the JavaScript | 
|  | 991 | programming language. The Yocto Project supports the NPM | 
|  | 992 | :ref:`fetcher <bitbake-user-manual/bitbake-user-manual-fetching:fetchers>`. | 
|  | 993 | You can use this fetcher in combination with | 
|  | 994 | :doc:`devtool </ref-manual/devtool-reference>` to create recipes that produce | 
|  | 995 | NPM packages. | 
| Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 996 |  | 
|  | 997 | There are two workflows that allow you to create NPM packages using | 
|  | 998 | ``devtool``: the NPM registry modules method and the NPM project code | 
|  | 999 | method. | 
|  | 1000 |  | 
|  | 1001 | .. note:: | 
|  | 1002 |  | 
|  | 1003 | While it is possible to create NPM recipes manually, using | 
|  | 1004 | ``devtool`` is far simpler. | 
|  | 1005 |  | 
|  | 1006 | Additionally, some requirements and caveats exist. | 
|  | 1007 |  | 
|  | 1008 | Requirements and Caveats | 
|  | 1009 | ------------------------ | 
|  | 1010 |  | 
|  | 1011 | You need to be aware of the following before using ``devtool`` to create | 
|  | 1012 | NPM packages: | 
|  | 1013 |  | 
|  | 1014 | -  Of the two methods that you can use ``devtool`` to create NPM | 
|  | 1015 | packages, the registry approach is slightly simpler. However, you | 
|  | 1016 | might consider the project approach because you do not have to | 
|  | 1017 | publish your module in the `NPM registry <https://docs.npmjs.com/misc/registry>`__, | 
|  | 1018 | which is NPM's public registry. | 
|  | 1019 |  | 
|  | 1020 | -  Be familiar with | 
|  | 1021 | :doc:`devtool </ref-manual/devtool-reference>`. | 
|  | 1022 |  | 
|  | 1023 | -  The NPM host tools need the native ``nodejs-npm`` package, which is | 
|  | 1024 | part of the OpenEmbedded environment. You need to get the package by | 
|  | 1025 | cloning the :oe_git:`meta-openembedded </meta-openembedded>` | 
|  | 1026 | repository. Be sure to add the path to your local copy | 
|  | 1027 | to your ``bblayers.conf`` file. | 
|  | 1028 |  | 
|  | 1029 | -  ``devtool`` cannot detect native libraries in module dependencies. | 
|  | 1030 | Consequently, you must manually add packages to your recipe. | 
|  | 1031 |  | 
|  | 1032 | -  While deploying NPM packages, ``devtool`` cannot determine which | 
|  | 1033 | dependent packages are missing on the target (e.g. the node runtime | 
|  | 1034 | ``nodejs``). Consequently, you need to find out what files are | 
|  | 1035 | missing and be sure they are on the target. | 
|  | 1036 |  | 
|  | 1037 | -  Although you might not need NPM to run your node package, it is | 
|  | 1038 | useful to have NPM on your target. The NPM package name is | 
|  | 1039 | ``nodejs-npm``. | 
|  | 1040 |  | 
|  | 1041 | Using the Registry Modules Method | 
|  | 1042 | --------------------------------- | 
|  | 1043 |  | 
|  | 1044 | This section presents an example that uses the ``cute-files`` module, | 
|  | 1045 | which is a file browser web application. | 
|  | 1046 |  | 
|  | 1047 | .. note:: | 
|  | 1048 |  | 
|  | 1049 | You must know the ``cute-files`` module version. | 
|  | 1050 |  | 
|  | 1051 | The first thing you need to do is use ``devtool`` and the NPM fetcher to | 
|  | 1052 | create the recipe:: | 
|  | 1053 |  | 
|  | 1054 | $ devtool add "npm://registry.npmjs.org;package=cute-files;version=1.0.2" | 
|  | 1055 |  | 
|  | 1056 | The | 
|  | 1057 | ``devtool add`` command runs ``recipetool create`` and uses the same | 
|  | 1058 | fetch URI to download each dependency and capture license details where | 
|  | 1059 | possible. The result is a generated recipe. | 
|  | 1060 |  | 
|  | 1061 | After running for quite a long time, in particular building the | 
|  | 1062 | ``nodejs-native`` package, the command should end as follows:: | 
|  | 1063 |  | 
|  | 1064 | INFO: Recipe /home/.../build/workspace/recipes/cute-files/cute-files_1.0.2.bb has been automatically created; further editing may be required to make it fully functional | 
|  | 1065 |  | 
|  | 1066 | The recipe file is fairly simple and contains every license that | 
|  | 1067 | ``recipetool`` finds and includes the licenses in the recipe's | 
|  | 1068 | :term:`LIC_FILES_CHKSUM` | 
|  | 1069 | variables. You need to examine the variables and look for those with | 
|  | 1070 | "unknown" in the :term:`LICENSE` | 
|  | 1071 | field. You need to track down the license information for "unknown" | 
|  | 1072 | modules and manually add the information to the recipe. | 
|  | 1073 |  | 
|  | 1074 | ``recipetool`` creates a "shrinkwrap" file for your recipe. Shrinkwrap | 
|  | 1075 | files capture the version of all dependent modules. Many packages do not | 
|  | 1076 | provide shrinkwrap files but ``recipetool`` will create a shrinkwrap file as it | 
|  | 1077 | runs. | 
|  | 1078 |  | 
|  | 1079 | .. note:: | 
|  | 1080 |  | 
|  | 1081 | A package is created for each sub-module. This policy is the only | 
|  | 1082 | practical way to have the licenses for all of the dependencies | 
|  | 1083 | represented in the license manifest of the image. | 
|  | 1084 |  | 
|  | 1085 | The ``devtool edit-recipe`` command lets you take a look at the recipe:: | 
|  | 1086 |  | 
|  | 1087 | $ devtool edit-recipe cute-files | 
|  | 1088 | # Recipe created by recipetool | 
|  | 1089 | # This is the basis of a recipe and may need further editing in order to be fully functional. | 
|  | 1090 | # (Feel free to remove these comments when editing.) | 
|  | 1091 |  | 
|  | 1092 | SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." | 
|  | 1093 | # WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is | 
|  | 1094 | # your responsibility to verify that the values are complete and correct. | 
|  | 1095 | # | 
|  | 1096 | # NOTE: multiple licenses have been detected; they have been separated with & | 
|  | 1097 | # in the LICENSE value for now since it is a reasonable assumption that all | 
|  | 1098 | # of the licenses apply. If instead there is a choice between the multiple | 
|  | 1099 | # licenses then you should change the value to separate the licenses with | | 
|  | 1100 | # instead of &. If there is any doubt, check the accompanying documentation | 
|  | 1101 | # to determine which situation is applicable. | 
|  | 1102 |  | 
|  | 1103 | SUMMARY = "Turn any folder on your computer into a cute file browser, available on the local network." | 
|  | 1104 | LICENSE = "BSD-3-Clause & ISC & MIT" | 
|  | 1105 | LIC_FILES_CHKSUM = "file://LICENSE;md5=71d98c0a1db42956787b1909c74a86ca \ | 
|  | 1106 | file://node_modules/accepts/LICENSE;md5=bf1f9ad1e2e1d507aef4883fff7103de \ | 
|  | 1107 | file://node_modules/array-flatten/LICENSE;md5=44088ba57cb871a58add36ce51b8de08 \ | 
|  | 1108 | ... | 
|  | 1109 | file://node_modules/cookie-signature/Readme.md;md5=57ae8b42de3dd0c1f22d5f4cf191e15a" | 
|  | 1110 |  | 
|  | 1111 | SRC_URI = " \ | 
|  | 1112 | npm://registry.npmjs.org/;package=cute-files;version=${PV} \ | 
|  | 1113 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ | 
|  | 1114 | " | 
|  | 1115 |  | 
|  | 1116 | S = "${WORKDIR}/npm" | 
|  | 1117 |  | 
|  | 1118 | inherit npm | 
|  | 1119 |  | 
|  | 1120 | LICENSE:${PN} = "MIT" | 
|  | 1121 | LICENSE:${PN}-accepts = "MIT" | 
|  | 1122 | LICENSE:${PN}-array-flatten = "MIT" | 
|  | 1123 | ... | 
|  | 1124 | LICENSE:${PN}-vary = "MIT" | 
|  | 1125 |  | 
|  | 1126 | Here are three key points in the previous example: | 
|  | 1127 |  | 
|  | 1128 | -  :term:`SRC_URI` uses the NPM | 
|  | 1129 | scheme so that the NPM fetcher is used. | 
|  | 1130 |  | 
|  | 1131 | -  ``recipetool`` collects all the license information. If a | 
|  | 1132 | sub-module's license is unavailable, the sub-module's name appears in | 
|  | 1133 | the comments. | 
|  | 1134 |  | 
|  | 1135 | -  The ``inherit npm`` statement causes the :ref:`ref-classes-npm` class to | 
|  | 1136 | package up all the modules. | 
|  | 1137 |  | 
|  | 1138 | You can run the following command to build the ``cute-files`` package:: | 
|  | 1139 |  | 
|  | 1140 | $ devtool build cute-files | 
|  | 1141 |  | 
|  | 1142 | Remember that ``nodejs`` must be installed on | 
|  | 1143 | the target before your package. | 
|  | 1144 |  | 
|  | 1145 | Assuming 192.168.7.2 for the target's IP address, use the following | 
|  | 1146 | command to deploy your package:: | 
|  | 1147 |  | 
|  | 1148 | $ devtool deploy-target -s cute-files root@192.168.7.2 | 
|  | 1149 |  | 
|  | 1150 | Once the package is installed on the target, you can | 
|  | 1151 | test the application to show the contents of any directory:: | 
|  | 1152 |  | 
|  | 1153 | $ cd /usr/lib/node_modules/cute-files | 
|  | 1154 | $ cute-files | 
|  | 1155 |  | 
|  | 1156 | On a browser, | 
|  | 1157 | go to ``http://192.168.7.2:3000`` and you see the following: | 
|  | 1158 |  | 
|  | 1159 | .. image:: figures/cute-files-npm-example.png | 
|  | 1160 | :width: 100% | 
|  | 1161 |  | 
|  | 1162 | You can find the recipe in ``workspace/recipes/cute-files``. You can use | 
|  | 1163 | the recipe in any layer you choose. | 
|  | 1164 |  | 
|  | 1165 | Using the NPM Projects Code Method | 
|  | 1166 | ---------------------------------- | 
|  | 1167 |  | 
|  | 1168 | Although it is useful to package modules already in the NPM registry, | 
|  | 1169 | adding ``node.js`` projects under development is a more common developer | 
|  | 1170 | use case. | 
|  | 1171 |  | 
|  | 1172 | This section covers the NPM projects code method, which is very similar | 
|  | 1173 | to the "registry" approach described in the previous section. In the NPM | 
|  | 1174 | projects method, you provide ``devtool`` with an URL that points to the | 
|  | 1175 | source files. | 
|  | 1176 |  | 
|  | 1177 | Replicating the same example, (i.e. ``cute-files``) use the following | 
|  | 1178 | command:: | 
|  | 1179 |  | 
|  | 1180 | $ devtool add https://github.com/martinaglv/cute-files.git | 
|  | 1181 |  | 
|  | 1182 | The recipe this command generates is very similar to the recipe created in | 
|  | 1183 | the previous section. However, the :term:`SRC_URI` looks like the following:: | 
|  | 1184 |  | 
|  | 1185 | SRC_URI = " \ | 
|  | 1186 | git://github.com/martinaglv/cute-files.git;protocol=https;branch=master \ | 
|  | 1187 | npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json \ | 
|  | 1188 | " | 
|  | 1189 |  | 
|  | 1190 | In this example, | 
|  | 1191 | the main module is taken from the Git repository and dependencies are | 
|  | 1192 | taken from the NPM registry. Other than those differences, the recipe is | 
|  | 1193 | basically the same between the two methods. You can build and deploy the | 
|  | 1194 | package exactly as described in the previous section that uses the | 
|  | 1195 | registry modules method. | 
|  | 1196 |  | 
|  | 1197 | Adding custom metadata to packages | 
|  | 1198 | ================================== | 
|  | 1199 |  | 
|  | 1200 | The variable | 
|  | 1201 | :term:`PACKAGE_ADD_METADATA` | 
|  | 1202 | can be used to add additional metadata to packages. This is reflected in | 
|  | 1203 | the package control/spec file. To take the ipk format for example, the | 
|  | 1204 | CONTROL file stored inside would contain the additional metadata as | 
|  | 1205 | additional lines. | 
|  | 1206 |  | 
|  | 1207 | The variable can be used in multiple ways, including using suffixes to | 
|  | 1208 | set it for a specific package type and/or package. Note that the order | 
|  | 1209 | of precedence is the same as this list: | 
|  | 1210 |  | 
|  | 1211 | -  ``PACKAGE_ADD_METADATA_<PKGTYPE>:<PN>`` | 
|  | 1212 |  | 
|  | 1213 | -  ``PACKAGE_ADD_METADATA_<PKGTYPE>`` | 
|  | 1214 |  | 
|  | 1215 | -  ``PACKAGE_ADD_METADATA:<PN>`` | 
|  | 1216 |  | 
|  | 1217 | -  :term:`PACKAGE_ADD_METADATA` | 
|  | 1218 |  | 
|  | 1219 | `<PKGTYPE>` is a parameter and expected to be a distinct name of specific | 
|  | 1220 | package type: | 
|  | 1221 |  | 
|  | 1222 | -  IPK for .ipk packages | 
|  | 1223 |  | 
|  | 1224 | -  DEB for .deb packages | 
|  | 1225 |  | 
|  | 1226 | -  RPM for .rpm packages | 
|  | 1227 |  | 
|  | 1228 | `<PN>` is a parameter and expected to be a package name. | 
|  | 1229 |  | 
|  | 1230 | The variable can contain multiple [one-line] metadata fields separated | 
|  | 1231 | by the literal sequence '\\n'. The separator can be redefined using the | 
|  | 1232 | variable flag ``separator``. | 
|  | 1233 |  | 
|  | 1234 | Here is an example that adds two custom fields for ipk | 
|  | 1235 | packages:: | 
|  | 1236 |  | 
|  | 1237 | PACKAGE_ADD_METADATA_IPK = "Vendor: CustomIpk\nGroup:Applications/Spreadsheets" | 
|  | 1238 |  |