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.

(From OE-Core rev: d1683b5bb584e2b09bda76bf8523b12636d91d73)

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Aníbal Limón 2015-06-01 16:45:25 -05:00 committed by Richard Purdie
parent 7cd3c6028c
commit 8c6bd8a843
1 changed files with 96 additions and 0 deletions

View 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