All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
@ 2010-12-15 12:42 Otavio Salvador
  2010-12-15 12:50 ` Otavio Salvador
  2010-12-15 21:17 ` [PATCH] classes/gitpkgv.bbclass: use 'git describe' information and simplify usage Otavio Salvador
  0 siblings, 2 replies; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 12:42 UTC (permalink / raw)
  To: openembedded-devel; +Cc: Otavio Salvador

Signed-off-by: Otavio Salvador <otavio@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




^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-12-15 21:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-15 12:42 [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version Otavio Salvador
2010-12-15 12:50 ` Otavio Salvador
2010-12-15 13:01   ` Martin Jansa
2010-12-15 14:27     ` Otavio Salvador
2010-12-15 16:36       ` Otavio Salvador
2010-12-15 17:18         ` Andreas Oberritter
2010-12-15 17:40           ` Otavio Salvador
2010-12-15 19:33       ` Martin Jansa
2010-12-15 21:17 ` [PATCH] classes/gitpkgv.bbclass: use 'git describe' information and simplify usage Otavio Salvador

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.