How to use dynamic layers in Yocto

It is common for a recipe in one layer (say your meta-mycompany layer) to modify a recipe in another layer. This allows you to change configuration options, add patches, etc. BSP layers are often prime candidates for appends. However, if the BSP layer is not present, then a bbappend will cause a bitbake error.

The bitbake dynamic layer feature allows you to conditionally add recipes if a layer is present. Here is how we use it in the Yoe Distribution:

# We have a conf and classes directory, append to BBPATH
BBPATH .= ":${LAYERDIR}"

# We have a recipes directory, add to BBFILES
BBFILES += "${LAYERDIR}/recipes*/*/*.bb ${LAYERDIR}/recipes*/*/*.bbappend"

BBFILE_COLLECTIONS += "meta-yoe"
BBFILE_PATTERN_meta-yoe := "^${LAYERDIR}/"
BBFILE_PRIORITY_meta-yoe = "99"
LAYERSERIES_COMPAT_meta-yoe = "kirkstone"
LAYERDEPENDS_meta-yoe = "core elm-binary-layer"

BBFILES_DYNAMIC += " \
    qt5-layer:${LAYERDIR}/dynamic-layers/qt5-layer/*/*/*.bb \
    qt5-layer:${LAYERDIR}/dynamic-layers/qt5-layer/*/*/*.bbappend \
    meta-96boards:${LAYERDIR}/dynamic-layers/meta-96boards/*/*/*.bb \
    meta-96boards:${LAYERDIR}/dynamic-layers/meta-96boards/*/*/*.bbappend \
    meta-ti-bsp:${LAYERDIR}/dynamic-layers/meta-ti/*/*/*.bb \
    meta-ti-bsp:${LAYERDIR}/dynamic-layers/meta-ti/*/*/*.bbappend \
    raspberrypi:${LAYERDIR}/dynamic-layers/raspberrypi/*/*/*.bb \
    raspberrypi:${LAYERDIR}/dynamic-layers/raspberrypi/*/*/*.bbappend \
    swupdate:${LAYERDIR}/dynamic-layers/swupdate/*/*/*.bb \
    swupdate:${LAYERDIR}/dynamic-layers/swupdate/*/*/*.bbappend \
    webkit:${LAYERDIR}/dynamic-layers/webkit/*/*/*.bb \
    webkit:${LAYERDIR}/dynamic-layers/webkit/*/*/*.bbappend \
"

When using Yoe, you can remove a BSP layer (ex: sources/raspberrypi) and Yoe will continue to build just fine. For product builds, it sometimes makes sense to remove extraneous layers to speed up bitbake parsing times and streamline builds.

Dynamic layers also makes it easier for stand-alone layers to be used in more situations without as many hard dependencies. Anytime you can reduce dependencies in your software builds, you are simplifying your build, which reduces long term maintenance costs.

For more information on dynamic layers, see reference manual.

well written !! I think we should remove meta-qt4 from this since its jaded :slight_smile:

agreed, qt4 sees little use any more