mirror of
https://git.yoctoproject.org/poky
synced 2026-05-09 05:29:32 +00:00
bitbake: fetch2/crate: add upstream latest version check function
This is actually rather easy: crate web API provides a json with all the versions, for example: https://crates.io/api/v1/crates/cargo-c/versions (Bitbake rev: f6c2755db9a1f88c8534193b420fa31d135945e6) Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
committed by
Richard Purdie
parent
f6de2b033d
commit
551fdabc54
@@ -70,6 +70,7 @@ class Crate(Wget):
|
|||||||
host = 'crates.io/api/v1/crates'
|
host = 'crates.io/api/v1/crates'
|
||||||
|
|
||||||
ud.url = "https://%s/%s/%s/download" % (host, name, version)
|
ud.url = "https://%s/%s/%s/download" % (host, name, version)
|
||||||
|
ud.versionsurl = "https://%s/%s/versions" % (host, name)
|
||||||
ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version)
|
ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version)
|
||||||
if 'name' not in ud.parm:
|
if 'name' not in ud.parm:
|
||||||
ud.parm['name'] = '%s-%s' % (name, version)
|
ud.parm['name'] = '%s-%s' % (name, version)
|
||||||
@@ -139,3 +140,11 @@ class Crate(Wget):
|
|||||||
mdpath = os.path.join(bbpath, cratepath, mdfile)
|
mdpath = os.path.join(bbpath, cratepath, mdfile)
|
||||||
with open(mdpath, "w") as f:
|
with open(mdpath, "w") as f:
|
||||||
json.dump(metadata, f)
|
json.dump(metadata, f)
|
||||||
|
|
||||||
|
def latest_versionstring(self, ud, d):
|
||||||
|
from functools import cmp_to_key
|
||||||
|
json_data = json.loads(self._fetch_index(ud.versionsurl, ud, d))
|
||||||
|
versions = [(0, i["num"], "") for i in json_data["versions"]]
|
||||||
|
versions = sorted(versions, key=cmp_to_key(bb.utils.vercmp))
|
||||||
|
|
||||||
|
return (versions[-1][1], "")
|
||||||
|
|||||||
@@ -1493,6 +1493,12 @@ class FetchLatestVersionTest(FetcherTest):
|
|||||||
: "2.8",
|
: "2.8",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test_crate_uris = {
|
||||||
|
# basic example; version pattern "A.B.C+cargo-D.E.F"
|
||||||
|
("cargo-c", "crate://crates.io/cargo-c/0.9.18+cargo-0.69")
|
||||||
|
: "0.9.29"
|
||||||
|
}
|
||||||
|
|
||||||
@skipIfNoNetwork()
|
@skipIfNoNetwork()
|
||||||
def test_git_latest_versionstring(self):
|
def test_git_latest_versionstring(self):
|
||||||
for k, v in self.test_git_uris.items():
|
for k, v in self.test_git_uris.items():
|
||||||
@@ -1532,6 +1538,16 @@ class FetchLatestVersionTest(FetcherTest):
|
|||||||
finally:
|
finally:
|
||||||
server.stop()
|
server.stop()
|
||||||
|
|
||||||
|
@skipIfNoNetwork()
|
||||||
|
def test_crate_latest_versionstring(self):
|
||||||
|
for k, v in self.test_crate_uris.items():
|
||||||
|
self.d.setVar("PN", k[0])
|
||||||
|
ud = bb.fetch2.FetchData(k[1], self.d)
|
||||||
|
pupver = ud.method.latest_versionstring(ud, self.d)
|
||||||
|
verstring = pupver[0]
|
||||||
|
self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0])
|
||||||
|
r = bb.utils.vercmp_string(v, verstring)
|
||||||
|
self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring))
|
||||||
|
|
||||||
class FetchCheckStatusTest(FetcherTest):
|
class FetchCheckStatusTest(FetcherTest):
|
||||||
test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
|
test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",
|
||||||
|
|||||||
Reference in New Issue
Block a user