packages.rst 44 KB

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