aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Kanavin <alex.kanavin@gmail.com>2024-04-19 14:17:13 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2024-04-20 07:36:21 +0100
commit73d3c758178ff31aa41ed32eb47b3a5b3d68a33b (patch)
tree6852f2cbf994f4576847b5e3360782e23c8ba21d
parent81b394874771019f0d14d42fbd0cd242b6d75ae4 (diff)
downloadbitbake-master-next.tar.gz
fetch2/crate: add upstream latest version check functionmaster-next
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 Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/fetch2/crate.py9
-rw-r--r--lib/bb/tests/fetch.py16
2 files changed, 25 insertions, 0 deletions
diff --git a/lib/bb/fetch2/crate.py b/lib/bb/fetch2/crate.py
index 01d49435c..e611736f0 100644
--- a/lib/bb/fetch2/crate.py
+++ b/lib/bb/fetch2/crate.py
@@ -70,6 +70,7 @@ class Crate(Wget):
host = 'crates.io/api/v1/crates'
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)
if 'name' not in ud.parm:
ud.parm['name'] = '%s-%s' % (name, version)
@@ -139,3 +140,11 @@ class Crate(Wget):
mdpath = os.path.join(bbpath, cratepath, mdfile)
with open(mdpath, "w") as 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], "")
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 85c1f79ff..e5d85f9da 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -1493,6 +1493,12 @@ class FetchLatestVersionTest(FetcherTest):
: "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()
def test_git_latest_versionstring(self):
for k, v in self.test_git_uris.items():
@@ -1532,6 +1538,16 @@ class FetchLatestVersionTest(FetcherTest):
finally:
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):
test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz",