devtool.rst 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. .. SPDX-License-Identifier: CC-BY-SA-2.0-UK
  2. Using the ``devtool`` command-line tool
  3. ***************************************
  4. The ``devtool`` command-line tool provides a number of features that
  5. help you build, test, and package software. This command is available
  6. alongside the ``bitbake`` command. Additionally, the ``devtool`` command
  7. is a key part of the :term:`Extensible Software Development Kit (eSDK)`.
  8. Use ``devtool add`` to Add an Application
  9. =========================================
  10. The ``devtool add`` command generates a new recipe based on existing
  11. source code. This command takes advantage of the
  12. :ref:`devtool-the-workspace-layer-structure`
  13. layer that many ``devtool`` commands use. The command is flexible enough
  14. to allow you to extract source code into both the workspace or a
  15. separate local Git repository and to use existing code that does not
  16. need to be extracted.
  17. Depending on your particular scenario, the arguments and options you use
  18. with ``devtool add`` form different combinations. The following diagram
  19. shows common development flows you would use with the ``devtool add``
  20. command:
  21. .. image:: figures/devtool-add-flow.png
  22. :width: 100%
  23. #. *Generating the New Recipe*: The top part of the flow shows three
  24. scenarios by which you could use ``devtool add`` to generate a recipe
  25. based on existing source code.
  26. In a shared development environment, it is typical for other
  27. developers to be responsible for various areas of source code. As a
  28. developer, you are probably interested in using that source code as
  29. part of your development within the Yocto Project. All you need is
  30. access to the code, a recipe, and a controlled area in which to do
  31. your work.
  32. Within the diagram, three possible scenarios feed into the
  33. ``devtool add`` workflow:
  34. - *Left*: The left scenario in the figure represents a common
  35. situation where the source code does not exist locally and needs
  36. to be extracted. In this situation, the source code is extracted
  37. to the default workspace --- you do not want the files in some
  38. specific location outside of the workspace. Thus, everything you
  39. need will be located in the workspace::
  40. $ devtool add recipe fetchuri
  41. With this command, ``devtool`` extracts the upstream
  42. source files into a local Git repository within the ``sources``
  43. folder. The command then creates a recipe named recipe and a
  44. corresponding append file in the workspace. If you do not provide
  45. recipe, the command makes an attempt to determine the recipe name.
  46. - *Middle*: The middle scenario in the figure also represents a
  47. situation where the source code does not exist locally. In this
  48. case, the code is again upstream and needs to be extracted to some
  49. local area --- this time outside of the default workspace.
  50. .. note::
  51. If required, ``devtool`` always creates a Git repository locally
  52. during the extraction.
  53. Furthermore, the first positional argument ``srctree`` in this case
  54. identifies where the ``devtool add`` command will locate the
  55. extracted code outside of the workspace. You need to specify an
  56. empty directory::
  57. $ devtool add recipe srctree fetchuri
  58. In summary, the source code is pulled from fetchuri and extracted into the
  59. location defined by ``srctree`` as a local Git repository.
  60. Within workspace, ``devtool`` creates a recipe named recipe along
  61. with an associated append file.
  62. - *Right*: The right scenario in the figure represents a situation
  63. where the ``srctree`` has been previously prepared outside of the
  64. ``devtool`` workspace.
  65. The following command provides a new recipe name and identifies
  66. the existing source tree location::
  67. $ devtool add recipe srctree
  68. The command examines the source code and creates a recipe named
  69. recipe for the code and places the recipe into the workspace.
  70. Because the extracted source code already exists, ``devtool`` does
  71. not try to relocate the source code into the workspace --- only the
  72. new recipe is placed in the workspace.
  73. Aside from a recipe folder, the command also creates an associated
  74. append folder and places an initial ``*.bbappend`` file within.
  75. #. *Edit the Recipe*: You can use ``devtool edit-recipe`` to open up the
  76. editor as defined by the ``$EDITOR`` environment variable and modify
  77. the file::
  78. $ devtool edit-recipe recipe
  79. From within the editor, you can make modifications to the recipe that
  80. take effect when you build it later.
  81. #. *Build the Recipe or Rebuild the Image*: The next step you take
  82. depends on what you are going to do with the new code.
  83. If you need to eventually move the build output to the target
  84. hardware, use the following ``devtool`` command::
  85. $ devtool build recipe
  86. On the other hand, if you want an image to contain the recipe's
  87. packages from the workspace for immediate deployment onto a device
  88. (e.g. for testing purposes), you can use the ``devtool build-image``
  89. command::
  90. $ devtool build-image image
  91. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  92. to build out your recipe, you probably want to see if the resulting
  93. build output works as expected on the target hardware.
  94. .. note::
  95. This step assumes you have a previously built image that is
  96. already either running in QEMU or is running on actual hardware.
  97. Also, it is assumed that for deployment of the image to the
  98. target, SSH is installed in the image and, if the image is running
  99. on real hardware, you have network access to and from your
  100. development machine.
  101. You can deploy your build output to that target hardware by using the
  102. ``devtool deploy-target`` command::
  103. $ devtool deploy-target recipe target
  104. The target is a live target machine running as an SSH server.
  105. You can, of course, also deploy the image you build to actual
  106. hardware by using the ``devtool build-image`` command. However,
  107. ``devtool`` does not provide a specific command that allows you to
  108. deploy the image to actual hardware.
  109. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  110. creates any patches corresponding to commits in the local Git
  111. repository, moves the new recipe to a more permanent layer, and then
  112. resets the recipe so that the recipe is built normally rather than
  113. from the workspace::
  114. $ devtool finish recipe layer
  115. .. note::
  116. Any changes you want to turn into patches must be committed to the
  117. Git repository in the source tree.
  118. As mentioned, the ``devtool finish`` command moves the final recipe
  119. to its permanent layer.
  120. As a final process of the ``devtool finish`` command, the state of
  121. the standard layers and the upstream source is restored so that you
  122. can build the recipe from those areas rather than the workspace.
  123. .. note::
  124. You can use the ``devtool reset`` command to put things back should you
  125. decide you do not want to proceed with your work. If you do use this
  126. command, realize that the source tree is preserved.
  127. Use ``devtool modify`` to Modify the Source of an Existing Component
  128. ====================================================================
  129. The ``devtool modify`` command prepares the way to work on existing code
  130. that already has a local recipe in place that is used to build the
  131. software. The command is flexible enough to allow you to extract code
  132. from an upstream source, specify the existing recipe, and keep track of
  133. and gather any patch files from other developers that are associated
  134. with the code.
  135. Depending on your particular scenario, the arguments and options you use
  136. with ``devtool modify`` form different combinations. The following
  137. diagram shows common development flows for the ``devtool modify``
  138. command:
  139. .. image:: figures/devtool-modify-flow.png
  140. :width: 100%
  141. #. *Preparing to Modify the Code*: The top part of the flow shows three
  142. scenarios by which you could use ``devtool modify`` to prepare to
  143. work on source files. Each scenario assumes the following:
  144. - The recipe exists locally in a layer external to the ``devtool``
  145. workspace.
  146. - The source files exist either upstream in an un-extracted state or
  147. locally in a previously extracted state.
  148. The typical situation is where another developer has created a layer
  149. for use with the Yocto Project and their recipe already resides in
  150. that layer. Furthermore, their source code is readily available
  151. either upstream or locally.
  152. - *Left*: The left scenario in the figure represents a common
  153. situation where the source code does not exist locally and it
  154. needs to be extracted from an upstream source. In this situation,
  155. the source is extracted into the default ``devtool`` workspace
  156. location. The recipe, in this scenario, is in its own layer
  157. outside the workspace (i.e. ``meta-``\ layername).
  158. The following command identifies the recipe and, by default,
  159. extracts the source files::
  160. $ devtool modify recipe
  161. Once ``devtool`` locates the recipe, ``devtool`` uses the recipe's
  162. :term:`SRC_URI` statements to locate the source code and any local
  163. patch files from other developers.
  164. With this scenario, there is no ``srctree`` argument. Consequently, the
  165. default behavior of the ``devtool modify`` command is to extract
  166. the source files pointed to by the :term:`SRC_URI` statements into a
  167. local Git structure. Furthermore, the location for the extracted
  168. source is the default area within the ``devtool`` workspace. The
  169. result is that the command sets up both the source code and an
  170. append file within the workspace while the recipe remains in its
  171. original location.
  172. Additionally, if you have any non-patch local files (i.e. files
  173. referred to with ``file://`` entries in :term:`SRC_URI` statement
  174. excluding ``*.patch/`` or ``*.diff``), these files are copied to
  175. an ``oe-local-files`` folder under the newly created source tree.
  176. Copying the files here gives you a convenient area from which you
  177. can modify the files. Any changes or additions you make to those
  178. files are incorporated into the build the next time you build the
  179. software just as are other changes you might have made to the
  180. source.
  181. - *Middle*: The middle scenario in the figure represents a situation
  182. where the source code also does not exist locally. In this case,
  183. the code is again upstream and needs to be extracted to some local
  184. area as a Git repository. The recipe, in this scenario, is again
  185. local and in its own layer outside the workspace.
  186. The following command tells ``devtool`` the recipe with which to
  187. work and, in this case, identifies a local area for the extracted
  188. source files that exists outside of the default ``devtool``
  189. workspace::
  190. $ devtool modify recipe srctree
  191. .. note::
  192. You cannot provide a URL for ``srctree`` using the ``devtool`` command.
  193. As with all extractions, the command uses the recipe's :term:`SRC_URI`
  194. statements to locate the source files and any associated patch
  195. files. Non-patch files are copied to an ``oe-local-files`` folder
  196. under the newly created source tree.
  197. Once the files are located, the command by default extracts them
  198. into ``srctree``.
  199. Within workspace, ``devtool`` creates an append file for the
  200. recipe. The recipe remains in its original location but the source
  201. files are extracted to the location you provide with ``srctree``.
  202. - *Right*: The right scenario in the figure represents a situation
  203. where the source tree (``srctree``) already exists locally as a
  204. previously extracted Git structure outside of the ``devtool``
  205. workspace. In this example, the recipe also exists elsewhere
  206. locally in its own layer.
  207. The following command tells ``devtool`` the recipe with which to
  208. work, uses the "-n" option to indicate source does not need to be
  209. extracted, and uses ``srctree`` to point to the previously extracted
  210. source files::
  211. $ devtool modify -n recipe srctree
  212. If an ``oe-local-files`` subdirectory happens to exist and it
  213. contains non-patch files, the files are used. However, if the
  214. subdirectory does not exist and you run the ``devtool finish``
  215. command, any non-patch files that might exist next to the recipe
  216. are removed because it appears to ``devtool`` that you have
  217. deleted those files.
  218. Once the ``devtool modify`` command finishes, it creates only an
  219. append file for the recipe in the ``devtool`` workspace. The
  220. recipe and the source code remain in their original locations.
  221. #. *Edit the Source*: Once you have used the ``devtool modify`` command,
  222. you are free to make changes to the source files. You can use any
  223. editor you like to make and save your source code modifications.
  224. #. *Build the Recipe or Rebuild the Image*: The next step you take
  225. depends on what you are going to do with the new code.
  226. If you need to eventually move the build output to the target
  227. hardware, use the following ``devtool`` command::
  228. $ devtool build recipe
  229. On the other hand, if you want an image to contain the recipe's
  230. packages from the workspace for immediate deployment onto a device
  231. (e.g. for testing purposes), you can use the ``devtool build-image``
  232. command::
  233. $ devtool build-image image
  234. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  235. to build out your recipe, you probably want to see if the resulting
  236. build output works as expected on target hardware.
  237. .. note::
  238. This step assumes you have a previously built image that is
  239. already either running in QEMU or running on actual hardware.
  240. Also, it is assumed that for deployment of the image to the
  241. target, SSH is installed in the image and if the image is running
  242. on real hardware that you have network access to and from your
  243. development machine.
  244. You can deploy your build output to that target hardware by using the
  245. ``devtool deploy-target`` command::
  246. $ devtool deploy-target recipe target
  247. The target is a live target machine running as an SSH server.
  248. You can, of course, use other methods to deploy the image you built
  249. using the ``devtool build-image`` command to actual hardware.
  250. ``devtool`` does not provide a specific command to deploy the image
  251. to actual hardware.
  252. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  253. creates any patches corresponding to commits in the local Git
  254. repository, updates the recipe to point to them (or creates a
  255. ``.bbappend`` file to do so, depending on the specified destination
  256. layer), and then resets the recipe so that the recipe is built
  257. normally rather than from the workspace::
  258. $ devtool finish recipe layer
  259. .. note::
  260. Any changes you want to turn into patches must be staged and
  261. committed within the local Git repository before you use the
  262. ``devtool finish`` command.
  263. Because there is no need to move the recipe, ``devtool finish``
  264. either updates the original recipe in the original layer or the
  265. command creates a ``.bbappend`` file in a different layer as provided
  266. by layer. Any work you did in the ``oe-local-files`` directory is
  267. preserved in the original files next to the recipe during the
  268. ``devtool finish`` command.
  269. As a final process of the ``devtool finish`` command, the state of
  270. the standard layers and the upstream source is restored so that you
  271. can build the recipe from those areas rather than from the workspace.
  272. .. note::
  273. You can use the ``devtool reset`` command to put things back should you
  274. decide you do not want to proceed with your work. If you do use this
  275. command, realize that the source tree is preserved.
  276. ``devtool ide-sdk`` configures IDEs and bootstraps SDKs
  277. =======================================================
  278. The ``devtool ide-sdk`` command can provide an IDE configuration for IDEs when
  279. working on the source code of one or more recipes.
  280. Depending on the programming language, and the build system used by the recipe,
  281. the tools required for cross-development and remote debugging are different.
  282. For example:
  283. - A C/C++ project usually uses CMake or Meson.
  284. - A Python project uses setuptools or one of its successors.
  285. - A Rust project uses Cargo.
  286. Also, the IDE plugins needed for the integration of a build system with the
  287. IDE and the corresponding settings are usually specific to these build-systems.
  288. To hide all these details from the user, ``devtool ide-sdk`` does two things:
  289. - It generates any kind of SDK needed for cross-development and remote
  290. debugging of the specified recipes.
  291. - It generates the configuration for the IDE (and the IDE plugins) for using
  292. the cross-toolchain and remote debugging tools provided by the SDK directly
  293. from the IDE.
  294. For supported build systems the configurations generated by ``devtool ide-sdk``
  295. combine the advantages of the ``devtool modify`` based workflow
  296. (see :ref:`using_devtool`) with the advantages of the simple Environment Setup
  297. script based workflow (see :ref:`running_the_ext_sdk_env`) provided by Yocto's
  298. SDK or eSDK:
  299. - The source code of the recipe is in the workspace created by
  300. ``devtool modify`` or ``devtool add``.
  301. Using ``devtool build``, ``devtool build-image``,
  302. ``devtool deploy-target`` or ``bitbake`` is possible.
  303. Also ``devtool ide-sdk`` can be used to update the SDK and the IDE
  304. configuration at any time.
  305. - ``devtool ide-sdk`` aims to support multiple programming languages and
  306. multiple IDEs natively. "Natively" means that the IDE is configured to call
  307. the build tool (e.g. ``cmake`` or ``meson``) directly. This has several
  308. advantages.
  309. First of all, it is usually much faster to call for example ``cmake`` than
  310. ``devtool build``.
  311. It also allows to benefit from the very good integration that IDEs like
  312. VSCode offer for tools like CMake or GDB.
  313. However, supporting many programming languages and multiple
  314. IDEs is quite an elaborate and constantly evolving thing. Support for IDEs
  315. is therefore implemented as plugins. Plugins can also be provided by
  316. optional layers.
  317. So much about the introduction to the default mode of ``devtool sdk-ide`` which
  318. is called the "modified" mode because it uses the workspace created by
  319. ``devtool modify`` and the per recipe :term:`Sysroots <Sysroot>` of BitBake.
  320. For some recipes and use cases, this default behavior of ``devtool ide-sdk``
  321. with full ``devtool`` and ``bitbake`` integration might not be suitable.
  322. To offer full feature parity with the SDK and the eSDK, ``devtool ide-sdk`` has
  323. a second mode called "shared" mode.
  324. If ``devtool ide-sdk`` is called with the ``--mode=shared`` option, it
  325. bootstraps an SDK directly from the BitBake environment, which offers the same
  326. Environment Setup script as described in :ref:`running_the_ext_sdk_env`.
  327. In addition to the (e)SDK installer-based setup, the IDE gets configured
  328. to use the shared :term:`Sysroots <Sysroot>` and the tools from the SDK.
  329. ``devtool ide-sdk --mode=shared`` is basically a wrapper for the setup of the
  330. extensible SDK as described in :ref:`setting_up_ext_sdk_in_build`.
  331. The use of ``devtool ide-sdk`` is an alternative to using one of the SDK
  332. installers.
  333. ``devtool ide-sdk`` allows the creation of SDKs that offer all the
  334. functionality of the SDK and the eSDK installers. Compared to the installers,
  335. however, the SDK created with ``devtool ide-sdk`` is much more flexible.
  336. For example, it is very easy to change the :term:`MACHINE` in the
  337. ``local.conf`` file, update the layer meta data and then regenerate the SDK.
  338. Let's take a look at an example of how to use ``devtool ide-sdk`` in each of
  339. the two modes:
  340. #. *Modified mode*:
  341. In order to use the ``devtool ide-sdk``, a few settings are needed. As a
  342. starting example, the following lines of code can be added to the
  343. ``local.conf`` file::
  344. # Build the companion debug file system
  345. IMAGE_GEN_DEBUGFS = "1"
  346. # Optimize build time: with devtool ide-sdk the dbg tar is not needed
  347. IMAGE_FSTYPES_DEBUGFS = ""
  348. # Without copying the binaries into roofs-dbg, GDB does not find all source files.
  349. IMAGE_CLASSES += "image-combined-dbg"
  350. # SSH is mandatory, no password simplifies the usage
  351. EXTRA_IMAGE_FEATURES += "\
  352. ssh-server-openssh \
  353. allow-empty-password \
  354. allow-root-login \
  355. empty-root-password \
  356. "
  357. # Remote debugging needs gdbserver on the target device
  358. IMAGE_INSTALL:append = " gdbserver"
  359. # Add the recipes which should be modified to the image
  360. # Otherwise some dependencies might be missing.
  361. IMAGE_INSTALL:append = " my-recipe"
  362. Assuming the BitBake environment is set up correctly and a workspace has
  363. been created for the recipe using ``devtool modify my-recipe`` or probably
  364. even better by using ``devtool modify my-recipe --debug-build``, the
  365. following command can create the SDK and the configuration for VSCode in
  366. the recipe workspace::
  367. $ devtool ide-sdk my-recipe core-image-minimal --target root@192.168.7.2
  368. The command requires an image recipe (``core-image-minimal`` for this
  369. example) that is used to create the SDK.
  370. This firmware image should also be installed on the target device.
  371. It is possible to pass multiple package recipes::
  372. $ devtool ide-sdk my-recipe-1 my-recipe-2 core-image-minimal --target root@192.168.7.2
  373. ``devtool ide-sdk`` tries to create an IDE configuration for all package
  374. recipes.
  375. What this command does exactly depends on the recipe, more precisely on the
  376. build tool used by the recipe. The basic idea is to configure the IDE so
  377. that it calls the build tool exactly as ``bitbake`` does.
  378. For example, a CMake preset is created for a recipe that inherits
  379. :ref:`ref-classes-cmake`. In the case of VSCode, CMake presets are supported
  380. by the CMake Tools plugin. This is an example of how the build configuration
  381. used by ``bitbake`` is exported to an IDE configuration that gives exactly
  382. the same build results.
  383. Support for remote debugging with seamless integration into the IDE is
  384. important for a cross-SDK. ``devtool ide-sdk`` automatically generates the
  385. necessary helper scripts for deploying the compiled artifacts to the target
  386. device as well as the necessary configuration for the debugger and the IDE.
  387. .. note::
  388. To ensure that the debug symbols on the build machine match the binaries
  389. running on the target device, it is essential that the image built by
  390. ``devtool ide-sdk`` is running on the target device.
  391. The default IDE is VSCode. Some hints about using VSCode:
  392. - VSCode can be used to work on the BitBake recipes or the application
  393. source code.
  394. Usually there is one instance of VSCode running in the folder where the
  395. BitBake recipes are. This instance has the
  396. `Yocto Project BitBake plugin <https://marketplace.visualstudio.com/items?itemName=yocto-project.yocto-bitbake>`_
  397. running.
  398. .. warning::
  399. Some VSCode plugins (Python, BitBake and others) need a reasonable
  400. configuration to work as expected. Otherwise, some plugins try to
  401. index the build directory of BitBake, which keeps your system quite
  402. busy until an out of memory exception stops this nonsense.
  403. Other plugins, such as the BitBake plugin, do not behave as expected.
  404. To work around such issues, the ``oe-init-build-env`` script creates
  405. an initial ``.vscode/settings.json`` file if ``code`` can be found
  406. and the ``.vscode`` folder does not yet exist.
  407. It is best to run ``oe-init-build-env`` once before starting VSCode.
  408. An alternative approach is to use a build folder outside the layers,
  409. e.g. ``oe-init-build-env ../build``.
  410. The BitBake plugin also offers to create devtool workspaces and run
  411. ``devtool ide-sdk`` with a few mouse clicks.
  412. Of course, issuing commands in the terminal works as well.
  413. - To work on the source code of a recipe another instance of VSCode is
  414. started in the recipe's workspace. Example::
  415. code build/workspace/sources/my-recipe
  416. This instance of VSCode uses plugins that are useful for the development
  417. of the application. ``devtool ide-sdk`` generates the necessary
  418. ``extensions.json``, ``settings.json``, ``tasks.json``and ``launch.json``
  419. configuration files for all the involved plugins.
  420. When the source code folder present in the workspace folder is opened in
  421. VSCode for the first time, a pop-up message recommends installing the
  422. required plugins.
  423. After accepting the installation of the plugins, working with the source
  424. code or some debugging tasks should work as usual with VSCode.
  425. Starting the VSCode instances in the recipe workspace folders can also be
  426. done by a mouse click on the recipe workspaces in the first VSCode
  427. instance.
  428. - To work with CMake press ``Ctrl + Shift + p``, type ``cmake``. This will
  429. show some possible commands like selecting a CMake preset, compiling or
  430. running CTest.
  431. For recipes inheriting :ref:`ref-classes-cmake-qemu` rather than
  432. :ref:`ref-classes-cmake`, executing cross-compiled unit tests on the host
  433. can be supported transparently with QEMU user-mode.
  434. - To work with Meson press ``Ctrl + Shift + p``, type ``meson``. This will
  435. show some possible commands like compiling or executing the unit tests.
  436. A note on running cross-compiled unit tests on the host: Meson enables
  437. support for QEMU user mode by default. It is expected that the execution
  438. of the unit tests from the IDE will work without any additional steps,
  439. given that the code is suitable for the execution on the host machine.
  440. - For the deployment to the target device, just press ``Ctrl + Shift + p``,
  441. type ``task``. Select ``install && deploy-target``.
  442. - For remote debugging, switch to the debugging view by pressing the "play"
  443. button with the ``bug icon`` on the left side. This will provide a green
  444. play button with a drop-down list where a debug configuration can be
  445. selected. After selecting one of the generated configurations, press the
  446. "play" button.
  447. Starting a remote debugging session automatically initiates the
  448. deployment to the target device. If this is not desired, the
  449. ``"dependsOn": ["install && deploy-target...]`` parameter of the tasks
  450. with ``"label": "gdbserver start...`` can be removed from the
  451. ``tasks.json`` file.
  452. VSCode supports GDB with many different setups and configurations for
  453. many different use cases. However, most of these setups have some
  454. limitations when it comes to cross-development, support only a few target
  455. architectures or require a high performance target device. Therefore
  456. ``devtool ide-sdk`` supports the classic, generic setup with GDB on the
  457. development host and gdbserver on the target device.
  458. Roughly summarized, this means:
  459. - The binaries are copied via SSH to the remote target device by a
  460. script referred by ``tasks.json``.
  461. - gdbserver is started on the remote target device via SSH by a script
  462. referred by ``tasks.json``.
  463. Changing the parameters that are passed to the debugging executable
  464. requires modifying the generated script. The script is located at
  465. ``oe-scripts/gdbserver_*``. Defining the parameters in the ``args``
  466. field in the ``launch.json`` file does not work.
  467. - VSCode connects to gdbserver as documented in
  468. `Remote debugging or debugging with a local debugger server
  469. <https://code.visualstudio.com/docs/cpp/launch-json-reference#_remote-debugging-or-debugging-with-a-local-debugger-server>`__.
  470. Additionally ``--ide=none`` is supported. With the ``none`` IDE parameter,
  471. some generic configuration files like ``gdbinit`` files and some helper
  472. scripts starting gdbserver remotely on the target device as well as the GDB
  473. client on the host are generated.
  474. Here is a usage example for the ``cmake-example`` recipe from the
  475. ``meta-selftest`` layer which inherits :ref:`ref-classes-cmake-qemu`:
  476. .. code-block:: sh
  477. # Create the SDK
  478. devtool modify cmake-example --debug-build
  479. devtool ide-sdk cmake-example core-image-minimal -c --ide=none
  480. # Install the firmware on a target device or start QEMU
  481. runqemu
  482. # From exploring the workspace of cmake-example
  483. cd build/workspace/sources/cmake-example
  484. # Find cmake-native and save the path into a variable
  485. # Note: using just cmake instead of $CMAKE_NATIVE would work in many cases
  486. CMAKE_NATIVE="$(jq -r '.configurePresets[0] | "\(.cmakeExecutable)"' CMakeUserPresets.json)"
  487. # List available CMake presets
  488. "$CMAKE_NATIVE" --list-presets
  489. Available configure presets:
  490. "cmake-example-cortexa57" - cmake-example: cortexa57
  491. # Re-compile the already compiled sources
  492. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57
  493. ninja: no work to do.
  494. # Do a clean re-build
  495. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target clean
  496. [1/1] Cleaning all built files...
  497. Cleaning... 8 files.
  498. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target all
  499. [7/7] Linking CXX executable cmake-example
  500. # Run the cross-compiled unit tests with QEMU user-mode
  501. "$CMAKE_NATIVE" --build --preset cmake-example-cortexa57 --target test
  502. [0/1] Running tests...
  503. Test project .../build/tmp/work/cortexa57-poky-linux/cmake-example/1.0/cmake-example-1.0
  504. Start 1: test-cmake-example
  505. 1/1 Test #1: test-cmake-example ............... Passed 0.03 sec
  506. 100% tests passed, 0 tests failed out of 1
  507. Total Test time (real) = 0.03 sec
  508. # Using CTest directly is possible as well
  509. CTEST_NATIVE="$(dirname "$CMAKE_NATIVE")/ctest"
  510. # List available CMake presets
  511. "$CTEST_NATIVE" --list-presets
  512. Available test presets:
  513. "cmake-example-cortexa57" - cmake-example: cortexa57
  514. # Run the cross-compiled unit tests with QEMU user-mode
  515. "$CTEST_NATIVE" --preset "cmake-example-cortexa57"
  516. Test project ...build/tmp/work/cortexa57-poky-linux/cmake-example/1.0/cmake-example-1.0
  517. Start 1: test-cmake-example
  518. 1/1 Test #1: test-cmake-example ............... Passed 0.03 sec
  519. 100% tests passed, 0 tests failed out of 1
  520. Total Test time (real) = 0.03 sec
  521. # Deploying the new build to the target device (default is QEUM at 192.168.7.2)
  522. oe-scripts/install_and_deploy_cmake-example-cortexa57
  523. # Start a remote debugging session with gdbserver on the target and GDB on the host
  524. oe-scripts/gdbserver_1234_usr-bin-cmake-example_m
  525. oe-scripts/gdb_1234_usr-bin-cmake-example
  526. break main
  527. run
  528. step
  529. stepi
  530. continue
  531. quit
  532. # Stop gdbserver on the target device
  533. oe-scripts/gdbserver_1234_usr-bin-cmake-example_m stop
  534. #. *Shared sysroots mode*
  535. Creating an SDK with shared :term:`Sysroots <Sysroot>` that contains all the
  536. dependencies needed to work with ``my-recipe`` is possible with the following
  537. example command::
  538. $ devtool ide-sdk --mode=shared my-recipe
  539. For VSCode the cross-toolchain is exposed as a CMake kit. CMake kits are
  540. defined in ``~/.local/share/CMakeTools/cmake-tools-kits.json``.
  541. The following example shows how the cross-toolchain can be selected in
  542. VSCode. First of all we need a folder containing a CMake project.
  543. For this example, let's create a CMake project and start VSCode::
  544. mkdir kit-test
  545. echo "project(foo VERSION 1.0)" > kit-test/CMakeLists.txt
  546. code kit-test
  547. If there is a CMake project in the workspace, cross-compilation is
  548. supported:
  549. - Press ``Ctrl + Shift + P``, type ``CMake: Scan for Kits``
  550. - Press ``Ctrl + Shift + P``, type ``CMake: Select a Kit``
  551. Finally most of the features provided by CMake and the IDE should be
  552. available.
  553. Other IDEs than VSCode are supported as well. However,
  554. ``devtool ide-sdk --mode=shared --ide=none my-recipe`` is currently
  555. just a simple wrapper for the setup of the extensible SDK, as described in
  556. :ref:`setting_up_ext_sdk_in_build`.
  557. Use ``devtool upgrade`` to Create a Version of the Recipe that Supports a Newer Version of the Software
  558. =======================================================================================================
  559. The ``devtool upgrade`` command upgrades an existing recipe to that of a
  560. more up-to-date version found upstream. Throughout the life of software,
  561. recipes continually undergo version upgrades by their upstream
  562. publishers. You can use the ``devtool upgrade`` workflow to make sure
  563. your recipes you are using for builds are up-to-date with their upstream
  564. counterparts.
  565. .. note::
  566. Several methods exist by which you can upgrade recipes ---
  567. ``devtool upgrade`` happens to be one. You can read about all the methods by
  568. which you can upgrade recipes in the
  569. :ref:`dev-manual/upgrading-recipes:upgrading recipes` section of the Yocto
  570. Project Development Tasks Manual.
  571. The ``devtool upgrade`` command is flexible enough to allow you to specify
  572. source code revision and versioning schemes, extract code into or out of the
  573. ``devtool`` :ref:`devtool-the-workspace-layer-structure`, and work with any
  574. source file forms that the
  575. :ref:`bitbake-user-manual/bitbake-user-manual-fetching:fetchers` support.
  576. The following diagram shows the common development flow used with the
  577. ``devtool upgrade`` command:
  578. .. image:: figures/devtool-upgrade-flow.png
  579. :width: 100%
  580. #. *Initiate the Upgrade*: The top part of the flow shows the typical
  581. scenario by which you use the ``devtool upgrade`` command. The
  582. following conditions exist:
  583. - The recipe exists in a local layer external to the ``devtool``
  584. workspace.
  585. - The source files for the new release exist in the same location
  586. pointed to by :term:`SRC_URI`
  587. in the recipe (e.g. a tarball with the new version number in the
  588. name, or as a different revision in the upstream Git repository).
  589. A common situation is where third-party software has undergone a
  590. revision so that it has been upgraded. The recipe you have access to
  591. is likely in your own layer. Thus, you need to upgrade the recipe to
  592. use the newer version of the software::
  593. $ devtool upgrade -V version recipe
  594. By default, the ``devtool upgrade`` command extracts source
  595. code into the ``sources`` directory in the
  596. :ref:`devtool-the-workspace-layer-structure`.
  597. If you want the code extracted to any other location, you need to
  598. provide the ``srctree`` positional argument with the command as follows::
  599. $ devtool upgrade -V version recipe srctree
  600. .. note::
  601. In this example, the "-V" option specifies the new version. If you
  602. don't use "-V", the command upgrades the recipe to the latest
  603. version.
  604. If the source files pointed to by the :term:`SRC_URI` statement in the
  605. recipe are in a Git repository, you must provide the "-S" option and
  606. specify a revision for the software.
  607. Once ``devtool`` locates the recipe, it uses the :term:`SRC_URI` variable
  608. to locate the source code and any local patch files from other
  609. developers. The result is that the command sets up the source code,
  610. the new version of the recipe, and an append file all within the
  611. workspace.
  612. Additionally, if you have any non-patch local files (i.e. files
  613. referred to with ``file://`` entries in :term:`SRC_URI` statement
  614. excluding ``*.patch/`` or ``*.diff``), these files are copied to an
  615. ``oe-local-files`` folder under the newly created source tree.
  616. Copying the files here gives you a convenient area from which you can
  617. modify the files. Any changes or additions you make to those files
  618. are incorporated into the build the next time you build the software
  619. just as are other changes you might have made to the source.
  620. #. *Resolve any Conflicts created by the Upgrade*: Conflicts could happen
  621. after upgrading the software to a new version. Conflicts occur
  622. if your recipe specifies some patch files in :term:`SRC_URI` that
  623. conflict with changes made in the new version of the software. For
  624. such cases, you need to resolve the conflicts by editing the source
  625. and following the normal ``git rebase`` conflict resolution process.
  626. Before moving onto the next step, be sure to resolve any such
  627. conflicts created through use of a newer or different version of the
  628. software.
  629. #. *Build the Recipe or Rebuild the Image*: The next step you take
  630. depends on what you are going to do with the new code.
  631. If you need to eventually move the build output to the target
  632. hardware, use the following ``devtool`` command::
  633. $ devtool build recipe
  634. On the other hand, if you want an image to contain the recipe's
  635. packages from the workspace for immediate deployment onto a device
  636. (e.g. for testing purposes), you can use the ``devtool build-image``
  637. command::
  638. $ devtool build-image image
  639. #. *Deploy the Build Output*: When you use the ``devtool build`` command
  640. or ``bitbake`` to build your recipe, you probably want to see if the
  641. resulting build output works as expected on target hardware.
  642. .. note::
  643. This step assumes you have a previously built image that is
  644. already either running in QEMU or running on actual hardware.
  645. Also, it is assumed that for deployment of the image to the
  646. target, SSH is installed in the image and if the image is running
  647. on real hardware that you have network access to and from your
  648. development machine.
  649. You can deploy your build output to that target hardware by using the
  650. ``devtool deploy-target`` command::
  651. $ devtool deploy-target recipe target
  652. The target is a live target machine running as an SSH server.
  653. You can, of course, also deploy the image you build using the
  654. ``devtool build-image`` command to actual hardware. However,
  655. ``devtool`` does not provide a specific command that allows you to do
  656. this.
  657. #. *Finish Your Work With the Recipe*: The ``devtool finish`` command
  658. creates any patches corresponding to commits in the local Git
  659. repository, moves the new recipe to a more permanent layer, and then
  660. resets the recipe so that the recipe is built normally rather than
  661. from the workspace.
  662. Any work you did in the ``oe-local-files`` directory is preserved in
  663. the original files next to the recipe during the ``devtool finish``
  664. command.
  665. If you specify a destination layer that is the same as the original
  666. source, then the old version of the recipe and associated files are
  667. removed prior to adding the new version::
  668. $ devtool finish recipe layer
  669. .. note::
  670. Any changes you want to turn into patches must be committed to the
  671. Git repository in the source tree.
  672. As a final process of the ``devtool finish`` command, the state of
  673. the standard layers and the upstream source is restored so that you
  674. can build the recipe from those areas rather than the workspace.
  675. .. note::
  676. You can use the ``devtool reset`` command to put things back should you
  677. decide you do not want to proceed with your work. If you do use this
  678. command, realize that the source tree is preserved.
  679. A Closer Look at ``devtool add``
  680. ================================
  681. The ``devtool add`` command automatically creates a recipe based on the
  682. source tree you provide with the command. Currently, the command has
  683. support for the following:
  684. - Autotools (``autoconf`` and ``automake``)
  685. - CMake
  686. - Scons
  687. - ``qmake``
  688. - Plain ``Makefile``
  689. - Out-of-tree kernel module
  690. - Binary package (i.e. "-b" option)
  691. - Node.js module
  692. - Python modules that use ``setuptools`` or ``distutils``
  693. Apart from binary packages, the determination of how a source tree
  694. should be treated is automatic based on the files present within that
  695. source tree. For example, if a ``CMakeLists.txt`` file is found, then
  696. the source tree is assumed to be using CMake and is treated accordingly.
  697. .. note::
  698. In most cases, you need to edit the automatically generated recipe in
  699. order to make it build properly. Typically, you would go through
  700. several edit and build cycles until the recipe successfully builds.
  701. Once the recipe builds, you could use possible further iterations to
  702. test the recipe on the target device.
  703. The remainder of this section covers specifics regarding how parts of
  704. the recipe are generated.
  705. Name and Version
  706. ----------------
  707. If you do not specify a name and version on the command line,
  708. ``devtool add`` uses various metadata within the source tree in an
  709. attempt to determine the name and version of the software being built.
  710. Based on what the tool determines, ``devtool`` sets the name of the
  711. created recipe file accordingly.
  712. If ``devtool`` cannot determine the name and version, the command prints
  713. an error. For such cases, you must re-run the command and provide the
  714. name and version, just the name, or just the version as part of the
  715. command line.
  716. Sometimes the name or version determined from the source tree might be
  717. incorrect. For such a case, you must reset the recipe::
  718. $ devtool reset -n recipename
  719. After running the ``devtool reset`` command, you need to
  720. run ``devtool add`` again and provide the name or the version.
  721. Dependency Detection and Mapping
  722. --------------------------------
  723. The ``devtool add`` command attempts to detect build-time dependencies and map
  724. them to other recipes in the system. During this mapping, the command fills in
  725. the names of those recipes as part of the :term:`DEPENDS` variable within the
  726. recipe. If a dependency cannot be mapped, ``devtool`` places a comment
  727. in the recipe indicating such. The inability to map a dependency can
  728. result from naming not being recognized or because the dependency simply
  729. is not available. For cases where the dependency is not available, you
  730. must use the ``devtool add`` command to add an additional recipe that
  731. satisfies the dependency. Once you add that recipe, you need to update
  732. the :term:`DEPENDS` variable in the original recipe to include the new
  733. recipe.
  734. If you need to add runtime dependencies, you can do so by adding the
  735. following to your recipe::
  736. RDEPENDS:${PN} += "dependency1 dependency2 ..."
  737. .. note::
  738. The ``devtool add`` command often cannot distinguish between mandatory and
  739. optional dependencies. Consequently, some of the detected dependencies might
  740. in fact be optional. When in doubt, consult the documentation or the
  741. configure script for the software the recipe is building for further
  742. details. In some cases, you might find you can substitute the
  743. dependency with an option that disables the associated functionality
  744. passed to the configure script.
  745. License Detection
  746. -----------------
  747. The ``devtool add`` command attempts to determine if the software you are
  748. adding is able to be distributed under a common, open-source license. If
  749. so, the command sets the :term:`LICENSE` value accordingly.
  750. You should double-check the value added by the command against the
  751. documentation or source files for the software you are building and, if
  752. necessary, update that :term:`LICENSE` value.
  753. The ``devtool add`` command also sets the :term:`LIC_FILES_CHKSUM`
  754. value to point to all files that appear to be license-related. Realize
  755. that license statements often appear in comments at the top of source
  756. files or within the documentation. In such cases, the command does not
  757. recognize those license statements. Consequently, you might need to
  758. amend the :term:`LIC_FILES_CHKSUM` variable to point to one or more of those
  759. comments if present. Setting :term:`LIC_FILES_CHKSUM` is particularly
  760. important for third-party software. The mechanism attempts to ensure
  761. correct licensing should you upgrade the recipe to a newer upstream
  762. version in future. Any change in licensing is detected and you receive
  763. an error prompting you to check the license text again.
  764. If the ``devtool add`` command cannot determine licensing information,
  765. ``devtool`` sets the :term:`LICENSE` value to "CLOSED" and leaves the
  766. :term:`LIC_FILES_CHKSUM` value unset. This behavior allows you to continue
  767. with development even though the settings are unlikely to be correct in
  768. all cases. You should check the documentation or source files for the
  769. software you are building to determine the actual license.
  770. Adding Makefile-Only Software
  771. -----------------------------
  772. The use of Make by itself is very common in both proprietary and
  773. open-source software. Unfortunately, Makefiles are often not written
  774. with cross-compilation in mind. Thus, ``devtool add`` often cannot do
  775. very much to ensure that these Makefiles build correctly. It is very
  776. common, for example, to explicitly call ``gcc`` instead of using the
  777. :term:`CC` variable. Usually, in a
  778. cross-compilation environment, ``gcc`` is the compiler for the build
  779. host and the cross-compiler is named something similar to
  780. ``arm-poky-linux-gnueabi-gcc`` and might require arguments (e.g. to
  781. point to the associated sysroot for the target machine).
  782. When writing a recipe for Makefile-only software, keep the following in
  783. mind:
  784. - You probably need to patch the Makefile to use variables instead of
  785. hardcoding tools within the toolchain such as ``gcc`` and ``g++``.
  786. - The environment in which Make runs is set up with various standard
  787. variables for compilation (e.g. :term:`CC`, :term:`CXX`, and so forth) in a
  788. similar manner to the environment set up by the SDK's environment
  789. setup script. One easy way to see these variables is to run the
  790. ``devtool build`` command on the recipe and then look in
  791. ``oe-logs/run.do_compile``. Towards the top of this file, there is
  792. a list of environment variables that are set. You can take
  793. advantage of these variables within the Makefile.
  794. - If the Makefile sets a default for a variable using "=", that default
  795. overrides the value set in the environment, which is usually not
  796. desirable. For this case, you can either patch the Makefile so it
  797. sets the default using the "?=" operator, or you can alternatively
  798. force the value on the ``make`` command line. To force the value on
  799. the command line, add the variable setting to
  800. :term:`EXTRA_OEMAKE` or
  801. :term:`PACKAGECONFIG_CONFARGS`
  802. within the recipe. Here is an example using :term:`EXTRA_OEMAKE`::
  803. EXTRA_OEMAKE += "'CC=${CC}' 'CXX=${CXX}'"
  804. In the above example,
  805. single quotes are used around the variable settings as the values are
  806. likely to contain spaces because required default options are passed
  807. to the compiler.
  808. - Hardcoding paths inside Makefiles is often problematic in a
  809. cross-compilation environment. This is particularly true because
  810. those hardcoded paths often point to locations on the build host and
  811. thus will either be read-only or will introduce contamination into
  812. the cross-compilation because they are specific to the build host
  813. rather than the target. Patching the Makefile to use prefix variables
  814. or other path variables is usually the way to handle this situation.
  815. - Sometimes a Makefile runs target-specific commands such as
  816. ``ldconfig``. For such cases, you might be able to apply patches that
  817. remove these commands from the Makefile.
  818. Adding Native Tools
  819. -------------------
  820. Often, you need to build additional tools that run on the :term:`Build Host`
  821. as opposed to the target. You should indicate this requirement by using one of
  822. the following methods when you run ``devtool add``:
  823. - Specify the name of the recipe such that it ends with "-native".
  824. Specifying the name like this produces a recipe that only builds for
  825. the build host.
  826. - Specify the "--also-native" option with the ``devtool add``
  827. command. Specifying this option creates a recipe file that still
  828. builds for the target but also creates a variant with a "-native"
  829. suffix that builds for the build host.
  830. .. note::
  831. If you need to add a tool that is shipped as part of a source tree
  832. that builds code for the target, you can typically accomplish this by
  833. building the native and target parts separately rather than within
  834. the same compilation process. Realize though that with the
  835. "--also-native" option, you can add the tool using just one
  836. recipe file.
  837. Adding Node.js Modules
  838. ----------------------
  839. You can use the ``devtool add`` command two different ways to add
  840. Node.js modules: through ``npm`` or from a repository or local source.
  841. Use the following form to add Node.js modules through ``npm``::
  842. $ devtool add "npm://registry.npmjs.org;name=forever;version=0.15.1"
  843. The name and
  844. version parameters are mandatory. Lockdown and shrinkwrap files are
  845. generated and pointed to by the recipe in order to freeze the version
  846. that is fetched for the dependencies according to the first time. This
  847. also saves checksums that are verified on future fetches. Together,
  848. these behaviors ensure the reproducibility and integrity of the build.
  849. .. note::
  850. - You must use quotes around the URL. ``devtool add`` does not
  851. require the quotes, but the shell considers ";" as a splitter
  852. between multiple commands. Thus, without the quotes,
  853. ``devtool add`` does not receive the other parts, which results in
  854. several "command not found" errors.
  855. - In order to support adding Node.js modules, a ``nodejs`` recipe
  856. must be part of your SDK.
  857. As mentioned earlier, you can also add Node.js modules directly from a
  858. repository or local source tree. To add modules this way, use
  859. ``devtool add`` in the following form::
  860. $ devtool add https://github.com/diversario/node-ssdp
  861. In this example, ``devtool`` fetches the specified Git repository, detects the
  862. code as Node.js code, fetches dependencies using ``npm``, and sets
  863. :term:`SRC_URI` accordingly.
  864. Working With Recipes
  865. ====================
  866. When building a recipe using the ``devtool build`` command, the typical
  867. build progresses as follows:
  868. #. Fetch the source
  869. #. Unpack the source
  870. #. Configure the source
  871. #. Compile the source
  872. #. Install the build output
  873. #. Package the installed output
  874. For recipes in the workspace, fetching and unpacking is disabled as the
  875. source tree has already been prepared and is persistent. Each of these
  876. build steps is defined as a function (task), usually with a "do\_" prefix
  877. (e.g. :ref:`ref-tasks-fetch`,
  878. :ref:`ref-tasks-unpack`, and so
  879. forth). These functions are typically shell scripts but can instead be
  880. written in Python.
  881. If you look at the contents of a recipe, you will see that the recipe
  882. does not include complete instructions for building the software.
  883. Instead, common functionality is encapsulated in classes inherited with
  884. the ``inherit`` directive. This technique leaves the recipe to describe
  885. just the things that are specific to the software being built. There is
  886. a :ref:`ref-classes-base` class that is implicitly inherited by all recipes
  887. and provides the functionality that most recipes typically need.
  888. The remainder of this section presents information useful when working
  889. with recipes.
  890. Finding Logs and Work Files
  891. ---------------------------
  892. After the first run of the ``devtool build`` command, recipes that were
  893. previously created using the ``devtool add`` command or whose sources
  894. were modified using the ``devtool modify`` command contain symbolic
  895. links created within the source tree:
  896. - ``oe-logs``: This link points to the directory in which log files and
  897. run scripts for each build step are created.
  898. - ``oe-workdir``: This link points to the temporary work area for the
  899. recipe. The following locations under ``oe-workdir`` are particularly
  900. useful:
  901. - ``image/``: Contains all of the files installed during the
  902. :ref:`ref-tasks-install` stage.
  903. Within a recipe, this directory is referred to by the expression
  904. ``${``\ :term:`D`\ ``}``.
  905. - ``sysroot-destdir/``: Contains a subset of files installed within
  906. :ref:`ref-tasks-install` that have been put into the shared sysroot. For
  907. more information, see the
  908. ":ref:`dev-manual/new-recipe:sharing files between recipes`" section.
  909. - ``packages-split/``: Contains subdirectories for each package
  910. produced by the recipe. For more information, see the
  911. ":ref:`dev-manual/devtool:packaging`" section.
  912. You can use these links to get more information on what is happening at
  913. each build step.
  914. Setting Configure Arguments
  915. ---------------------------
  916. If the software your recipe is building uses GNU autoconf, then a fixed
  917. set of arguments is passed to it to enable cross-compilation plus any
  918. extras specified by :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`
  919. set within the recipe. If you wish to pass additional options, add them
  920. to :term:`EXTRA_OECONF` or :term:`PACKAGECONFIG_CONFARGS`. Other supported build
  921. tools have similar variables (e.g. :term:`EXTRA_OECMAKE` for CMake,
  922. :term:`EXTRA_OESCONS` for Scons, and so forth). If you need to pass anything on
  923. the ``make`` command line, you can use :term:`EXTRA_OEMAKE` or the
  924. :term:`PACKAGECONFIG_CONFARGS` variables to do so.
  925. You can use the ``devtool configure-help`` command to help you set the
  926. arguments listed in the previous paragraph. The command determines the
  927. exact options being passed, and shows them to you along with any custom
  928. arguments specified through :term:`EXTRA_OECONF` or
  929. :term:`PACKAGECONFIG_CONFARGS`. If applicable, the command also shows you
  930. the output of the configure script's "--help" option as a
  931. reference.
  932. Sharing Files Between Recipes
  933. -----------------------------
  934. Recipes often need to use files provided by other recipes on the
  935. :term:`Build Host`. For example,
  936. an application linking to a common library needs access to the library
  937. itself and its associated headers. The way this access is accomplished
  938. within the extensible SDK is through the sysroot. There is one sysroot per
  939. "machine" for which the SDK is being built. In practical terms, this
  940. means there is a sysroot for the target machine, and a sysroot for
  941. the build host.
  942. Recipes should never write files directly into the sysroot. Instead,
  943. files should be installed into standard locations during the
  944. :ref:`ref-tasks-install` task within the ``${``\ :term:`D`\ ``}`` directory. A
  945. subset of these files automatically goes into the sysroot. The reason
  946. for this limitation is that almost all files that go into the sysroot
  947. are cataloged in manifests in order to ensure they can be removed later
  948. when a recipe is modified or removed. Thus, the sysroot is able to
  949. remain free from stale files.
  950. Packaging
  951. ---------
  952. Packaging is not always particularly relevant within the extensible SDK.
  953. However, if you examine how build output gets into the final image on
  954. the target device, it is important to understand packaging because the
  955. contents of the image are expressed in terms of packages and not
  956. recipes.
  957. During the :ref:`ref-tasks-package` task, files installed during the
  958. :ref:`ref-tasks-install` task are split into one main package, which is almost
  959. always named the same as the recipe, and into several other packages. This
  960. separation exists because not all of those installed files are useful in every
  961. image. For example, you probably do not need any of the documentation installed
  962. in a production image. Consequently, for each recipe the documentation
  963. files are separated into a ``-doc`` package. Recipes that package
  964. software containing optional modules or plugins might undergo additional
  965. package splitting as well.
  966. After building a recipe, you can see where files have gone by looking in
  967. the ``oe-workdir/packages-split`` directory, which contains a
  968. subdirectory for each package. Apart from some advanced cases, the
  969. :term:`PACKAGES` and :term:`FILES` variables controls
  970. splitting. The :term:`PACKAGES` variable lists all of the packages to be
  971. produced, while the :term:`FILES` variable specifies which files to include
  972. in each package by using an override to specify the package. For
  973. example, ``FILES:${PN}`` specifies the files to go into the main package
  974. (i.e. the main package has the same name as the recipe and
  975. ``${``\ :term:`PN`\ ``}`` evaluates to the
  976. recipe name). The order of the :term:`PACKAGES` value is significant. For
  977. each installed file, the first package whose :term:`FILES` value matches the
  978. file is the package into which the file goes. Both the :term:`PACKAGES` and
  979. :term:`FILES` variables have default values. Consequently, you might find
  980. you do not even need to set these variables in your recipe unless the
  981. software the recipe is building installs files into non-standard
  982. locations.
  983. Restoring the Target Device to its Original State
  984. =================================================
  985. If you use the ``devtool deploy-target`` command to write a recipe's
  986. build output to the target, and you are working on an existing component
  987. of the system, then you might find yourself in a situation where you
  988. need to restore the original files that existed prior to running the
  989. ``devtool deploy-target`` command. Because the ``devtool deploy-target``
  990. command backs up any files it overwrites, you can use the
  991. ``devtool undeploy-target`` command to restore those files and remove
  992. any other files the recipe deployed. Consider the following example::
  993. $ devtool undeploy-target lighttpd root@192.168.7.2
  994. If you have deployed
  995. multiple applications, you can remove them all using the "-a" option
  996. thus restoring the target device to its original state::
  997. $ devtool undeploy-target -a root@192.168.7.2
  998. Information about files deployed to
  999. the target as well as any backed up files are stored on the target
  1000. itself. This storage, of course, requires some additional space on the
  1001. target machine.
  1002. .. note::
  1003. The ``devtool deploy-target`` and ``devtool undeploy-target`` commands do
  1004. not currently interact with any package management system on the target
  1005. device (e.g. RPM or OPKG). Consequently, you should not intermingle
  1006. ``devtool deploy-target`` and package manager operations on the target
  1007. device. Doing so could result in a conflicting set of files.