Poky version-specific variables

From time to time I need some code that is only applicable to a certain version of Yocto. Each Yocto release updates the DISTRO_VERSION variable so we can use that to track poky upgrades in our layer. This is useful because often the Yocto poky distribution is updated independently of other layers.

Imagine a bug fix on newer upstream version that you don’t want to back port to your local poky. Instead, you want to overwrite that code or variable in your own independent layer. To do that you need a bit of python code. Let’s imagine you have want to change ERROR_QA specifically for poky DISTRO_VERSION=4.0.1:

# local.conf
python() {
  # Check if we have the correct DISTRO_VERSION and send a fatal error if we do not.
  if d.getVar("DISTRO_VERSION") != "4.0.1":
    bb.fatal(f"Change of ERROR_QA is not validated for {d.getVar('DISTRO_VERSION')}")

  # set ERROR_QA to a specia value only if Poky is at our desired version
  d.setVar("ERROR_QA", "dev-so")

The above code will generate a fatal error if the DISTRO_VERSION is different than what we originally intended. The fatal error makes sure you will need to either remove the workaround or fix it again.

This also works to override entire functions, on your layer, as long as the function name and signature matches.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s