summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb
diff options
context:
space:
mode:
authorFrederic Martinsons <frederic.martinsons@gmail.com>2023-03-15 14:40:29 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-03-17 17:20:05 +0000
commitee5e6a86fd0d2f81a6a3db4fba7ec5158555e595 (patch)
tree02ec29c630883b3aa162fd885be55f728b74ad2d /bitbake/lib/bb
parentdc2ac3ca4f8146e8f75682543596639a537e5695 (diff)
downloadpoky-ee5e6a86fd0d2f81a6a3db4fba7ec5158555e595.tar.gz
bitbake: crate.py: authorize crate url with parameters
This allow to have classic fetch parameters (like destsuffix, sha256, name ...) not being considered by crate fetcher itself (and so mess up its download) Moreover, it allow to overload the name of the downloaded crate (maybe usefull if there is a naming clash between two crates coming from different repositories) (Bitbake rev: 278bd2f1758b8af97552af8d23d16ffb5127a131) Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb')
-rw-r--r--bitbake/lib/bb/fetch2/crate.py9
-rw-r--r--bitbake/lib/bb/tests/fetch.py24
2 files changed, 30 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/crate.py b/bitbake/lib/bb/fetch2/crate.py
index f091200dd9..2889e39c73 100644
--- a/bitbake/lib/bb/fetch2/crate.py
+++ b/bitbake/lib/bb/fetch2/crate.py
@@ -56,8 +56,10 @@ class Crate(Wget):
56 if len(parts) < 5: 56 if len(parts) < 5:
57 raise bb.fetch2.ParameterError("Invalid URL: Must be crate://HOST/NAME/VERSION", ud.url) 57 raise bb.fetch2.ParameterError("Invalid URL: Must be crate://HOST/NAME/VERSION", ud.url)
58 58
59 # last field is version 59 # version is expected to be the last token
60 version = parts[len(parts) - 1] 60 # but ignore possible url parameters which will be used
61 # by the top fetcher class
62 version, _, _ = parts[len(parts) -1].partition(";")
61 # second to last field is name 63 # second to last field is name
62 name = parts[len(parts) - 2] 64 name = parts[len(parts) - 2]
63 # host (this is to allow custom crate registries to be specified 65 # host (this is to allow custom crate registries to be specified
@@ -69,7 +71,8 @@ class Crate(Wget):
69 71
70 ud.url = "https://%s/%s/%s/download" % (host, name, version) 72 ud.url = "https://%s/%s/%s/download" % (host, name, version)
71 ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version) 73 ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version)
72 ud.parm['name'] = name 74 if 'name' not in ud.parm:
75 ud.parm['name'] = name
73 76
74 logger.debug2("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename'])) 77 logger.debug2("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename']))
75 78
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 73eefc5938..1533d52b1e 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -2385,6 +2385,30 @@ class CrateTest(FetcherTest):
2385 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs")) 2385 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
2386 2386
2387 @skipIfNoNetwork() 2387 @skipIfNoNetwork()
2388 def test_crate_url_params(self):
2389
2390 uri = "crate://crates.io/aho-corasick/0.7.20;name=aho-corasick-renamed"
2391 self.d.setVar('SRC_URI', uri)
2392
2393 uris = self.d.getVar('SRC_URI').split()
2394 d = self.d
2395
2396 fetcher = bb.fetch2.Fetch(uris, self.d)
2397 ud = fetcher.ud[fetcher.urls[0]]
2398
2399 self.assertIn("name", ud.parm)
2400 self.assertEqual(ud.parm["name"], "aho-corasick-renamed")
2401 self.assertIn("downloadfilename", ud.parm)
2402 self.assertEqual(ud.parm["downloadfilename"], "aho-corasick-0.7.20.crate")
2403
2404 fetcher.download()
2405 fetcher.unpack(self.tempdir)
2406 self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
2407 self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['aho-corasick-0.7.20.crate', 'aho-corasick-0.7.20.crate.done'])
2408 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/.cargo-checksum.json"))
2409 self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/src/lib.rs"))
2410
2411 @skipIfNoNetwork()
2388 def test_crate_url_multi(self): 2412 def test_crate_url_multi(self):
2389 2413
2390 uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35" 2414 uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35"