diff options
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oe/recipeutils.py | 96 |
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 |