summaryrefslogtreecommitdiffstats
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:19:27 +0000
commit278bd2f1758b8af97552af8d23d16ffb5127a131 (patch)
treee97c1baae0575e67b37c1c5d2b9118fe68186eee
parentb29f6e04091b6bfe697dc41c76880de466736fc3 (diff)
downloadbitbake-278bd2f1758b8af97552af8d23d16ffb5127a131.tar.gz
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) 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>
-rw-r--r--lib/bb/fetch2/crate.py9
-rw-r--r--lib/bb/tests/fetch.py24
2 files changed, 30 insertions, 3 deletions
diff --git a/lib/bb/fetch2/crate.py b/lib/bb/fetch2/crate.py
index f091200dd..2889e39c7 100644
--- a/lib/bb/fetch2/crate.py
+++ b/lib/bb/fetch2/crate.py
@@ -56,8 +56,10 @@ class Crate(Wget):
if len(parts) < 5:
raise bb.fetch2.ParameterError("Invalid URL: Must be crate://HOST/NAME/VERSION", ud.url)
- # last field is version
- version = parts[len(parts) - 1]
+ # version is expected to be the last token
+ # but ignore possible url parameters which will be used
+ # by the top fetcher class
+ version, _, _ = parts[len(parts) -1].partition(";")
# second to last field is name
name = parts[len(parts) - 2]
# host (this is to allow custom crate registries to be specified
@@ -69,7 +71,8 @@ class Crate(Wget):
ud.url = "https://%s/%s/%s/download" % (host, name, version)
ud.parm['downloadfilename'] = "%s-%s.crate" % (name, version)
- ud.parm['name'] = name
+ if 'name' not in ud.parm:
+ ud.parm['name'] = name
logger.debug2("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename']))
diff --git a/lib/bb/tests/fetch.py b/lib/bb/tests/fetch.py
index 73eefc593..1533d52b1 100644
--- a/lib/bb/tests/fetch.py
+++ b/lib/bb/tests/fetch.py
@@ -2385,6 +2385,30 @@ class CrateTest(FetcherTest):
self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs"))
@skipIfNoNetwork()
+ def test_crate_url_params(self):
+
+ uri = "crate://crates.io/aho-corasick/0.7.20;name=aho-corasick-renamed"
+ self.d.setVar('SRC_URI', uri)
+
+ uris = self.d.getVar('SRC_URI').split()
+ d = self.d
+
+ fetcher = bb.fetch2.Fetch(uris, self.d)
+ ud = fetcher.ud[fetcher.urls[0]]
+
+ self.assertIn("name", ud.parm)
+ self.assertEqual(ud.parm["name"], "aho-corasick-renamed")
+ self.assertIn("downloadfilename", ud.parm)
+ self.assertEqual(ud.parm["downloadfilename"], "aho-corasick-0.7.20.crate")
+
+ fetcher.download()
+ fetcher.unpack(self.tempdir)
+ self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked'])
+ self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['aho-corasick-0.7.20.crate', 'aho-corasick-0.7.20.crate.done'])
+ self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/.cargo-checksum.json"))
+ self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/aho-corasick-0.7.20/src/lib.rs"))
+
+ @skipIfNoNetwork()
def test_crate_url_multi(self):
uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35"