[oe] [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version

Otavio Salvador otavio at ossystems.com.br
Wed Dec 15 12:42:29 UTC 2010


Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
 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..7f46fcb
--- /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 = "<hash>"
+
+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"
-- 
1.7.3





More information about the Openembedded-devel mailing list