Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 1 | .. SPDX-License-Identifier: CC-BY-SA-2.0-UK |
| 2 | |
| 3 | Recipe Style Guide |
| 4 | ****************** |
| 5 | |
| 6 | Recipe Naming Conventions |
| 7 | ========================= |
| 8 | |
| 9 | In general, most recipes should follow the naming convention |
| 10 | ``recipes-category/package/packagename_version.bb``. Recipes for related |
| 11 | projects may share the same package directory. ``packagename``, ``category``, |
| 12 | and ``package`` may contain hyphens, but hyphens are not allowed in ``version``. |
| 13 | |
| 14 | If the recipe is tracking a Git revision that does not correspond to a released |
| 15 | version of the software, ``version`` may be ``git`` (e.g. ``packagename_git.bb``) |
| 16 | |
| 17 | Version Policy |
| 18 | ============== |
| 19 | |
| 20 | Our versions follow the form ``<package epoch>:<package version>-<package revision>`` |
| 21 | or in BitBake variable terms ${:term:`PE`}:${:term:`PV`}-${:term:`PR`}. We |
| 22 | generally follow the `Debian <https://www.debian.org/doc/debian-policy/ch-controlfields.html#version>`__ |
| 23 | version policy which defines these terms. |
| 24 | |
| 25 | In most cases the version :term:`PV` will be set automatically from the recipe |
| 26 | file name. It is recommended to use released versions of software as these are |
| 27 | revisions that upstream are expecting people to use. |
| 28 | |
| 29 | Package versions should always compare and sort correctly so that upgrades work |
| 30 | as expected. With conventional versions such as ``1.4`` upgrading ``to 1.5`` |
| 31 | this happens naturally, but some versions don't sort. For example, |
| 32 | ``1.5 Release Candidate 2`` could be written as ``1.5rc2`` but this sorts after |
| 33 | ``1.5``, so upgrades from feeds won't happen correctly. |
| 34 | |
| 35 | Instead the tilde (``~``) operator can be used, which sorts before the empty |
| 36 | string so ``1.5~rc2`` comes before ``1.5``. There is a historical syntax which |
| 37 | may be found where :term:`PV` is set as a combination of the prior version |
| 38 | ``+`` the pre-release version, for example ``PV=1.4+1.5rc2``. This is a valid |
| 39 | syntax but the tilde form is preferred. |
| 40 | |
| 41 | For version comparisons, the ``opkg-compare-versions`` program from |
| 42 | ``opkg-utils`` can be useful when attempting to determine how two version |
| 43 | numbers compare to each other. Our definitive version comparison algorithm is |
| 44 | the one within bitbake which aims to match those of the package managers and |
| 45 | Debian policy closely. |
| 46 | |
| 47 | When a recipe references a git revision that does not correspond to a released |
| 48 | version of software (e.g. is not a tagged version), the :term:`PV` variable |
| 49 | should include the Git revision using the following to make the |
| 50 | version clear:: |
| 51 | |
| 52 | PV = "<version>+git${SRCPV}" |
| 53 | |
| 54 | In this case, ``<version>`` should be the most recently released version of the |
| 55 | software from the current source revision (``git describe`` can be useful for |
| 56 | determining this). Whilst not recommended for published layers, this format is |
| 57 | also useful when using :term:`AUTOREV` to set the recipe to increment source |
| 58 | control revisions automatically, which can be useful during local development. |
| 59 | |
| 60 | Version Number Changes |
| 61 | ====================== |
| 62 | |
| 63 | The :term:`PR` variable is used to indicate different revisions of a recipe |
| 64 | that reference the same upstream source version. It can be used to force a |
| 65 | new version of a package to be installed onto a device from a package feed. |
| 66 | These once had to be set manually but in most cases these can now be set and |
| 67 | incremented automatically by a PR Server connected with a package feed. |
| 68 | |
| 69 | When :term:`PV` increases, any existing :term:`PR` value can and should be |
| 70 | removed. |
| 71 | |
| 72 | If :term:`PV` changes in such a way that it does not increase with respect to |
| 73 | the previous value, you need to increase :term:`PE` to ensure package managers |
| 74 | will upgrade it correctly. If unset you should set :term:`PE` to "1" since |
| 75 | the default of empty is easily confused with "0" depending on the package |
| 76 | manager. :term:`PE` can only have an integer value. |
| 77 | |
| 78 | Recipe formatting |
| 79 | ================= |
| 80 | |
| 81 | Variable Formatting |
| 82 | ------------------- |
| 83 | |
| 84 | - Variable assignment should a space around each side of the operator, e.g. |
| 85 | ``FOO = "bar"``, not ``FOO="bar"``. |
| 86 | |
| 87 | - Double quotes should be used on the right-hand side of the assignment, |
| 88 | e.g. ``FOO = "bar"`` not ``FOO = 'bar'`` |
| 89 | |
| 90 | - Spaces should be used for indenting variables, with 4 spaces per tab |
| 91 | |
| 92 | - Long variables should be split over multiple lines when possible by using |
| 93 | the continuation character (``\``) |
| 94 | |
| 95 | - When splitting a long variable over multiple lines, all continuation lines |
| 96 | should be indented (with spaces) to align with the start of the quote on the |
| 97 | first line:: |
| 98 | |
| 99 | FOO = "this line is \ |
| 100 | long \ |
| 101 | " |
| 102 | |
| 103 | Instead of:: |
| 104 | |
| 105 | FOO = "this line is \ |
| 106 | long \ |
| 107 | " |
| 108 | |
| 109 | Python Function formatting |
| 110 | -------------------------- |
| 111 | |
| 112 | - Spaces must be used for indenting Python code, with 4 spaces per tab |
| 113 | |
| 114 | Shell Function formatting |
| 115 | ------------------------- |
| 116 | |
| 117 | - The formatting of shell functions should be consistent within layers. |
| 118 | Some use tabs, some use spaces. |
| 119 | |
| 120 | Recipe metadata |
| 121 | =============== |
| 122 | |
| 123 | Required Variables |
| 124 | ------------------ |
| 125 | |
| 126 | The following variables should be included in all recipes: |
| 127 | |
| 128 | - :term:`SUMMARY`: a one line description of the upstream project |
| 129 | |
| 130 | - :term:`DESCRIPTION`: an extended description of the upstream project, |
| 131 | possibly with multiple lines. If no reasonable description can be written, |
| 132 | this may be omitted as it defaults to :term:`SUMMARY`. |
| 133 | |
| 134 | - :term:`HOMEPAGE`: the URL to the upstream projects homepage. |
| 135 | |
| 136 | - :term:`BUGTRACKER`: the URL upstream projects bug tracking website, |
| 137 | if applicable. |
| 138 | |
| 139 | Recipe Ordering |
| 140 | --------------- |
| 141 | |
| 142 | When a variable is defined in recipes and classes, variables should follow the |
| 143 | general order when possible: |
| 144 | |
| 145 | - :term:`SUMMARY` |
| 146 | - :term:`DESCRIPTION` |
| 147 | - :term:`HOMEPAGE` |
| 148 | - :term:`BUGTRACKER` |
| 149 | - :term:`SECTION` |
| 150 | - :term:`LICENSE` |
| 151 | - :term:`LIC_FILES_CHKSUM` |
| 152 | - :term:`DEPENDS` |
| 153 | - :term:`PROVIDES` |
| 154 | - :term:`PV` |
| 155 | - :term:`SRC_URI` |
| 156 | - :term:`SRCREV` |
| 157 | - :term:`S` |
| 158 | - ``inherit ...`` |
| 159 | - :term:`PACKAGECONFIG` |
| 160 | - Build class specific variables such as ``EXTRA_QMAKEVARS_POST`` and :term:`EXTRA_OECONF` |
| 161 | - Tasks such as :ref:`ref-tasks-configure` |
| 162 | - :term:`PACKAGE_ARCH` |
| 163 | - :term:`PACKAGES` |
| 164 | - :term:`FILES` |
| 165 | - :term:`RDEPENDS` |
| 166 | - :term:`RRECOMMENDS` |
| 167 | - :term:`RSUGGESTS` |
| 168 | - :term:`RPROVIDES` |
| 169 | - :term:`RCONFLICTS` |
| 170 | - :term:`BBCLASSEXTEND` |
| 171 | |
| 172 | There are some cases where ordering is important and these cases would override |
| 173 | this default order. Examples include: |
| 174 | |
| 175 | - :term:`PACKAGE_ARCH` needing to be set before ``inherit packagegroup`` |
| 176 | |
| 177 | Tasks should be ordered based on the order they generally execute. For commonly |
| 178 | used tasks this would be: |
| 179 | |
| 180 | - :ref:`ref-tasks-fetch` |
| 181 | - :ref:`ref-tasks-unpack` |
| 182 | - :ref:`ref-tasks-patch` |
| 183 | - :ref:`ref-tasks-prepare_recipe_sysroot` |
| 184 | - :ref:`ref-tasks-configure` |
| 185 | - :ref:`ref-tasks-compile` |
| 186 | - :ref:`ref-tasks-install` |
| 187 | - :ref:`ref-tasks-populate_sysroot` |
| 188 | - :ref:`ref-tasks-package` |
| 189 | |
| 190 | Custom tasks should be sorted similarly. |
| 191 | |
| 192 | Package specific variables are typically grouped together, e.g.:: |
| 193 | |
| 194 | RDEPENDS:${PN} = “foo” |
| 195 | RDEPENDS:${PN}-libs = “bar” |
| 196 | |
| 197 | RRECOMMENDS:${PN} = “one” |
| 198 | RRECOMMENDS:${PN}-libs = “two” |
| 199 | |
| 200 | Recipe License Fields |
| 201 | --------------------- |
| 202 | |
| 203 | Recipes need to define both the :term:`LICENSE` and |
| 204 | :term:`LIC_FILES_CHKSUM` variables: |
| 205 | |
| 206 | - :term:`LICENSE`: This variable specifies the license for the software. |
| 207 | If you do not know the license under which the software you are |
| 208 | building is distributed, you should go to the source code and look |
| 209 | for that information. Typical files containing this information |
| 210 | include ``COPYING``, :term:`LICENSE`, and ``README`` files. You could |
| 211 | also find the information near the top of a source file. For example, |
| 212 | given a piece of software licensed under the GNU General Public |
| 213 | License version 2, you would set :term:`LICENSE` as follows:: |
| 214 | |
| 215 | LICENSE = "GPL-2.0-only" |
| 216 | |
| 217 | The licenses you specify within :term:`LICENSE` can have any name as long |
| 218 | as you do not use spaces, since spaces are used as separators between |
| 219 | license names. For standard licenses, use the names of the files in |
| 220 | ``meta/files/common-licenses/`` or the :term:`SPDXLICENSEMAP` flag names |
| 221 | defined in ``meta/conf/licenses.conf``. |
| 222 | |
| 223 | - :term:`LIC_FILES_CHKSUM`: The OpenEmbedded build system uses this |
| 224 | variable to make sure the license text has not changed. If it has, |
| 225 | the build produces an error and it affords you the chance to figure |
| 226 | it out and correct the problem. |
| 227 | |
| 228 | You need to specify all applicable licensing files for the software. |
| 229 | At the end of the configuration step, the build process will compare |
| 230 | the checksums of the files to be sure the text has not changed. Any |
| 231 | differences result in an error with the message containing the |
| 232 | current checksum. For more explanation and examples of how to set the |
| 233 | :term:`LIC_FILES_CHKSUM` variable, see the |
| 234 | ":ref:`dev-manual/licenses:tracking license changes`" section. |
| 235 | |
| 236 | To determine the correct checksum string, you can list the |
| 237 | appropriate files in the :term:`LIC_FILES_CHKSUM` variable with incorrect |
| 238 | md5 strings, attempt to build the software, and then note the |
| 239 | resulting error messages that will report the correct md5 strings. |
| 240 | See the ":ref:`dev-manual/new-recipe:fetching code`" section for |
| 241 | additional information. |
| 242 | |
| 243 | Here is an example that assumes the software has a ``COPYING`` file:: |
| 244 | |
| 245 | LIC_FILES_CHKSUM = "file://COPYING;md5=xxx" |
| 246 | |
| 247 | When you try to build the |
| 248 | software, the build system will produce an error and give you the |
| 249 | correct string that you can substitute into the recipe file for a |
| 250 | subsequent build. |
| 251 | |
| 252 | Tips and Guidelines for Writing Recipes |
| 253 | --------------------------------------- |
| 254 | |
| 255 | - Use :term:`BBCLASSEXTEND` instead of creating separate recipes such as ``-native`` |
| 256 | and ``-nativesdk`` ones, whenever possible. This avoids having to maintain multiple |
| 257 | recipe files at the same time. |