diff options
Diffstat (limited to 'meta-oe/classes/gitpkgv.bbclass')
-rw-r--r-- | meta-oe/classes/gitpkgv.bbclass | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/meta-oe/classes/gitpkgv.bbclass b/meta-oe/classes/gitpkgv.bbclass index 2d9680a35c..5ab507969c 100644 --- a/meta-oe/classes/gitpkgv.bbclass +++ b/meta-oe/classes/gitpkgv.bbclass @@ -7,8 +7,8 @@ # 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 +# - GITPKGVTAG which is the output of 'git describe --tags --exact-match' +# allowing for automatic versioning # # gitpkgv.bbclass assumes the git repository has been cloned, and # contains SRCREV. So ${GITPKGV} and ${GITPKGVTAG} should never be @@ -25,32 +25,38 @@ # # 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 +# PV = "1.0+git" # expands to 1.0+git +# PKGV = "1.0+git${GITPKGV}" # expands also to something like 1.0+git31337+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 +# PV = "1.0+git" # expands to 1.0+git +# 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 GITPKGV = "${@get_git_pkgv(d, False)}" GITPKGVTAG = "${@get_git_pkgv(d, True)}" -def gitpkgv_drop_tag_prefix(version): +# This regexp is used to drop unwanted parts of the found tags. Any matching +# groups will be concatenated to yield the final version. +GITPKGV_TAG_REGEXP ??= "v(\d.*)" + +def gitpkgv_drop_tag_prefix(d, version): import re - if re.match("v\d", version): - return version[1:] + + m = re.match(d.getVar('GITPKGV_TAG_REGEXP'), version) + if m: + return ''.join(group for group in m.groups() if group) else: return version def get_git_pkgv(d, use_tags): import os import bb - from pipes import quote + from shlex import quote src_uri = d.getVar('SRC_URI').split() fetcher = bb.fetch2.Fetch(src_uri, d) @@ -87,10 +93,8 @@ def get_git_pkgv(d, use_tags): if not os.path.exists(rev_file) or os.path.getsize(rev_file)==0: commits = bb.fetch2.runfetchcmd( - "cd %(repodir)s && " - "git rev-list %(rev)s -- 2> /dev/null " - "| wc -l" % vars, - d, quiet=True).strip().lstrip('0') + "git --git-dir=%(repodir)s rev-list %(rev)s -- 2>/dev/null | wc -l" + % vars, d, quiet=True).strip().lstrip('0') if commits != "": oe.path.remove(rev_file, recurse=False) @@ -105,10 +109,9 @@ def get_git_pkgv(d, use_tags): if use_tags: try: output = bb.fetch2.runfetchcmd( - "cd %(repodir)s && " - "git describe %(rev)s 2>/dev/null" % vars, - d, quiet=True).strip() - ver = gitpkgv_drop_tag_prefix(output) + "git --git-dir=%(repodir)s describe %(rev)s --tags --exact-match 2>/dev/null" + % vars, d, quiet=True).strip() + ver = gitpkgv_drop_tag_prefix(d, output) except Exception: ver = "0.0-%s-g%s" % (commits, vars['rev'][:7]) else: |