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

* [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  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 21:17 ` [PATCH] classes/gitpkgv.bbclass: use 'git describe' information and simplify usage Otavio Salvador
  1 sibling, 1 reply; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 12:50 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..c9496f1
--- /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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 12:50 ` Otavio Salvador
@ 2010-12-15 13:01   ` Martin Jansa
  2010-12-15 14:27     ` Otavio Salvador
  0 siblings, 1 reply; 9+ messages in thread
From: Martin Jansa @ 2010-12-15 13:01 UTC (permalink / raw)
  To: openembedded-devel; +Cc: Otavio Salvador

On Wed, Dec 15, 2010 at 10:50:25AM -0200, Otavio Salvador wrote:
> 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..c9496f1
> --- /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)}"

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,

-- 
Martin 'JaMa' Jansa     jabber: Martin.Jansa@gmail.com



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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 13:01   ` Martin Jansa
@ 2010-12-15 14:27     ` Otavio Salvador
  2010-12-15 16:36       ` Otavio Salvador
  2010-12-15 19:33       ` Martin Jansa
  0 siblings, 2 replies; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 14:27 UTC (permalink / raw)
  To: Martin Jansa; +Cc: openembedded-devel

On Wed, Dec 15, 2010 at 11:01, Martin Jansa <martin.jansa@gmail.com> wrote:
> On Wed, Dec 15, 2010 at 10:50:25AM -0200, Otavio Salvador wrote:
>> 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..c9496f1
>> --- /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)}"
>
> 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.

> 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?

-- 
Otavio Salvador                             O.S. Systems
E-mail: otavio@ossystems.com.br  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br



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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 14:27     ` Otavio Salvador
@ 2010-12-15 16:36       ` Otavio Salvador
  2010-12-15 17:18         ` Andreas Oberritter
  2010-12-15 19:33       ` Martin Jansa
  1 sibling, 1 reply; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 16:36 UTC (permalink / raw)
  To: Martin Jansa; +Cc: openembedded-devel

On Wed, Dec 15, 2010 at 12:27, Otavio Salvador <otavio@ossystems.com.br> wrote:
> 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.

-- 
Otavio Salvador                             O.S. Systems
E-mail: otavio@ossystems.com.br  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br



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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 16:36       ` Otavio Salvador
@ 2010-12-15 17:18         ` Andreas Oberritter
  2010-12-15 17:40           ` Otavio Salvador
  0 siblings, 1 reply; 9+ messages in thread
From: Andreas Oberritter @ 2010-12-15 17:18 UTC (permalink / raw)
  To: openembedded-devel

On 12/15/2010 05:36 PM, Otavio Salvador wrote:
> On Wed, Dec 15, 2010 at 12:27, Otavio Salvador <otavio@ossystems.com.br> wrote:
>> 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)}"?




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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 17:18         ` Andreas Oberritter
@ 2010-12-15 17:40           ` Otavio Salvador
  0 siblings, 0 replies; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 17:40 UTC (permalink / raw)
  To: openembedded-devel

On Wed, Dec 15, 2010 at 15:18, Andreas Oberritter <obi@opendreambox.org> wrote:
> On 12/15/2010 05:36 PM, Otavio Salvador wrote:
>> On Wed, Dec 15, 2010 at 12:27, Otavio Salvador <otavio@ossystems.com.br> wrote:
>>> 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.

-- 
Otavio Salvador                             O.S. Systems
E-mail: otavio@ossystems.com.br  http://www.ossystems.com.br
Mobile: +55 53 9981-7854              http://projetos.ossystems.com.br



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

* Re: [PATCH] classes/gitpv.bbclass: use 'git describe' to for package version
  2010-12-15 14:27     ` Otavio Salvador
  2010-12-15 16:36       ` Otavio Salvador
@ 2010-12-15 19:33       ` Martin Jansa
  1 sibling, 0 replies; 9+ messages in thread
From: Martin Jansa @ 2010-12-15 19:33 UTC (permalink / raw)
  To: Otavio Salvador; +Cc: openembedded-devel

On Wed, Dec 15, 2010 at 12:27:12PM -0200, Otavio Salvador wrote:
> On Wed, Dec 15, 2010 at 11:01, Martin Jansa <martin.jansa@gmail.com> wrote:
> > On Wed, Dec 15, 2010 at 10:50:25AM -0200, Otavio Salvador wrote:
> >> 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..c9496f1
> >> --- /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)}"
> >
> > can you integrate it with
> > classes/gitpkgv.bbclass ?
> 
> 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".

> 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).

> 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/openembedded-devel@lists.openembedded.org/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,

-- 
Martin 'JaMa' Jansa     jabber: Martin.Jansa@gmail.com



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

* [PATCH] classes/gitpkgv.bbclass: use 'git describe' information and simplify usage
  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 21:17 ` Otavio Salvador
  1 sibling, 0 replies; 9+ messages in thread
From: Otavio Salvador @ 2010-12-15 21:17 UTC (permalink / raw)
  To: openembedded-devel; +Cc: 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.

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




^ 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.