From patchwork Wed Dec 15 12:50:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: classes/gitpv.bbclass: use 'git describe' to for package version Date: Wed, 15 Dec 2010 12:50:25 -0000 From: Otavio Salvador X-Patchwork-Id: 72 Message-Id: <1292417425-1328-1-git-send-email-otavio@ossystems.com.br> To: openembedded-devel@lists.openembedded.org Cc: Otavio Salvador Signed-off-by: Otavio Salvador --- classes/gitpv.bbclass | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-) create mode 100644 classes/gitpv.bbclass diff --git a/classes/gitpv.bbclass b/classes/gitpv.bbclass new file mode 100644 index 0000000..c9496f1 --- /dev/null +++ b/classes/gitpv.bbclass @@ -0,0 +1,41 @@ +# gitpv.bbclass provides a PV variable which is a sortable version +# with the output of "git describe". +# +# It can handle SRCREV = ${AUTOREV}, as well as SRCREV = "" + +PV = "${@get_git_pv(d)}" + +def git_drop_tag_prefix(version): + import re + if re.match("v\d", version): + return version[1:] + else: + return version + +def get_git_pv(d): + import os + import bb + + urls = bb.data.getVar('SRC_URI', d, 1).split() + + for url in urls: + (type, host, path, user, pswd, parm) = bb.decodeurl(bb.data.expand(url, d)) + if type in ['git']: + gitsrcname = '%s%s' % (host, path.replace('/', '.')) + repodir = os.path.join(bb.data.expand('${GITDIR}', d), gitsrcname) + rev = bb.fetch.get_srcrev(d).split('+')[1] + + cwd = os.getcwd() + os.chdir(repodir) + + try: + ver = bb.fetch.runfetchcmd("git describe %s 2>/dev/null" % rev, d, quiet=True).strip() + except Exception: + commits = bb.fetch.runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True).strip() + ver = "0.0-%s-g%s" % commits, rev[:7] + + os.chdir(cwd) + + return git_drop_tag_prefix(ver) + + return "0+0"