diff options
author | Alexander Kanavin <alex.kanavin@gmail.com> | 2024-04-19 14:17:13 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-05-08 14:51:43 +0100 |
commit | 551fdabc54f34b6ffa940dfd616b44ef4858277d (patch) | |
tree | 072780439e91f9a6d09658769d6b198bd6eaa064 /bitbake | |
parent | f6de2b033d32c0f92f19f5a4a8c4c8874a00a8f7 (diff) | |
download | poky-551fdabc54f34b6ffa940dfd616b44ef4858277d.tar.gz |
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>
Diffstat (limited to 'bitbake')
-rw-r--r-- | bitbake/lib/bb/fetch2/crate.py | 9 | ||||
-rw-r--r-- | bitbake/lib/bb/tests/fetch.py | 16 |
2 files changed, 25 insertions, 0 deletions
diff --git a/bitbake/lib/bb/fetch2/crate.py b/bitbake/lib/bb/fetch2/crate.py index 01d49435c3..e611736f06 100644 --- a/bitbake/lib/bb/fetch2/crate.py +++ b/bitbake/lib/bb/fetch2/crate.py | |||
@@ -70,6 +70,7 @@ class Crate(Wget): | |||
70 | host = 'crates.io/api/v1/crates' | 70 | host = 'crates.io/api/v1/crates' |
71 | 71 | ||
72 | ud.url = "https://%s/%s/%s/download" % (host, name, version) | 72 | ud.url = "https://%s/%s/%s/download" % (host, name, version) |
73 | ud.versionsurl = "https://%s/%s/versions" % (host, name) | ||
73 | ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version) | 74 | ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version) |
74 | if 'name' not in ud.parm: | 75 | if 'name' not in ud.parm: |
75 | ud.parm['name'] = '%s-%s' % (name, version) | 76 | ud.parm['name'] = '%s-%s' % (name, version) |
@@ -139,3 +140,11 @@ class Crate(Wget): | |||
139 | mdpath = os.path.join(bbpath, cratepath, mdfile) | 140 | mdpath = os.path.join(bbpath, cratepath, mdfile) |
140 | with open(mdpath, "w") as f: | 141 | with open(mdpath, "w") as f: |
141 | json.dump(metadata, f) | 142 | json.dump(metadata, f) |
143 | |||
144 | def latest_versionstring(self, ud, d): | ||
145 | from functools import cmp_to_key | ||
146 | json_data = json.loads(self._fetch_index(ud.versionsurl, ud, d)) | ||
147 | versions = [(0, i["num"], "") for i in json_data["versions"]] | ||
148 | versions = sorted(versions, key=cmp_to_key(bb.utils.vercmp)) | ||
149 | |||
150 | return (versions[-1][1], "") | ||
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py index 85c1f79ff3..e5d85f9dac 100644 --- a/bitbake/lib/bb/tests/fetch.py +++ b/bitbake/lib/bb/tests/fetch.py | |||
@@ -1493,6 +1493,12 @@ class FetchLatestVersionTest(FetcherTest): | |||
1493 | : "2.8", | 1493 | : "2.8", |
1494 | } | 1494 | } |
1495 | 1495 | ||
1496 | test_crate_uris = { | ||
1497 | # basic example; version pattern "A.B.C+cargo-D.E.F" | ||
1498 | ("cargo-c", "crate://crates.io/cargo-c/0.9.18+cargo-0.69") | ||
1499 | : "0.9.29" | ||
1500 | } | ||
1501 | |||
1496 | @skipIfNoNetwork() | 1502 | @skipIfNoNetwork() |
1497 | def test_git_latest_versionstring(self): | 1503 | def test_git_latest_versionstring(self): |
1498 | for k, v in self.test_git_uris.items(): | 1504 | for k, v in self.test_git_uris.items(): |
@@ -1532,6 +1538,16 @@ class FetchLatestVersionTest(FetcherTest): | |||
1532 | finally: | 1538 | finally: |
1533 | server.stop() | 1539 | server.stop() |
1534 | 1540 | ||
1541 | @skipIfNoNetwork() | ||
1542 | def test_crate_latest_versionstring(self): | ||
1543 | for k, v in self.test_crate_uris.items(): | ||
1544 | self.d.setVar("PN", k[0]) | ||
1545 | ud = bb.fetch2.FetchData(k[1], self.d) | ||
1546 | pupver = ud.method.latest_versionstring(ud, self.d) | ||
1547 | verstring = pupver[0] | ||
1548 | self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) | ||
1549 | r = bb.utils.vercmp_string(v, verstring) | ||
1550 | self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) | ||
1535 | 1551 | ||
1536 | class FetchCheckStatusTest(FetcherTest): | 1552 | class FetchCheckStatusTest(FetcherTest): |
1537 | test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", | 1553 | test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", |