@@ -9,6 +9,10 @@
## This class is used to update the list of crates in SRC_URI
## by reading Cargo.lock in the source tree.
##
+## Both the current Cargo.lock format (checksum stored per [[package]])
+## and the old v1 format (checksums stored in the [metadata] table as
+## "checksum <name> <version> (<source>)" checksum-val) are supported.
+##
## See meta/recipes-devtools/python/python3-bcrypt_*.bb for an example
##
## To perform the update: bitbake -c update_crates recipe-name
@@ -25,6 +29,25 @@ CARGO_LOCK_SRC_DIR ??= "${S}"
python do_update_crates() {
cargo_lock_src_dir = d.getVar("CARGO_LOCK_SRC_DIR")
+ def get_legacy_checksums(crates, filename):
+ # Old (v1) Cargo.lock files do not carry a 'checksum' field per
+ # [[package]]; instead they are collected in the [metadata] table:
+ # "checksum <name> <version> (<source>)" = "<sha256>"
+ # Packages without a checksum (e.g. git sources) use "<none>".
+ checksums = {}
+ for key, value in crates.get('metadata', {}).items():
+ if not key.startswith('checksum '):
+ continue
+ parts = key.split(' ', 3)
+ if len(parts) != 4 or not (parts[3].startswith('(') and parts[3].endswith(')')):
+ bb.warn("Unable to parse metadata entry '%s' in %s" % (key, filename))
+ continue
+ name, version, source = parts[1], parts[2], parts[3][1:-1]
+ if value == '<none>':
+ continue
+ checksums[(name, version, source)] = value
+ return checksums
+
def get_crates(filename):
try:
import tomllib
@@ -36,6 +59,8 @@ python do_update_crates() {
with open(filename, 'rb') as fp:
crates = tomllib.load(fp)
+ legacy_checksums = get_legacy_checksums(crates, filename)
+
# Build a list with crates info that have crates.io in the source
crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package']))
@@ -48,9 +73,12 @@ python do_update_crates() {
cksum_list = ''
for c in crates_candidates:
rename = "%s-%s" % (c['name'], c['version'])
+ checksum = c.get('checksum')
+ if checksum is None:
+ checksum = legacy_checksums.get((c['name'], c['version'], c['source']))
c_list += '\n crate://crates.io/%s/%s \\' % (c['name'], c['version'])
- if 'checksum' in c:
- cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum'])
+ if checksum is not None:
+ cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, checksum)
c_list += '\n"\n'
c_list += cksum_list
Cargo.lock files in the old v1 format don't store a checksum per [[package]] but collect them in the [metadata] table as "checksum <name> <version> (<source>)" = "<sha256>". do_update_crates only read the per-package field, so it emitted crate:// entries without SRC_URI[...sha256sum] for such lockfiles. Fall back to the [metadata] checksums and skip "<none>" entries used for e.g. git sources. Signed-off-by: Marco Felsch <m.felsch@pengutronix.de> --- .../cargo-update-recipe-crates.bbclass | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-)