Skip to contentSkip to conversation

classes/gitpv.bbclass: use 'git describe' to for package version

PATCH New Otavio Salvador 3 participants 9 messages Dec 15, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 classes/gitpv.bbclass: use 'git describe' to for package version

---
 classes/gitpv.bbclass |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 classes/gitpv.bbclass
classes/gitpv.bbclass new file +41 -0
new file mode 100644
index 0000000..7f46fcb
@@ -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"
Signature · 1 line
1.7.3
#1 lore raw

PATCH 1/1 classes/gitpv.bbclass: use 'git describe' to for package version

---
 classes/gitpv.bbclass |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 classes/gitpv.bbclass
classes/gitpv.bbclass new file +41 -0
new file mode 100644
index 0000000..c9496f1
@@ -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"
Signature · 1 line
1.7.3
#2 lore raw
Quoted 12 lines · Otavio Salvador
---
 classes/gitpv.bbclass |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)
 create mode 100644 classes/gitpv.bbclass
classes/gitpv.bbclass new file +0 -0
new file mode 100644
index 0000000..c9496f1

classes/gitpv.bbclass line 6

Quoted 6 lines
classes/gitpv.bbclass new file +6 -0
@@ -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)}"

can you integrate it with
classes/gitpkgv.bbclass ?

get_git_pkgv() there is quite similar
and after improving it with git describe you can use it here as ${GITPKGV}

and maybe assign to PV only ?= as IMHO recipe should be able to say different base version than 0.0 or use it only in PKGV..

Regards,

Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#3 lore raw
Quoted 7 lines · Martin Jansa
Quoted 6 lines · Otavio Salvador

---
 classes/gitpv.bbclass |   41 +++++++++++++++++++++++++++++++++++++++++

 1 files changed, 41 insertions(+), 0 deletions(-)

 create mode 100644 classes/gitpv.bbclass

Quoted 15 lines

classes/gitpv.bbclass line 6

Quoted 12 lines
classes/gitpv.bbclass new file +6 -0
new file mode 100644
index 0000000..c9496f1
@@ -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)}"

can you integrate it with
classes/gitpkgv.bbclass ?

I can however I think the usage is different.

The gitpkgv does not use describe and if there's users of it (there's no in recipes) we'd change it for them. That is wrong in my opinion.

So I thought about adding another class and not messing with it.

Quoted 5 lines

get_git_pkgv() there is quite similar
and after improving it with git describe you can use it here as ${GITPKGV}

and maybe assign to PV only ?= as IMHO recipe should be able to say different base version than 0.0 or use it only in PKGV..

about assign to PV ?= I agree however why someone might want to use it only in PKGV?

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#4 lore raw
Quoted 2 lines · Otavio Salvador

about assign to PV ?= I agree however why someone might want to use it only in PKGV?

?= doesn't seem to work. PV is preset so it won't override it.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#5 lore raw
Quoted 6 lines · Otavio Salvador
Quoted 2 lines · Otavio Salvador

about assign to PV ?= I agree however why someone might want to use it only in PKGV?

?= doesn't seem to work. PV is preset so it won't override it.

How about PV .= "${@get_git_pv(d)}"?

#6 lore raw
Quoted 9 lines · Andreas Oberritter
Quoted 6 lines · Otavio Salvador
Quoted 2 lines · Otavio Salvador

about assign to PV ?= I agree however why someone might want to use it only in PKGV?

?= doesn't seem to work. PV is preset so it won't override it.

How about PV .= "${@get_git_pv(d)}"?

It ought to use the get_git_pv output _only otherwise you'll get a confusing string.

Signature · 3 lines
Otavio Salvador                             O.S. Systems
E-mail: [email protected]  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br
#7 lore raw
In reply to Otavio Salvador
Quoted 24 lines · Otavio Salvador
Quoted 7 lines · Martin Jansa
Quoted 6 lines · Otavio Salvador

---
 classes/gitpv.bbclass |   41 +++++++++++++++++++++++++++++++++++++++++

 1 files changed, 41 insertions(+), 0 deletions(-)

 create mode 100644 classes/gitpv.bbclass

Quoted 15 lines

classes/gitpv.bbclass line 6

Quoted 12 lines
classes/gitpv.bbclass new file +6 -0
new file mode 100644
index 0000000..c9496f1
@@ -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)}"

can you integrate it with
classes/gitpkgv.bbclass ?

Quoted 1 line

I can however I think the usage is different.

I find 3 similar classes a bit confusing
gitpkgv, gitver and now gitpv

so I was hoping that all 3 classes could be merged to one (probably gitver is best name) where all usefull variables will be prepared, and then only the right one used in recipe.

Like in gitpkgv.bbclass example:

# inherit gitpkgv
#
# PV = "1.0+git${SRCPV}"        
# PKGV = "1.0+git${GITPKGV}"

btw there should be '+gitr' not '+git' AFAIK

in your case, you can use something like
PV = "${GITVER}"

btw your current implementation imho doesn't provide sortable version in case someone makes tag "something-special" between tags "release-2010.12" and "release-2011.03".

Quoted 2 lines

The gitpkgv does not use describe and if there's users of it (there's no in recipes) we'd change it for them. That is wrong in my opinion.

agreed but it can still be in same bbclass maybe in new variable ?GITTAGVER? as long as bbclass is not changing variables like PV (and expects recipe to use provided variables itself).

Quoted 2 lines

about assign to PV ?= I agree however why someone might want to use it only in PKGV?

Here is a bit longer thread with reasoning and description
http://www.mail-archive.com/[email protected]/msg06746.html

Even after converting many recipes from SRCREV to SRCPV I find this concept nice and if local persistent cache will be still needed in new fetchers implementation, then we should probably convert git recipes using SRCPV to something like GITPKGV (this time hopefully without PE bump).

Regards,

Signature · 1 line
Martin 'JaMa' Jansa     jabber: [email protected]
#8 lore raw

PATCH 1/1 classes/gitpkgv.bbclass: use 'git describe' information and simplify usage

In reply to Otavio Salvador

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.

---
 classes/gitpkgv.bbclass |   41 +++++++++++++++++++++++++----------------
 1 files changed, 25 insertions(+), 16 deletions(-)
classes/gitpkgv.bbclass +25 -16
index bc1dc32..ed34a50 100644
@@ -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"
Signature · 1 line
1.7.3