]> code.ossystems Code Review - openembedded-core.git/commitdiff
recipeutils: Add get_recipe_upstream_version and get_recipe_pv_without_srcpv functions
authorAníbal Limón <anibal.limon@linux.intel.com>
Mon, 1 Jun 2015 21:45:25 +0000 (16:45 -0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Wed, 3 Jun 2015 15:33:00 +0000 (16:33 +0100)
The get_recipe_upstream_version functions tries to get the current
version of recipe in upstream it uses bb.fetch2 latest_versionstring
method also latest_revision when is SCM.

The get_recipe_pv_without_srcpv discards the SRCPV in SCM's recipe like
git it returns a tuple with the version, prefix and suffix of a PV.

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
meta/lib/oe/recipeutils.py

index f05b6c06ba6594f5895a903a3a82583f18fd0582..37efefb0930a1eda5730d131e9d91aca1157ed7e 100644 (file)
@@ -626,3 +626,99 @@ def replace_dir_vars(path, d):
         path = path.replace(dirpath, '${%s}' % dirvars[dirpath])
     return path
 
+def get_recipe_pv_without_srcpv(rd, uri_type):
+    """
+    Get PV without SRCPV common in SCM's for now only
+    support git.
+
+    Returns tuple with pv, prefix and suffix.
+    """
+    pv = ''
+    pfx = ''
+    sfx = ''
+
+    if uri_type == 'git':
+        rd_tmp = rd.createCopy()
+
+        rd_tmp.setVar('SRCPV', '')
+        pv = rd_tmp.getVar('PV', True)
+
+        git_regex = re.compile("(?P<pfx>(v|))(?P<ver>((\d+[\.\-_]*)+))(?P<sfx>(\+|)(git|)(r|)(AUTOINC|)(\+|))(?P<rev>.*)")
+        m = git_regex.match(pv)
+
+        if m:
+            pv = m.group('ver')
+            pfx = m.group('pfx')
+            sfx = m.group('sfx')
+    else:
+        pv = rd.getVar('PV', True)
+
+    return (pv, pfx, sfx)
+
+def get_recipe_upstream_version(rd):
+    """
+        Get upstream version of recipe using bb.fetch2 methods with support for
+        http, https, ftp and git.
+
+        bb.fetch2 exceptions can be raised,
+            FetchError when don't have network access or upstream site don't response.
+            NoMethodError when uri latest_versionstring method isn't implemented.
+
+        Returns a dictonary with version, type and datetime.
+        Type can be A for Automatic, M for Manual and U for Unknown.
+    """
+    from bb.fetch2 import decodeurl
+    from datetime import datetime
+
+    ru = {}
+    ru['version'] = ''
+    ru['type'] = 'U'
+    ru['datetime'] = ''
+
+    # XXX: we suppose that the first entry points to the upstream sources
+    src_uri = rd.getVar('SRC_URI', True).split()[0] 
+    uri_type, _, _, _, _, _ =  decodeurl(src_uri)
+
+    pv = rd.getVar('PV', True)
+
+    manual_upstream_version = rd.getVar("RECIPE_UPSTREAM_VERSION", True)
+    if manual_upstream_version:
+        # manual tracking of upstream version.
+        ru['version'] = manual_upstream_version
+        ru['type'] = 'M'
+
+        manual_upstream_date = rd.getVar("CHECK_DATE", True)
+        if manual_upstream_date:
+            date = datetime.strptime(manual_upstream_date, "%b %d, %Y")
+        else:
+            date = datetime.now()
+        ru['datetime'] = date
+
+    elif uri_type == "file":
+        # files are always up-to-date
+        ru['version'] =  pv
+        ru['type'] = 'A'
+        ru['datetime'] = datetime.now()
+    else:
+        ud = bb.fetch2.FetchData(src_uri, rd)
+        pupver = ud.method.latest_versionstring(ud, rd)
+
+        if uri_type == 'git':
+            (pv, pfx, sfx) = get_recipe_pv_without_srcpv(rd, uri_type)
+
+            latest_revision = ud.method.latest_revision(ud, rd, ud.names[0])
+
+            # if contains revision but not pupver use current pv
+            if pupver == '' and latest_revision:
+                pupver = pv
+
+            if pupver != '':
+                pupver = pfx + pupver + sfx + latest_revision[:10]
+
+        if pupver != '':
+            ru['version'] = pupver
+            ru['type'] = 'A'
+
+        ru['datetime'] = datetime.now()
+
+    return ru