From 7587877e5d683a30c2bd5e1ac1c4e327fac1ee1c Mon Sep 17 00:00:00 2001 From: Aníbal Limón Date: Wed, 5 Nov 2014 12:10:28 -0600 Subject: bitbake: fetch/git: Add latest_versionstring method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Being able to generate a version string representing the most recent git commit given git is useful, not least for the package reporting system. This adds in a latest_versionstring method to the git fetcher which allows users to query the latest version using ls-remote and filtering the responses. The patch also adds unittests for this function so that if improvements are made, the original test urls can be used to evaulate the those changes. This is based on code from Irina Patru . (Bitbake rev: f71c8c0354e87fed80bc845db6728e6e18ce9c4d) Signed-off-by: Saul Wold Signed-off-by: Aníbal Limón Signed-off-by: Richard Purdie --- bitbake/lib/bb/fetch2/git.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'bitbake/lib/bb/fetch2/git.py') diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py index 66a77a8376..f771fd02b6 100644 --- a/bitbake/lib/bb/fetch2/git.py +++ b/bitbake/lib/bb/fetch2/git.py @@ -67,6 +67,7 @@ Supported SRC_URI options are: # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os +import re import bb from bb import data from bb.fetch2 import FetchMethod @@ -346,6 +347,43 @@ class Git(FetchMethod): output = self._lsremote(ud, d, search) return output.split()[0] + def latest_versionstring(self, ud, d): + """ + Compute the latest release name like "x.y.x" in "x.y.x+gitHASH" + by searching through the tags output of ls-remote, comparing + versions and returning the highest match. + """ + verstring = "" + tagregex = re.compile(d.getVar('GITTAGREGEX', True) or "(?P([0-9][\.|_]?)+)") + try: + output = self._lsremote(ud, d, "refs/tags/*^{}") + except bb.fetch2.FetchError or bb.fetch2.NetworkAccess: + return "" + + for line in output.split("\n"): + if not line: + break + + line = line.split("/")[-1] + # Ignore non-released branches + m = re.search("(alpha|beta|rc|final)+", line) + if m: + continue + + # search for version in the line + tag = tagregex.search(line) + if tag == None: + continue + + tag = tag.group('pver') + tag = tag.replace("_", ".") + + if verstring and bb.utils.vercmp(("0", tag, ""), ("0", verstring, "")) < 0: + continue + verstring = tag + + return verstring + def _build_revision(self, ud, d, name): return ud.revisions[name] -- cgit v1.2.3-54-g00ecf