summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/cargo-update-recipe-crates.bbclass
diff options
context:
space:
mode:
authorAlexander Kanavin <alex.kanavin@gmail.com>2022-10-31 12:47:07 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-01 17:34:58 +0000
commit6a5b4d84288904957f99446ebc5629302554df89 (patch)
tree9bc629a13487f561b252eeebb67ead4b1f17bb81 /meta/classes-recipe/cargo-update-recipe-crates.bbclass
parent04eee95515735c0f14e99b0d989d8fc85a1f06b5 (diff)
downloadpoky-6a5b4d84288904957f99446ebc5629302554df89.tar.gz
cargo-update-recipe-crates.bbclass: add a class to generate SRC_URI crate lists from Cargo.lock
For better or worse, more and more rust components are appearing that do not include their dependencies in tarballs (or git trees), and rely on cargo to fetch them. On the other hand, bitbake does not use cargo (and quite possible won't ever be able to), and relies on having each item explicitly listed in SRC_URI with a crate:// prefix. This however creates a problem of both making such lists in the first place and updating them when a recipe is updated to a newer version. So this class can be used to perform such updates by implementing a task that does it; the next commit shows the outcome for python3-bcrypt (which has been tested to work and produce a successful build). Note: the python script relies on tomllib library, which appears in Python 3.11 and does not exist in earlier versions - I've tested this by first updating python to 3.11-rc2 in oe-core. (From OE-Core rev: 9eee3631124d64574b18a70a2fc42f446d58bfd2) Signed-off-by: Alexander Kanavin <alex@linutronix.de> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/cargo-update-recipe-crates.bbclass')
-rw-r--r--meta/classes-recipe/cargo-update-recipe-crates.bbclass41
1 files changed, 41 insertions, 0 deletions
diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
new file mode 100644
index 0000000000..f90938c734
--- /dev/null
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -0,0 +1,41 @@
1#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7##
8## Purpose:
9## This class is used to update the list of crates in SRC_URI
10## by reading Cargo.lock in the source tree.
11##
12## See meta/recipes-devtools/python/python3-bcrypt_*.bb for an example
13##
14## To perform the update: bitbake -c update_crates recipe-name
15
16addtask do_update_crates after do_patch
17do_update_crates[depends] = "python3-native:do_populate_sysroot"
18
19do_update_crates() {
20 nativepython3 - <<EOF
21
22def get_crates(f):
23 import tomllib
24 c_list = 'SRC_URI += " \\ \n'
25 crates = tomllib.load(open(f, 'rb'))
26 for c in crates['package']:
27 if 'source' in c and 'crates.io' in c['source']:
28 c_list += " crate://crates.io/{}/{} \\ \n".format(c['name'], c['version'])
29 c_list += '"\n'
30 return c_list
31
32import os
33crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
34for root, dirs, files in os.walk('${S}'):
35 for file in files:
36 if file == 'Cargo.lock':
37 crates += get_crates(os.path.join(root, file))
38open(os.path.join('${THISDIR}', '${PN}'+"-crates.inc"), 'w').write(crates)
39
40EOF
41}