classes/gitpkgv.bbclass: add GITPKGVTAG that uses 'git describe'
PATCH 1/1 classes/gitpkgv.bbclass: add GITPKGVTAG that uses 'git describe'
Using ${GITPKGVTAG} allows for automatic versioning based on the repository tags. For those that doesn't want to use it, ${GITPKGV} is still available.
--- classes/gitpkgv.bbclass | 54 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 43 insertions(+), 11 deletions(-)
classes/gitpkgv.bbclass +43 -11
@@ -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"
Signature · 1 line
1.7.3
PATCH 1/1 classes/gitpkgv.bbclass: add GITPKGVTAG that uses 'git describe'
Using ${GITPKGVTAG} allows for automatic versioning based on the repository tags. For those that doesn't want to use it, ${GITPKGV} is still available.
--- classes/gitpkgv.bbclass | 59 ++++++++++++++++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 13 deletions(-)
classes/gitpkgv.bbclass +46 -13
@@ -1,23 +1,46 @@ -# 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: # # inherit gitpkgv # -# PV = "1.0+git${SRCPV}" -# PKGV = "1.0+git${GITPKGV}" +# PV = "1.0+gitr${SRCPV}" +# PKGV = "1.0+gitr${GITPKGV}" +# +# or +# +# inherit gitpkgv +# +# PV = "1.0+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,19 @@ 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) + + commits = bb.fetch.runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True).strip() + + if use_tags: + try: + ver = git_drop_tag_prefix(bb.fetch.runfetchcmd("git describe %s 2>/dev/null" % rev, d, quiet=True).strip()) + except Exception: + ver = "0.0-%s-g%s" % commits, rev[:7] + else: + ver = "%s+%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
Quoted 3 lines · Otavio Salvador
Using ${GITPKGVTAG} allows for automatic versioning based on the repository tags. For those that doesn't want to use it, ${GITPKGV} is still available.
Thanks for merging it to one bbclass. IMHO looks much better now. Consider providing examples and warning as suggested bellow.
Quoted 32 lines
Signed-off-by Otavio Salvador <[email protected]>--- classes/gitpkgv.bbclass | 59 ++++++++++++++++++++++++++++++++++++---------- 1 files changed, 46 insertions(+), 13 deletions(-)classes/gitpkgv.bbclass +13
-7@@ -1,23 +1,46 @@ -# 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
classes/gitpkgv.bbclass line 23
Quoted 10 lines
classes/gitpkgv.bbclass +3
-2+# well as SRCREV = "<some fixed git hash>" # # use example: # # inherit gitpkgv # -# PV = "1.0+git${SRCPV}" -# PKGV = "1.0+git${GITPKGV}" +# PV = "1.0+gitr${SRCPV}" +# PKGV = "1.0+gitr${GITPKGV}"
# PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b
# PKGV = "1.0+gitr${GITPKGV}" # expands also to something like 1.0+gitr31337+4c1c21d7dbbf93b0df336994524313dfe0d4963b
classes/gitpkgv.bbclass line 25
Quoted 2 lines
classes/gitpkgv.bbclass +2
-0+# +# or
As we were discussing with otavio on #oe, I think there should be warning, that GITPKGVTAG is really sortable only if the upstream repo keeps consistent AND sortable tag names.
For example tags in OE repo will fail, because only tested_2010-* tags are sortable but this sequence:
tested_2010-11-04
release-2010.12-branchpoint
tested_2010-11-12
is not. And only way to fix it when it's shiped with non-standard tag to targets is to bump PE :/.
Even better solution would be to set something like GITTAGFORMAT in recipe, to expected consistent tag scheme and if returned git describe prefix is different then warn builder about it or even fail or ignore that tag.
Proposed "warning":
# or if upstream repository is always using consistent and sortable tag # name scheme you can get sortable version including tag name with # GITPKGVTAG, but be aware that ie tag sequence "v1.0, v1.2, xtest, v2.0" # will force you to increment PE to get upgradeable path to v2.0 revisions
classes/gitpkgv.bbclass line 30
Quoted 5 lines
classes/gitpkgv.bbclass +5
-0+# +# inherit gitpkgv +# +# PV = "1.0+gitr${SRCPV}" +# PKGV = "${GITPKGVTAG}"
# PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b # PKGV = "${GITPKGVTAG}" # expands to something like 1.0-31337+g4c1c21d
# if there is tag v1.0 before this revision or
# ver1.0-31337+g4c1c21d if there is tag ver1.0
Quoted 48 lines
classes/gitpkgv.bbclass +23
-4-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,19 @@ 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) + + commits = bb.fetch.runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True).strip() + + if use_tags: + try: + ver = git_drop_tag_prefix(bb.fetch.runfetchcmd("git describe %s 2>/dev/null" % rev, d, quiet=True).strip()) + except Exception: + ver = "0.0-%s-g%s" % commits, rev[:7] + else: + ver = "%s+%s" % commits, rev[:7] + os.chdir(cwd) - return "%s+%s" % (output.split()[0], rev) + return ver return "0+0"Signature · 7 lines
1.7.3 _______________________________________________ Openembedded-devel mailing list [email protected] http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Signature · 1 line
Martin 'JaMa' Jansa jabber: [email protected]
Quoted 7 lines · Martin Jansa
Quoted 3 lines · Otavio Salvador
Using ${GITPKGVTAG} allows for automatic versioning based on the repository tags. For those that doesn't want to use it, ${GITPKGV} is still available.
Thanks for merging it to one bbclass. IMHO looks much better now. Consider providing examples and warning as suggested bellow.
You're welcome. Thanks for keep commenting on it and helping with good advices.
...
Quoted 2 lines
# PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b # PKGV = "1.0+gitr${GITPKGV}" # expands also to something like 1.0+gitr31337+4c1c21d7dbbf93b0df336994524313dfe0d4963b
added.
...
Quoted 7 lines
As we were discussing with otavio on #oe, I think there should be warning, that GITPKGVTAG is really sortable only if the upstream repo keeps consistent AND sortable tag names.
For example tags in OE repo will fail, because only tested_2010-* tags are sortable but this sequence:
Quoted 6 lines
tested_2010-11-04
release-2010.12-branchpoint
tested_2010-11-12is not. And only way to fix it when it's shiped with non-standard tag to targets is to bump PE :/.
Yes. I fully agree that it is something the user of the class need to be aware of.
Quoted 4 lines
Even better solution would be to set something like GITTAGFORMAT in recipe, to expected consistent tag scheme and if returned git describe prefix is different then warn builder about it or even fail or ignore that tag.
I like the idea but I prefer to have this merged soon so I can started using it (for example in freerdp package) and at company.
Quoted 6 lines
Proposed "warning":
# or if upstream repository is always using consistent and sortable tag # name scheme you can get sortable version including tag name with # GITPKGVTAG, but be aware that ie tag sequence "v1.0, v1.2, xtest, v2.0" # will force you to increment PE to get upgradeable path to v2.0 revisions
I added it as a warning on the comment.
The final header is:
# gitpkgv.bbclass provides a GITPKGV and GITPKGVTAG variables to be
# used in PKGV, as described bellow:
#
# - GITPKGV 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
#
# - 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>".
#
# WARNING: if upstream repository is always using consistent and
# sortable tag name scheme you can get sortable version including tag
# name with ${GITPKGVTAG}, but be aware that ie tag sequence "v1.0,
# v1.2, xtest, v2.0" will force you to increment PE to get upgradeable
# path to v2.0 revisions
#
# use example:
#
# inherit gitpkgv
#
# PV = "1.0+gitr${SRCPV}" # expands to something like
1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b
# PKGV = "1.0+gitr${GITPKGV}" # expands also to something like
1.0+gitr31337+4c1c21d7d
#
# or
#
# inherit gitpkgv
#
# PV = "1.0+gitr${SRCPV}" # expands to something like
1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b
# PKGV = "${GITPKGVTAG}" # expands to something like 1.0-31337+g4c1c21d
# if there is tag v1.0 before this revision or
# ver1.0-31337+g4c1c21d if there is tag ver1.0Does it seems good enough for pushing 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
Martin Jansa
Acked-byQuoted 96 lines · Otavio Salvador
Quoted 7 lines · Martin Jansa
Quoted 3 lines · Otavio Salvador
Using ${GITPKGVTAG} allows for automatic versioning based on the repository tags. For those that doesn't want to use it, ${GITPKGV} is still available.
Thanks for merging it to one bbclass. IMHO looks much better now. Consider providing examples and warning as suggested bellow.
You're welcome. Thanks for keep commenting on it and helping with good advices.
...
Quoted 2 lines
# PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b # PKGV = "1.0+gitr${GITPKGV}" # expands also to something like 1.0+gitr31337+4c1c21d7dbbf93b0df336994524313dfe0d4963b
added.
...
Quoted 7 lines
As we were discussing with otavio on #oe, I think there should be warning, that GITPKGVTAG is really sortable only if the upstream repo keeps consistent AND sortable tag names.
For example tags in OE repo will fail, because only tested_2010-* tags are sortable but this sequence:
Quoted 6 lines
tested_2010-11-04
release-2010.12-branchpoint
tested_2010-11-12is not. And only way to fix it when it's shiped with non-standard tag to targets is to bump PE :/.
Yes. I fully agree that it is something the user of the class need to be aware of.
Quoted 4 lines
Even better solution would be to set something like GITTAGFORMAT in recipe, to expected consistent tag scheme and if returned git describe prefix is different then warn builder about it or even fail or ignore that tag.
I like the idea but I prefer to have this merged soon so I can started using it (for example in freerdp package) and at company.
Quoted 6 lines
Proposed "warning":
# or if upstream repository is always using consistent and sortable tag # name scheme you can get sortable version including tag name with # GITPKGVTAG, but be aware that ie tag sequence "v1.0, v1.2, xtest, v2.0" # will force you to increment PE to get upgradeable path to v2.0 revisionsI added it as a warning on the comment.
The final header is:
# gitpkgv.bbclass provides a GITPKGV and GITPKGVTAG variables to be # used in PKGV, as described bellow: # # - GITPKGV 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 # # - 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>". # # WARNING: if upstream repository is always using consistent and # sortable tag name scheme you can get sortable version including tag # name with ${GITPKGVTAG}, but be aware that ie tag sequence "v1.0, # v1.2, xtest, v2.0" will force you to increment PE to get upgradeable # path to v2.0 revisions # # use example: # # inherit gitpkgv # # PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b # PKGV = "1.0+gitr${GITPKGV}" # expands also to something like 1.0+gitr31337+4c1c21d7d # # or # # inherit gitpkgv # # PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b # PKGV = "${GITPKGVTAG}" # expands to something like 1.0-31337+g4c1c21d # if there is tag v1.0 before this revision or # ver1.0-31337+g4c1c21d if there is tag ver1.0
Quoted 1 line
Does it seems good enough for pushing it?
Yes
Signature · 1 line
Martin 'JaMa' Jansa jabber: [email protected]