summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/crate.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/bb/fetch2/crate.py')
-rw-r--r--bitbake/lib/bb/fetch2/crate.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/bitbake/lib/bb/fetch2/crate.py b/bitbake/lib/bb/fetch2/crate.py
index f4ddc782a9..e611736f06 100644
--- a/bitbake/lib/bb/fetch2/crate.py
+++ b/bitbake/lib/bb/fetch2/crate.py
@@ -33,7 +33,7 @@ class Crate(Wget):
return ud.type in ['crate']
def recommends_checksum(self, urldata):
- return False
+ return True
def urldata_init(self, ud, d):
"""
@@ -56,22 +56,26 @@ 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[-1].split(";")[0]
# second to last field is name
- name = parts[len(parts) - 2]
+ name = parts[-2]
# host (this is to allow custom crate registries to be specified
- host = '/'.join(parts[2:len(parts) - 2])
+ host = '/'.join(parts[2:-2])
# if using upstream just fix it up nicely
if host == 'crates.io':
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)
- ud.parm['name'] = name
+ if 'name' not in ud.parm:
+ ud.parm['name'] = '%s-%s' % (name, version)
- logger.debug("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename']))
+ logger.debug2("Fetching %s to %s" % (ud.url, ud.parm['downloadfilename']))
def unpack(self, ud, rootdir, d):
"""
@@ -95,11 +99,13 @@ class Crate(Wget):
save_cwd = os.getcwd()
os.chdir(rootdir)
- pn = d.getVar('BPN')
- if pn == ud.parm.get('name'):
+ bp = d.getVar('BP')
+ if bp == ud.parm.get('name'):
cmd = "tar -xz --no-same-owner -f %s" % thefile
+ ud.unpack_tracer.unpack("crate-extract", rootdir)
else:
cargo_bitbake = self._cargo_bitbake_path(rootdir)
+ ud.unpack_tracer.unpack("cargo-extract", cargo_bitbake)
cmd = "tar -xz --no-same-owner -f %s -C %s" % (thefile, cargo_bitbake)
@@ -134,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], "")