summaryrefslogtreecommitdiff
path: root/meta/lib
diff options
context:
space:
mode:
authorAníbal Limón <anibal.limon@linux.intel.com>2015-06-01 16:45:25 -0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-06-03 16:33:00 +0100
commitd1683b5bb584e2b09bda76bf8523b12636d91d73 (patch)
tree1c1afa25534faaf84903c65478e210fba25b66a5 /meta/lib
parent729592223a0c076abe2c58a0cf3f4c6d6583602c (diff)
downloadopenembedded-core-d1683b5bb584e2b09bda76bf8523b12636d91d73.tar.gz
openembedded-core-d1683b5bb584e2b09bda76bf8523b12636d91d73.tar.bz2
openembedded-core-d1683b5bb584e2b09bda76bf8523b12636d91d73.zip
recipeutils: Add get_recipe_upstream_version and get_recipe_pv_without_srcpv functions
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>
Diffstat (limited to 'meta/lib')
-rw-r--r--meta/lib/oe/recipeutils.py96
1 files changed, 96 insertions, 0 deletions
diff --git a/meta/lib/oe/recipeutils.py b/meta/lib/oe/recipeutils.py
index f05b6c06ba..37efefb093 100644
--- a/meta/lib/oe/recipeutils.py
+++ b/meta/lib/oe/recipeutils.py
@@ -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