[oe] [PATCH] classes/gitpkgv.bbclass: use 'git describe' information and simplify usage
Otavio Salvador
otavio at ossystems.com.br
Wed Dec 15 21:17:13 UTC 2010
By default the PKGV is going to use 'git describe' information except
if 'GITPKGV_USE_TAGS = "0"' is used.
For easy usage, the class defines PV and PKGV for sane values making
it quite trivial for its use.
Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
classes/gitpkgv.bbclass | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/classes/gitpkgv.bbclass b/classes/gitpkgv.bbclass
index bc1dc32..ed34a50 100644
--- a/classes/gitpkgv.bbclass
+++ b/classes/gitpkgv.bbclass
@@ -1,27 +1,27 @@
-# gitpkgv.bbclass provides a GITPKGV variable which is a sortable version
-# with the format NN+GITHASH, to be used in PKGV, where
-#
-# NN equals the total number of revs up to SRCREV
-# GITHASH is SRCREV's (full) hash
+# gitpkgv.bbclass provides a PKGV variable based on 'git describe'
+# output or the number of commits up to SRCREV.
#
# gitpkgv.bbclass assumes the git repository has been cloned, and contains
-# SRCREV. So ${GITPKGV} should never be used in PV, only in PKGV.
-# It can handle SRCREV = ${AUTOREV}, as well as SRCREV = "<some fixed git hash>"
-#
-# use example:
+# SRCREV. So it should never be used in PV, only in PKGV.
#
-# inherit gitpkgv
-#
-# PV = "1.0+git${SRCPV}"
-# PKGV = "1.0+git${GITPKGV}"
+# It can handle SRCREV = ${AUTOREV}, as well as SRCREV = "<some fixed git hash>"
-GITPKGV = "${@get_git_pkgv(d)}"
+PV = "gitr${SRCPV}"
+PKGV = "${@get_git_pkgv(d)}"
+
+def git_drop_tag_prefix(version):
+ import re
+ if re.match("v\d", version):
+ return version[1:]
+ else:
+ return version
def get_git_pkgv(d):
import os
import bb
urls = bb.data.getVar('SRC_URI', d, 1).split()
+ use_tags = bb.data.getVar('GITPKGV_USE_TAGS', d, 1)
for url in urls:
(type, host, path, user, pswd, parm) = bb.decodeurl(bb.data.expand(url, d))
@@ -33,9 +33,18 @@ def get_git_pkgv(d):
cwd = os.getcwd()
os.chdir(repodir)
- output = bb.fetch.runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True)
+
+ try:
+ if not use_tags:
+ raise Exception("Ignoring tag values.")
+
+ ver = git_drop_tag_prefix(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 "%s+%s" % (output.split()[0], rev)
+ return ver
return "0+0"
--
1.7.3
More information about the Openembedded-devel
mailing list