Difference between revisions of "Styleguide"
PaulEggleton (talk | contribs) (Explicitly link to Versioning Policy page) |
(add PACKAGECONFIG and BBCLASSEXTEND to variable layout section. add EXTRA_OECONF as an additional example of "build class specific variables") |
||
Line 83: | Line 83: | ||
** S | ** S | ||
** inherit ... | ** inherit ... | ||
− | ** build class specific variables, i.e. EXTRA_QMAKEVARS_POST | + | ** PACKAGECONFIG |
+ | ** build class specific variables, i.e. EXTRA_QMAKEVARS_POST, EXTRA_OECONF | ||
** task overrides, i.e. do_configure | ** task overrides, i.e. do_configure | ||
** PACKAGE_ARCH | ** PACKAGE_ARCH | ||
Line 93: | Line 94: | ||
** RPROVIDES | ** RPROVIDES | ||
** RCONFLICTS | ** RCONFLICTS | ||
+ | ** BBCLASSEXTEND | ||
* Package related variables for a given package are often grouped together for clarity. | * Package related variables for a given package are often grouped together for clarity. |
Revision as of 17:22, 24 May 2018
Contents
Motivation
As with most style guides, the idea here is to have a consistent format and look so that when someone new comes to the scene they can learn quickly and get involved. This also helps reviewers and maintainers understand what changes are being made by contributors.
Naming Conventions
- Generally, name recipes <packagename>_<version>.bb
- See also Versioning Policy
Format Guidelines
- The correct spacing for a variable assignment is FOO = "BAR".
- Use quotes on the right hand side of assignments: FOO = "BAR"
- No spaces are allowed behind the line continuation symbol (\)
- Comments are allowed using the '#' character at the beginning of a line, but you cannot use a comment within a continuation.
- Use spaces for indentation as developers tends to use different amount of spaces per one tab.
- Python functions must be four space indented - no tabs.
- Shell functions in OE-Core usually use tabs for indentation, but other layers usually use consistent indentation with 4 spaces (in shell functions, python functions and for indentation of multi-line variables)
- Splitting of long list values (such as SRC_URI) over multiple lines, and indenting the second line onwards is desirable:
- For values split over multiple lines, indent successive lines up to the level of the start of the value on the first line, and have the final closing quote on its own line:
FOO = "\ bar \ done \ "
- Some layers prefer to use four-space indentation on sucessive lines and prefer the closing quote as the first character:
FOO = "\ bar \ done \ "
- For values split over multiple lines, indent successive lines up to the level of the start of the value on the first line, and have the final closing quote on its own line:
Style Guidelines
Additional Metadata
All recipes should aim to specify the following fields where possible:
- SUMMARY: should give an 80 character/one line maximum short summary of the description.
- DESCRIPTION: should give an extended (possibly multi-line) description of what recipe provides. Note that by default, DESCRIPTION is set to the value of SUMMARY, so if you only have a short description to use, just set SUMMARY.
- HOMEPAGE: upstream website
- BUGTRACKER: upstream bug tracker URL if available
- LICENSE: must be accurate and list all applicable licenses.
- LIC_FILES_CHKSUM: should if at all possible point to one or more files within the upstream source in order to detect changes on upgrade
For details on how to set LICENSE and LIC_FILES_CHKSUM, see Recipe License Fields.
do_install
- Use
oe_runmake install
(which runsmake install
) where at all possible - Don't use cp to put files into staging or destination directories, use install instead.
- Don't use mkdir to create destination directories, use install -d instead.
- Modify files after installing them, not before (to ensure do_install can be re-executed)
- Use rm -f to avoid failure in case do_install is re-executed
Ordering and grouping
- Put the inherit declaration after the initial variables are set up and before any custom do_ routines. This is flexible as ordering is often important.
- If you define custom do_ routines, keep them in the order of the tasks being executed, that is:
- do_fetch
- do_unpack
- do_patch
- do_configure
- do_compile
- do_install
- do_populate_sysroot
- do_package
- Recipes should follow a roughly standard variable / function order, based on the logical order fields are needed and tasks are executed:
- SUMMARY
- DESCRIPTION
- AUTHOR
- HOMEPAGE
- SECTION
- LICENSE
- LIC_FILES_CHKSUM
- DEPENDS
- PROVIDES
- PV
- SRC_URI
- SRCREV
- S
- inherit ...
- PACKAGECONFIG
- build class specific variables, i.e. EXTRA_QMAKEVARS_POST, EXTRA_OECONF
- task overrides, i.e. do_configure
- PACKAGE_ARCH
- PACKAGES
- FILES
- RDEPENDS
- RRECOMMENDS
- RSUGGESTS
- RPROVIDES
- RCONFLICTS
- BBCLASSEXTEND
- Package related variables for a given package are often grouped together for clarity.
Version fields
- Handling PR (revision):
- Remove PR when PV (i.e. the recipe version) increases
- Preserve existing PR values otherwise (or the overall version will decrease which is not desirable)
- Do not specify PR in new recipes
- No need to increase existing values of PR unless there is a change that would not otherwise trigger the appropriate rebuild/re-execution (very rare)
- If the PV changes in such a way that it does not increase with respect to the previous value, you need to increase PE (or set it to "1" if not already set) to ensure package managers will upgrade it correctly
See also Versioning Policy
Patches
Patches (i.e. patch files which are referred to in SRC_URI within recipes) should have a header containing information about where they came from and why they are required. This makes examining patches in future and sending appropriate ones upstream much easier.
For further information on patch header formatting, see Commit Patch Message Guidelines.
Misc
- Use BBCLASSEXTEND where possible instead of separate -native and -nativesdk recipes
- Avoid custom do_configure for autotooled projects - the default provided by autotools.bbclass should work for almost all cases
- pkgconfig .pc files should be correct and not need manual mangling
Style Checking tools
You can run contrib/oe-stylize.py from meta-oe on your recipes before submitting them; however it is not necessarily up-to-date with all current style conventions. This page should be considered the canonical reference.
Example Recipe
SUMMARY = "X11 Code Viewer" DESCRIPTION = "Allow viewing of X11 code in a fancy way which allows easier \ and more productive X11 programming" AUTHOR = "John Bazz <john.bazz@example.org>" HOMEPAGE = "http://www.example.org/xcv/" SECTION = "x11/applications" LICENSE = "GPL-2.0" DEPENDS = "libsm libx11 libxext libxaw" PV = "0.9+git${SRCPV}" # upstream does not yet publish any release so we have to fetch last working version from GIT SRCREV = "6a5e79ae8a0f4a273a603b2df1742972510d3d8f" SRC_URI = "git://xcv.example.org/xcv;protocol=http \ file://toolbar-resize-fix.patch" S = "${WORKDIR}/xcv/" inherit autotools do_configure_prepend() { rm ${S}/aclocal.m4 } do_install() { install -d ${D}${bindir} install -d ${D}${mandir}/man1 install -m 0755 xcv ${D}${bindir}/ install -m 0644 xcv.1.gz ${D}${mandir}/man1/ } RDEPENDS_${PN} = "shared-mime-info" RRECOMMENDS_${PN} = "ctags" RCONFLICTS_${PN} = "xcv2"