1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-09 17:39:31 +00:00

bitbake: fetch2: wget latest_versionstring improvments in get version by dir

Add support for scan every version directory using _check_latest_version
makes code more robust because sometimes upstream projects publish
new directories without files, causing don't find version.

To support this new behaviour remove _check_latest_dir and replace for
_check_latest_version_by_dir,

(Bitbake rev: 1a75b3707743c32eec9d2cf566fb6bbea9f73784)

Signed-off-by: Aníbal Limón <anibal.limon@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Aníbal Limón
2015-02-13 15:58:11 -06:00
committed by Richard Purdie
parent 62e171b721
commit 22cebb87b7
+36 -70
View File
@@ -113,7 +113,6 @@ class Wget(FetchMethod):
""" """
Find and group name, version and archive type in the given string s Find and group name, version and archive type in the given string s
""" """
bb.debug(3, "_parse_path(%s, %s)" % (regex.pattern, s))
m = regex.search(s) m = regex.search(s)
if m: if m:
@@ -199,44 +198,6 @@ class Wget(FetchMethod):
f.close() f.close()
return fetchresult return fetchresult
def _check_latest_dir(self, url, versionstring, ud, d):
"""
Return the name of the directory with the greatest package version
If error or no version, return None
"""
bb.debug(3, "DirURL: %s, %s" % (url, versionstring))
soup = BeautifulSoup(self._fetch_index(url, ud, d))
if not soup:
return None
valid = 0
prefix = ''
regex = re.compile("(\D*)((\d+[\.\-_])+(\d+))")
m = regex.search(versionstring)
if m:
version = ('', m.group(2), '')
prefix = m.group(1)
bb.debug(3, "version: %s, prefix: %s" % (version, prefix))
else:
version = ('', versionstring, '')
for href in soup.find_all('a', href=True):
bb.debug(3, "href: %s" % (href['href']))
if href['href'].find(versionstring) >= 0:
valid = 1
m = regex.search(href['href'].strip("/"))
if m:
thisversion = ('', m.group(2), '')
if thisversion and self._vercmp(version, thisversion) < 0:
version = thisversion
if valid:
bb.debug(3, "Would return %s" % (prefix+version[1]))
return prefix+version[1]
else:
bb.debug(3, "Not Valid")
return None
def _check_latest_version(self, url, package, package_regex, current_version, ud, d): def _check_latest_version(self, url, package, package_regex, current_version, ud, d):
""" """
Return the latest version of a package inside a given directory path Return the latest version of a package inside a given directory path
@@ -252,8 +213,8 @@ class Wget(FetchMethod):
return "" return ""
for line in soup.find_all('a', href=True): for line in soup.find_all('a', href=True):
bb.debug(3, "line = '%s'" % (str(line)))
bb.debug(3, "line['href'] = '%s'" % (line['href'])) bb.debug(3, "line['href'] = '%s'" % (line['href']))
bb.debug(3, "line = '%s'" % (str(line)))
newver = self._parse_path(package_regex, line['href']) newver = self._parse_path(package_regex, line['href'])
if not newver: if not newver:
@@ -267,12 +228,13 @@ class Wget(FetchMethod):
elif self._vercmp(version, newver) < 0: elif self._vercmp(version, newver) < 0:
version = newver version = newver
# check whether a valid package and version were found pupver = re.sub('_', '.', version[1])
bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" % bb.debug(3, "*** %s -> UpstreamVersion = %s (CurrentVersion = %s)" %
(package, version[1] or "N/A", current_version[1])) (package, pupver or "N/A", current_version[1]))
if valid: if valid:
return re.sub('_', '.', version[1]) return pupver
return "" return ""
@@ -353,14 +315,10 @@ class Wget(FetchMethod):
psuffix_regex = "(tar\.gz|tgz|tar\.bz2|zip|xz|rpm|bz2|orig\.tar\.gz|tar\.xz|src\.tar\.gz|src\.tgz|svnr\d+\.tar\.bz2|stable\.tar\.gz|src\.rpm)" psuffix_regex = "(tar\.gz|tgz|tar\.bz2|zip|xz|rpm|bz2|orig\.tar\.gz|tar\.xz|src\.tar\.gz|src\.tgz|svnr\d+\.tar\.bz2|stable\.tar\.gz|src\.rpm)"
# match name, version and archive type of a package # match name, version and archive type of a package
package_regex_comp = re.compile("(?P<name>%s?)\.?v?(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s$)" package_regex_comp = re.compile("(?P<name>%s?\.?v?)(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s$)"
% (pn_regex, pver_regex, parch_regex, psuffix_regex)) % (pn_regex, pver_regex, parch_regex, psuffix_regex))
self.suffix_regex_comp = re.compile(psuffix_regex) self.suffix_regex_comp = re.compile(psuffix_regex)
# search for version matches on folders inside the path, like:
# "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
self.dirver_regex_comp = re.compile("(?P<dirver>[^/]*(\d+\.)*\d+([\-_]r\d+)*)/")
# compile regex, can be specific by package or generic regex # compile regex, can be specific by package or generic regex
pn_regex = d.getVar('REGEX', True) pn_regex = d.getVar('REGEX', True)
if pn_regex: if pn_regex:
@@ -369,10 +327,10 @@ class Wget(FetchMethod):
version = self._parse_path(package_regex_comp, package) version = self._parse_path(package_regex_comp, package)
if version: if version:
package_custom_regex_comp = re.compile( package_custom_regex_comp = re.compile(
"(?P<name>%s)(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s)$" % "(?P<name>%s)(?P<pver>%s)(?P<arch>%s)?[\.\-](?P<type>%s)" %
(re.escape(version[0]), pver_regex, parch_regex, psuffix_regex)) (re.escape(version[0]), pver_regex, parch_regex, psuffix_regex))
else: else:
package_custom_regex_comp = package_regex_comp package_custom_regex_comp = None
return package_custom_regex_comp return package_custom_regex_comp
@@ -383,33 +341,41 @@ class Wget(FetchMethod):
sanity check to ensure same name and type. sanity check to ensure same name and type.
""" """
package = ud.path.split("/")[-1] package = ud.path.split("/")[-1]
regex_uri = d.getVar("REGEX_URI", True) current_version = ['', d.getVar('PV', True), '']
newpath = regex_uri or ud.path
pupver = ""
package_regex = self._init_regexes(package, ud, d)
current_version = ('', d.getVar('PV', True), '')
"""possible to have no version in pkg name, such as spectrum-fw""" """possible to have no version in pkg name, such as spectrum-fw"""
if not re.search("\d+", package): if not re.search("\d+", package):
return re.sub('_', '.', current_version[1]) current_version[1] = re.sub('_', '.', current_version[1])
current_version[1] = re.sub('-', '.', current_version[1])
return current_version[1]
package_regex = self._init_regexes(package, ud, d)
if package_regex is None:
bb.warn("latest_versionstring: package %s don't match pattern" % (package))
return ""
bb.debug(3, "latest_versionstring, regex: %s" % (package_regex.pattern))
uri = ""
regex_uri = d.getVar("REGEX_URI", True)
if not regex_uri: if not regex_uri:
# generate the new uri with the appropriate latest directory path = ud.path.split(package)[0]
m = self.dirver_regex_comp.search(ud.path)
# search for version matches on folders inside the path, like:
# "5.7" in http://download.gnome.org/sources/${PN}/5.7/${PN}-${PV}.tar.gz
dirver_regex = re.compile("(?P<dirver>[^/]*(\d+\.)*\d+([\-_]r\d+)*)/")
m = dirver_regex.search(path)
if m: if m:
pn = d.getVar('PN', True)
dirver = m.group('dirver') dirver = m.group('dirver')
newuri = bb.fetch.encodeurl([ud.type, ud.host,
ud.path.split(dirver)[0], ud.user, ud.pswd, {}])
new_dirver = self._check_latest_dir(newuri, dirver, ud, d)
if new_dirver and dirver != new_dirver:
newpath = ud.path.replace(dirver, new_dirver, True)
newpath = newpath.split(package)[0] or "/" # path to directory dirver_pn_regex = re.compile("%s\d?" % (re.escape(pn)))
newuri = bb.fetch.encodeurl([ud.type, ud.host, newpath, ud.user, ud.pswd, {}]) if not dirver_pn_regex.search(dirver):
return self._check_latest_version_by_dir(dirver,
package, package_regex, current_version, ud, d)
uri = bb.fetch.encodeurl([ud.type, ud.host, path, ud.user, ud.pswd, {}])
else: else:
newuri = newpath uri = regex_uri
return self._check_latest_version(newuri, package, package_regex, return self._check_latest_version(uri, package, package_regex,
current_version, ud, d) current_version, ud, d)