Is there any option to set package version in recipe from git output?
I have a recipe thats always download latest revision from git by setting SRCREV = "${AUTOREV}"
, and want to bitbake to set package version "PV" to output of git describe --abbrev=4 --dirty --always --long
I was able to manage some code to archive this goal, but I feel that this solution is not the perfect one, but anyway please see why.
Firstly let's compare output git command (git describe --abbrev=4 --dirty --always --long)* based on recipe and from git repository, to be sure that it's working as expected:
PV generated by bitbake based on recipe:
$ bitbake --environment hello-world | grep ^PV=
PV="4b5f"
output git repository:
$ git remote -v | grep fetch
origin https://github.com/leachim6/hello-world.git (fetch)
$ git describe --abbrev=4 --always --long
4b5f
How to archive that ? For test purpose I chose hello-world repository, lately on to define the PV I use bitbake python function approach that allows me to set output from such function to PV, recipe content:
$ cat ../meta-test/recipes-hello-world/hello-world/hello-world_git.bb
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://LICENSE;md5=2c4ac2930215d12ccb72d945112a0fa3"
SRC_URI = "git://github.com/leachim6/hello-world.git;protocol=https"
SRCREV = "4b5ff1ef90ceb442f5633fc9e5d28297ac0f69ff"
PV = "${@define_pn(d)}"
def define_pn(d):
import subprocess
source_dir = d.getVar('DL_DIR') + "/git2/github.com.leachim6.hello-world.git/"
cmd = "git describe --abbrev=4 --always --long"
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, cwd=source_dir)
out, err = proc.communicate()
return out.decode("utf-8").rstrip()
My main about this solution is how to setup properly source_dir variable in python function, that will be much flexible. I was trying to use the ${S} variable for instance but without luck - I got python errors during parsing recipe - gist with error. I am not so advanced in bitbake code, but maybe someone else could provide better way to setup this proper path.
*while I was uses the original command with --dirty flag, In bitbake output there was PV="4b5f-dirty", without it the output is the same as in the git repository.