From patchwork Mon Nov 30 20:40:25 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 106593 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.42146.1796071233000660133 for ; Mon, 30 Nov 2026 12:40:33 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@pengutronix.de header.s=20260414 header.b=FCbh/ra/; spf=pass (domain: pengutronix.de, ip: 185.203.200.13, mailfrom: m.felsch@pengutronix.de) Received: from dude06.red.stw.pengutronix.de (dude06.red.stw.4.pengutronix.de [10.17.1.27]) (Authenticated sender: relay-from-dude06.red.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 4AF16205AAF; Mon, 30 Nov 2026 21:40:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmwrFt3+2ZcEhyDiDSwEditFN9OS2xDDQzvI6wV6Wns=; b=FCbh/ra/FZDQJiJXKzYrMb+8Wv0YLFeNo1zxMy1N+02GGLc34CC1E8X/oNMzEXY/iIEDiq vAgRQfkinsepzEI43iX08YrNdC8CulxlhSEk2DSx5z2QQ+rxFDJDRB7q46ybvqdWPWsu90 oW1gD0sJyOBNrbfWY77FNwf550nBmwAIo5whXihGQOaCUPKtwX2ji8d7sJG7OP02/7jFse yGH1KurN4fAFbITixJ+onOvbCVsZ7rYzlFIGRqQgm+ff7f4uIpO8NokfWRSw5wLCb7nbYZ 5oTrVToUU2d1fjUoBfIVJSgGplhsV1a4Pudbn5v1kCtHlrlibMXgDmVrXNRFiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmwrFt3+2ZcEhyDiDSwEditFN9OS2xDDQzvI6wV6Wns=; b=AWBiBogUBBPTfUyi6qionvX5CQKNcx3+ePiSyxptOPPuv2r8+zmtlobi2gooCXD5CVVH0e X3fOijKeOc0VfjVtlsu+y+r0N2ku9gbRqgbuvdJ/eNPKT4tR7T1yzE84EAbM2pzwbGOTQs 627ga0PKDqEaFOkrjPx16OR5BnDsLU4T2PRGJqEcdGUdtPzlOopC6T8dkDQYZ5tTA1E1JK vqn+Sd1Q6siRU+IkUeyp20wMkI2f3X2lhi+i3bxt1xqrlV4NiUTgVUSmiZxUntfg/lppPb bA3J64V/RQXp//mvtr3tQNtVe90GRxuPB+xhEf7KMUeSXyrJ6tM7l5IFn09UYw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-dude06.red.stw.pengutronix.de smtp.mailfrom=m.felsch@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796071226; a=rsa-sha256; cv=none; b=M7k6qHMmTaDdrZe+Ni3bo/dOGD8z/1ysEQL/kZ007R8+ihWcZaKHjjUbLVwyz6WAeebf9f VcNmh8E9hqTiYQjNwrYo4U7lW1qpLo0lgbjdA37ma8+j53v1dwpo4/tW8uo1+rrQ79qNZq D1Lw6PfMBSxRJjUTlRzUEePTsdtb1LGhzPaAge3Y/n4XKjkgl6U0jBOQ5wUs6cft6+/IMP KUIR7NhnWYzNh/0TBXT2MJrJ0ZIOtxrwP3a9izo6kagg6Ap2WRaXd6Elp7BUDR8I+dHgZc oeEfiR2ojHXy0UKb38uZ2/OzcQSJlmEvqmn156BLEE0KogyMkEKkcjrd0YXSEg== Received: from dude06.red.stw.pengutronix.de (localhost [IPv6:::1]) by dude06.red.stw.pengutronix.de (Postfix) with ESMTP id 330E2640D65; Mon, 30 Nov 2026 21:40:26 +0100 (CET) From: Marco Felsch Date: Mon, 30 Nov 2026 21:40:25 +0100 Subject: [PATCH v4 1/3] classes/cargo-update-recipe-crates: use bb.warn() instead of print() MIME-Version: 1.0 Message-Id: <20261130-mfe-multi-cargo-lock-files-v4-1-a3ebce5cc283@pengutronix.de> References: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> In-Reply-To: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> To: openembedded-core@lists.openembedded.org Cc: peter.kjellerstedt@axis.com, paul@pbarker.dev, yocto@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 30 Nov 2026 20:40:43 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251646 The do_update_crates task is a regular python task since commit d56fb40b32c1 ("classes/cargo-update-recipe-crates: use tomllib directly"), so the print() output only ends up in the task log and is neither shown on the console nor counted in the warning summary. Make use of bb.warn() to fix this. Signed-off-by: Marco Felsch --- meta/classes-recipe/cargo-update-recipe-crates.bbclass | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass index 0767b566ee287d11dc2e1e6d0aeea0a0d3b225b8..d4318bc9f5749503cb7995927e2e54b9771a6b75 100644 --- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass +++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass @@ -40,7 +40,7 @@ python do_update_crates() { crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package'])) if not crates_candidates: - print("WARNING: Unable to find any candidate crates that use crates.io") + bb.warn("Unable to find any candidate crates that use crates.io") return None # Update crates uri and their checksum, to avoid name clashing on the checksum From patchwork Mon Nov 30 20:40:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 106594 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.41739.1796071233125536039 for ; Mon, 30 Nov 2026 12:40:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@pengutronix.de header.s=20260414 header.b=VM5nCW5k; spf=pass (domain: pengutronix.de, ip: 185.203.200.13, mailfrom: m.felsch@pengutronix.de) Received: from dude06.red.stw.pengutronix.de (dude06.red.stw.pengutronix.de [IPv6:2a0a:edc0:0:1101:1d::5c]) (Authenticated sender: relay-from-dude06.red.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 4FD4E205AB0; Mon, 30 Nov 2026 21:40:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=owSznV8oZIrc1ErHtALiiDJ6ivGsqJttT31tvUrsF9w=; b=VM5nCW5ksSfrTzWdjsGLTBwYt+rP4C0XxZu7LgcEblo1sDItnx9lw7QxkoyfQ5AjTHxDiI yItpwUx5PuiAzy1Yi0SG+zpOE7FoEVHnzaUZ4h/HwQ0AvCpGa1Ac2j0zhOTTG8zu9OrUrI +jxhXRl/E+E+21z1RcBRoGukodItPpjhtzWffz0mmbQ1iJgfzdJT1l3+KfpsFuRYF3u3Rk +qGYclBF24BnB0JgITiZtHyjSf5TWOYO00sY2KYv85vpAILoIniybrJ/OJRzTLDJnak+bb r5EvBYs3iEO1+L3zUl0B96TdI+sAyyFnz+dgELPfdIY7iBjGSvkD91XrBHv3iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=owSznV8oZIrc1ErHtALiiDJ6ivGsqJttT31tvUrsF9w=; b=BzQI60S29rOmRxHBytY3KNOrASjXyptOAsoMZ4K0mtLMQSCqN+rIuFCpoPq7X+tdhOOXVO c5omg42eQzTV+s1XNMnedLNxVJDlE5eGg2VrEUH0gRJtzY2rRiH1Igswec5Fki9e1zuQoZ aNZSkEBcnnjT6ZlwJrgYUYyTVybyhrEz1wC9iQUpEWmNkuJnzH/1d4HUmdCcY8kLhwbnqk bGk3nPvc1EDDYWmue7Aqvgrsd1kZSxHLibHzNinu897X3yRzqiRuEIDNzZw7cZTTnkxtkD XjlKBCQf02J+r57i3JajZ6rojROh7PRGgXBuA78ECACHDy3XL77pzsJTHNSRPQ== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-dude06.red.stw.pengutronix.de smtp.mailfrom=m.felsch@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796071226; a=rsa-sha256; cv=none; b=feEb/8RlEIRRJ/GUo2yJvDiKOsYOvJruwz8rXpURnoisB8wz8BE7X4bkDVgrOyWkOk5VRo xwRKA1Yg/iUfY7g13jvej74T1hmK5G4CZ+aOk/+BBrJmm4RoDMGR1exoDYRTW3nedePqkK fopfexjQHCIxmshZntdMDNfibpDKvGfTUqcJMOsyneG6hjWMlwYdW9RM6X7jQ8UuoHanjO 7CRqve8qgxiFNkQ0+A1w/rXFHpewdTkSHWo7U1u6QTTH+IbBtkl3Kgi2PY9Fn1F9DfSpvm xcxZ/yWqgpascTxQxiCuk0XtuZu4YmaEa6aLnxSGE78UmupzQhiz5+jQPbiYNA== Received: from dude06.red.stw.pengutronix.de (localhost [IPv6:::1]) by dude06.red.stw.pengutronix.de (Postfix) with ESMTP id 33546640E5E; Mon, 30 Nov 2026 21:40:26 +0100 (CET) From: Marco Felsch Date: Mon, 30 Nov 2026 21:40:26 +0100 Subject: [PATCH v4 2/3] classes/cargo-update-recipe-crates: support v1 Cargo.lock format MIME-Version: 1.0 Message-Id: <20261130-mfe-multi-cargo-lock-files-v4-2-a3ebce5cc283@pengutronix.de> References: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> In-Reply-To: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> To: openembedded-core@lists.openembedded.org Cc: peter.kjellerstedt@axis.com, paul@pbarker.dev, yocto@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 30 Nov 2026 20:40:43 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251648 Cargo.lock files in the old v1 format don't store a checksum per [[package]] but collect them in the [metadata] table as "checksum ()" = "". 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 "" entries used for e.g. git sources. Signed-off-by: Marco Felsch --- .../cargo-update-recipe-crates.bbclass | 32 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass index d4318bc9f5749503cb7995927e2e54b9771a6b75..9f92f0a522979fde8f0b88abdefb9a03c0c651ee 100644 --- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass +++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass @@ -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 ()" 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 ()" = "" + # Packages without a checksum (e.g. git sources) use "". + 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 == '': + 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 From patchwork Mon Nov 30 20:40:27 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Felsch X-Patchwork-Id: 106592 Received: from mx1.white.stw.pengutronix.de (mx1.white.stw.pengutronix.de [185.203.200.13]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.41738.1796071233125456427 for ; Mon, 30 Nov 2026 12:40:34 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@pengutronix.de header.s=20260414 header.b=AIkBaVo0; spf=pass (domain: pengutronix.de, ip: 185.203.200.13, mailfrom: m.felsch@pengutronix.de) Received: from dude06.red.stw.pengutronix.de (dude06.red.stw.pengutronix.de [IPv6:2a0a:edc0:0:1101:1d::5c]) (Authenticated sender: relay-from-dude06.red.stw.pengutronix.de) by mx1.white.stw.pengutronix.de (Postfix) with ESMTPSA id 54A42205AF2; Mon, 30 Nov 2026 21:40:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ipa7oKX4Vx87kK9XjNBp4vXQXME9dblFiAOS5Wmj6eE=; b=AIkBaVo0zEWF+FEN56U/TtRJq9qEghb+GmhdZVdjDNjfVqSHfsWMp7E+qsMRjvoHqhzcau sPnU8vBMjVaepC/xrRdsfjcEPPmB+cwwGew2H+Dyfm9E2vflf+tQXvTtajF2PQdu1QVTDT 2PefkUbKZJ1FvjSi3MXlHaubVYE3BZpfNVCEr3HhWeUCEU7ijPrhj2Y85L/nCiFVEoGJCv POWnpa069rbJkaLmNGc9z0f3wbsMa1H9J086Zcb1SMyyOpCI9j/1TTytH0UemhsTK1rI6M S3bIdtTqTy1dHy/nX0V4KdTjZA5TdlBA6Ua07yrvspz3YmeYJMW0n8EyLIa/RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=pengutronix.de; s=20260414; t=1796071226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ipa7oKX4Vx87kK9XjNBp4vXQXME9dblFiAOS5Wmj6eE=; b=BigIla9QGwz9PSqByZLpoS7sZmms+zka7BQulT6Dpeu6uMpPYduMo9wyPUXeFgpgmgkC7M 3pVzduwlS6Km5e4uggWNKLudSV7HmDamGO8qJg0+pdsYWxpz6t/BWg9KFuFGXnSiN6ovA5 LduVL0Plv40s9BIDOhQqnadBS670fJutMGH35EWxb/nX9hxKyxOIiaps5a6zFVG8lAaGwS yFMLyHMGnjSOVMYdlVdZ9ugmcjlIReF0n0v31wA1XWeLWlmgM5FFONLuq3A/AfGXz472cY KhjzeivHTd/YlAdAxe4M8KRxXep2dCw41JsbQTZrkoAQEPUah9ucB6DGUgeZRw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=relay-from-dude06.red.stw.pengutronix.de smtp.mailfrom=m.felsch@pengutronix.de ARC-Seal: i=1; s=20260414; d=pengutronix.de; t=1796071226; a=rsa-sha256; cv=none; b=JLSuEKqEx8pFCmbSIuatqBlfbjq6kItpreTGhPrzXDHfJ7Ft1+CBLuV4rWo8VpFKh3+3b7 DqSlUjMtVetEfmrsB7amwZ0sPUBX2C+ZB9QiBHRM27v21DPR2/0UVkP+nBu9Yu8VLeZEin 2g3nz4nbNTJQbkCm3UJSUz3bwD/Zhy58cTxSTAnrvA0eYL8n19/dPB5rPtAzRaBMfefMeu gLtvtQ4Zn4VQgtf0CT/H6SK+VwfInTVk9B3uoR1hDrZ79c2LsfMoB3rIcsDDRjo9kqgV+b xZqpItKmeWMd/3vfahKtJMpRDaJ40/43qMjlnhAqqZZOSfS8thmtxZ93/joiHA== Received: from dude06.red.stw.pengutronix.de (localhost [IPv6:::1]) by dude06.red.stw.pengutronix.de (Postfix) with ESMTP id 33A11642862; Mon, 30 Nov 2026 21:40:26 +0100 (CET) From: Marco Felsch Date: Mon, 30 Nov 2026 21:40:27 +0100 Subject: [PATCH v4 3/3] classes/cargo-update-recipe-crates: support multiple Cargo.lock search directories MIME-Version: 1.0 Message-Id: <20261130-mfe-multi-cargo-lock-files-v4-3-a3ebce5cc283@pengutronix.de> References: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> In-Reply-To: <20261130-mfe-multi-cargo-lock-files-v4-0-a3ebce5cc283@pengutronix.de> To: openembedded-core@lists.openembedded.org Cc: peter.kjellerstedt@axis.com, paul@pbarker.dev, yocto@pengutronix.de, Marco Felsch X-Mailer: b4 0.14.2 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Mon, 30 Nov 2026 20:40:43 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251649 Recipes using cargo's -Z build-std must also vendor the standard library's dependencies. The std sources staged by rust-native (.../rustlib/src/rust/library) ship a Cargo.lock but no vendor directory, so those crates need crate:// entries in SRC_URI as well. Until now only a single directory could be scanned (CARGO_LOCK_SRC_DIR), which forced the std crate list to be maintained by hand and go stale on toolchain upgrades, breaking do_compile with: error: failed to select a version for the requirement `cfg-if = "^1.0"` (locked to 1.0.4) Keep the existing CARGO_LOCK_SRC_DIR and extend it to support a space-separated list of directories, to allow: CARGO_LOCK_SRC_DIR = "${S} ${STAGING_LIBDIR_NATIVE}/rustlib/src/rust/library" This way the behavior can be backported. Crates found in multiple lockfiles are listed only once, in the section of the first Cargo.lock containing them; conflicting checksums for the same crate version now fail the task. The crates.io warning now names the lockfile it came from. Output for recipes with a single lockfile is unchanged. Signed-off-by: Marco Felsch --- .../cargo-update-recipe-crates.bbclass | 53 ++++++++++++++-------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass index 9f92f0a522979fde8f0b88abdefb9a03c0c651ee..449a1c5d81b92c686e9aea76648a55e88ec77efc 100644 --- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass +++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass @@ -23,12 +23,12 @@ do_update_crates[doc] = "Update the recipe by reading Cargo.lock and write in ${ RECIPE_UPGRADE_EXTRA_TASKS += "do_update_crates" -# The directory where to search for Cargo.lock files +# Space-separated list of directories where to search for Cargo.lock files. +# Crates found in multiple Cargo.lock files are listed only once, in the +# section of the first Cargo.lock file that contains them. 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: @@ -48,13 +48,13 @@ python do_update_crates() { checksums[(name, version, source)] = value return checksums - def get_crates(filename): + def get_crates(filename, src_dir, seen): try: import tomllib except ImportError: import bb._vendor.tomli as tomllib - c_list = '# from %s' % os.path.relpath(filename, cargo_lock_src_dir) + c_list = '# from %s' % os.path.relpath(filename, src_dir) c_list += '\nSRC_URI += " \\' with open(filename, 'rb') as fp: crates = tomllib.load(fp) @@ -65,20 +65,31 @@ python do_update_crates() { crates_candidates = list(filter(lambda c: 'crates.io' in c.get('source', ''), crates['package'])) if not crates_candidates: - bb.warn("Unable to find any candidate crates that use crates.io") + bb.warn("Unable to find any candidate crates that use crates.io in %s" % filename) return None # Update crates uri and their checksum, to avoid name clashing on the checksum # we need to rename crates with name and version to have a unique key + # Crates already emitted for a previous Cargo.lock are skipped. cksum_list = '' + ncrates = 0 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'])) + if rename in seen: + if seen[rename] != checksum: + raise ValueError(f"Conflicting checksums for crate {rename}") + continue c_list += '\n crate://crates.io/%s/%s \\' % (c['name'], c['version']) if checksum is not None: cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, checksum) + seen[rename] = checksum + ncrates += 1 + + if not ncrates: + return None c_list += '\n"\n' c_list += cksum_list @@ -90,23 +101,25 @@ python do_update_crates() { pn = d.getVar("PN") crates = f"# Autogenerated with 'bitbake -c update_crates {pn}'\n\n" + seen = {} found = False - for root, dirs, files in os.walk(cargo_lock_src_dir): - # ignore git and patches directories - if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')): - continue - if root.startswith(os.path.join(cargo_lock_src_dir, '.git')): - continue - for file in files: - if file == 'Cargo.lock': - cargo_lock_path = os.path.join(root, file) - c = get_crates(cargo_lock_path) - if c is not None: - crates += c - found = True + for cargo_lock_src_dir in d.getVar("CARGO_LOCK_SRC_DIR").split(): + for root, dirs, files in os.walk(cargo_lock_src_dir): + # ignore git and patches directories + if root.startswith(os.path.join(cargo_lock_src_dir, '.pc')): + continue + if root.startswith(os.path.join(cargo_lock_src_dir, '.git')): + continue + for file in files: + if file == 'Cargo.lock': + cargo_lock_path = os.path.join(root, file) + c = get_crates(cargo_lock_path, cargo_lock_src_dir, seen) + if c is not None: + crates += c + found = True if not found: - raise ValueError(f"Unable to find any Cargo.lock in {cargo_lock_src_dir}") + raise ValueError(f"Unable to find any Cargo.lock in '{d.getVar('CARGO_LOCK_SRC_DIR')}'") target_file = d.expand("${THISDIR}/${BPN}-crates.inc") with open(target_file, 'w') as f: