summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/fetch2/git.py38
-rw-r--r--bitbake/lib/bb/tests/fetch.py44
2 files changed, 81 insertions, 1 deletions
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:
67# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 67# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
68 68
69import os 69import os
70import re
70import bb 71import bb
71from bb import data 72from bb import data
72from bb.fetch2 import FetchMethod 73from bb.fetch2 import FetchMethod
@@ -346,6 +347,43 @@ class Git(FetchMethod):
346 output = self._lsremote(ud, d, search) 347 output = self._lsremote(ud, d, search)
347 return output.split()[0] 348 return output.split()[0]
348 349
350 def latest_versionstring(self, ud, d):
351 """
352 Compute the latest release name like "x.y.x" in "x.y.x+gitHASH"
353 by searching through the tags output of ls-remote, comparing
354 versions and returning the highest match.
355 """
356 verstring = ""
357 tagregex = re.compile(d.getVar('GITTAGREGEX', True) or "(?P<pver>([0-9][\.|_]?)+)")
358 try:
359 output = self._lsremote(ud, d, "refs/tags/*^{}")
360 except bb.fetch2.FetchError or bb.fetch2.NetworkAccess:
361 return ""
362
363 for line in output.split("\n"):
364 if not line:
365 break
366
367 line = line.split("/")[-1]
368 # Ignore non-released branches
369 m = re.search("(alpha|beta|rc|final)+", line)
370 if m:
371 continue
372
373 # search for version in the line
374 tag = tagregex.search(line)
375 if tag == None:
376 continue
377
378 tag = tag.group('pver')
379 tag = tag.replace("_", ".")
380
381 if verstring and bb.utils.vercmp(("0", tag, ""), ("0", verstring, "")) < 0:
382 continue
383 verstring = tag
384
385 return verstring
386
349 def _build_revision(self, ud, d, name): 387 def _build_revision(self, ud, d, name):
350 return ud.revisions[name] 388 return ud.revisions[name]
351 389
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index d95b43a5e3..aa9b222612 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -24,6 +24,7 @@ import tempfile
24import subprocess 24import subprocess
25import os 25import os
26from bb.fetch2 import URI 26from bb.fetch2 import URI
27from bb.fetch2 import FetchMethod
27import bb 28import bb
28 29
29class URITest(unittest.TestCase): 30class URITest(unittest.TestCase):
@@ -565,5 +566,46 @@ class URLHandle(unittest.TestCase):
565 result = bb.fetch.encodeurl(v) 566 result = bb.fetch.encodeurl(v)
566 self.assertEqual(result, k) 567 self.assertEqual(result, k)
567 568
569class FetchMethodTest(FetcherTest):
570
571 test_git_uris = {
572 # version pattern "X.Y.Z"
573 ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4", "9b1db6b8060bd00b121a692f942404a24ae2960f", "")
574 : "1.99.4",
575 # version pattern "vX.Y"
576 ("mtd-utils", "git://git.infradead.org/mtd-utils.git", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "")
577 : "1.5.0",
578 # version pattern "pkg_name-X.Y"
579 ("presentproto", "git://anongit.freedesktop.org/git/xorg/proto/presentproto", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "")
580 : "1.0",
581 # version pattern "pkg_name-vX.Y.Z"
582 ("dtc", "git://git.qemu.org/dtc.git", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "")
583 : "1.4.0",
584 # combination version pattern
585 ("sysprof", "git://git.gnome.org/sysprof", "cd44ee6644c3641507fb53b8a2a69137f2971219", "")
586 : "1.2.0",
587 ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "")
588 : "2014.01",
589 # version pattern "yyyymmdd"
590 ("mobile-broadband-provider-info", "git://git.gnome.org/mobile-broadband-provider-info", "4ed19e11c2975105b71b956440acdb25d46a347d", "")
591 : "20120614",
592 # packages with a valid GITTAGREGEX
593 ("xf86-video-omap", "git://anongit.freedesktop.org/xorg/driver/xf86-video-omap", "ae0394e687f1a77e966cf72f895da91840dffb8f", "(?P<pver>(\d+\.(\d\.?)*))")
594 : "0.4.3",
595 ("build-appliance-image", "git://git.yoctoproject.org/poky", "b37dd451a52622d5b570183a81583cc34c2ff555", "(?P<pver>(([0-9][\.|_]?)+[0-9]))")
596 : "11.0.0",
597 ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot", "cd437ecbd8986c894442f8fce1e0061e20f04dee", "chkconfig\-(?P<pver>((\d+[\.\-_]*)+))")
598 : "1.3.59",
599 ("remake", "git://github.com/rocky/remake.git", "f05508e521987c8494c92d9c2871aec46307d51d", "(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))")
600 : "3.82+dbg0.9",
601 }
568 602
569 603 def test_git_latest_versionstring(self):
604 for k, v in self.test_git_uris.items():
605 self.d.setVar("SRCREV", k[2])
606 self.d.setVar("GITTAGREGEX", k[3])
607 ud = bb.fetch2.FetchData(k[1], self.d)
608 verstring = ud.method.latest_versionstring(ud, self.d)
609 print("Package %s, version: %s <= %s" % (k[0], v, verstring))
610 r = bb.utils.vercmp_string(v, verstring)
611 self.assertTrue(r == -1 or r == 0)