[oe] [PATCH] classes/gitpkgv.bbclass: add GITPKGVTAG that uses 'git describe'
Otavio Salvador
otavio at ossystems.com.br
Thu Dec 16 14:35:12 UTC 2010
Using ${GITPKGVTAG} allows for automatic versioning based on the
repository tags. For those that doesn't want to use it, ${GITPKGV} is
still available.
Signed-off-by: Otavio Salvador <otavio at ossystems.com.br>
---
classes/gitpkgv.bbclass | 54 +++++++++++++++++++++++++++++++++++++---------
1 files changed, 43 insertions(+), 11 deletions(-)
diff --git a/classes/gitpkgv.bbclass b/classes/gitpkgv.bbclass
index bc1dc32..ab8ba6e 100644
--- a/classes/gitpkgv.bbclass
+++ b/classes/gitpkgv.bbclass
@@ -1,12 +1,19 @@
-# gitpkgv.bbclass provides a GITPKGV variable which is a sortable version
-# with the format NN+GITHASH, to be used in PKGV, where
+# gitpkgv.bbclass provides a GITPKGV and GITPKGVTAG variables to be
+# used in PKGV, as described bellow:
#
-# NN equals the total number of revs up to SRCREV
-# GITHASH is SRCREV's (full) hash
+# - GITPKGV which is a sortable version with the format NN+GITHASH, to
+# be used in PKGV, where
#
-# 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>"
+# NN equals the total number of revs up to SRCREV
+# GITHASH is SRCREV's (full) hash
+#
+# - GITPKGVTAG which is the output of 'git describe' allowing for
+# automatic versioning
+#
+# gitpkgv.bbclass assumes the git repository has been cloned, and
+# contains SRCREV. So ${GITPKGV} and ${GITPKGVTAG}should never be used
+# in PV, only in PKGV. It can handle SRCREV = ${AUTOREV}, as well as
+# SRCREV = "<some fixed git hash>"
#
# use example:
#
@@ -14,10 +21,26 @@
#
# PV = "1.0+git${SRCPV}"
# PKGV = "1.0+git${GITPKGV}"
+#
+# or
+#
+# inherit gitpkgv
+#
+# PV = "gitr${SRCPV}"
+# PKGV = "${GITPKGVTAG}"
-GITPKGV = "${@get_git_pkgv(d)}"
-def get_git_pkgv(d):
+GITPKGV = "${@get_git_pkgv(d, False)}"
+GITPKGVTAG = "${@get_git_pkgv(d, True)}"
+
+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, use_tags):
import os
import bb
@@ -33,9 +56,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 = "%s+%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