summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/cargo-update-recipe-crates.bbclass
diff options
context:
space:
mode:
authorMartin Jansa <Martin.Jansa@gmail.com>2022-11-02 09:12:07 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-11-03 07:46:47 +0000
commit99350f44b2b215bd84f873a6ce653c4d386db8b0 (patch)
tree77279d678fff592c71e6f221931fca81d0abe193 /meta/classes-recipe/cargo-update-recipe-crates.bbclass
parent5c31bd2cff020a58a69cce0c810d9dd00a2987ee (diff)
downloadpoky-99350f44b2b215bd84f873a6ce653c4d386db8b0.tar.gz
cargo-update-recipe-crates: small improvements
* use 4 spaces * avoid trailing space * add CARGO_LOCK_SRC_DIR to allow searching outside ${S} * use BPN in output filename * First I've used CARGO_LOCK_SRC_DIR as relative to ${S}, because that's what CARGO_SRC_DIR in cargo.bbclass is using: meta/classes-recipe/cargo.bbclass:CARGO_SRC_DIR ??= "" meta/classes-recipe/cargo.bbclass:MANIFEST_PATH ??= "${S}/${CARGO_SRC_DIR}/Cargo.toml" but change to absolute path (defaulting to ${S}) as requested by Alex: 11:44 < kanavin> JaMa, would prefer CARGO_LOCK_SRC_DIR ??= "${S}" 11:46 < kanavin> otherwise looks good * I've resolved my usecase for CARGO_LOCK_SRC_DIR by changing S back to ${WORKDIR}/git and using CARGO_SRC_DIR to select the right subdirectory to be built, because the Cargo.toml in this subdirectory was also referencing other subdirectories with relative path: https://github.com/solana-labs/solana-program-library/blob/88b147506d5b9515f3a4762421a0b8c309188dc9/token/cli/Cargo.toml#L30 so including all Cargo.lock files in whole ${WORKDIR}/git seems like reasonable approach (From OE-Core rev: 7636a2b8080521ed2ad54b0edce47a8742a12d58) Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com> 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.bbclass14
1 files changed, 9 insertions, 5 deletions
diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index f90938c734..3a12ba247d 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -16,26 +16,30 @@
16addtask do_update_crates after do_patch 16addtask do_update_crates after do_patch
17do_update_crates[depends] = "python3-native:do_populate_sysroot" 17do_update_crates[depends] = "python3-native:do_populate_sysroot"
18 18
19# The directory where to search for Cargo.lock files
20CARGO_LOCK_SRC_DIR ??= "${S}"
21
19do_update_crates() { 22do_update_crates() {
20 nativepython3 - <<EOF 23 nativepython3 - <<EOF
21 24
22def get_crates(f): 25def get_crates(f):
23 import tomllib 26 import tomllib
24 c_list = 'SRC_URI += " \\ \n' 27 c_list = '# from %s' % os.path.relpath(f, '${CARGO_LOCK_SRC_DIR}')
28 c_list += '\nSRC_URI += " \\\'
25 crates = tomllib.load(open(f, 'rb')) 29 crates = tomllib.load(open(f, 'rb'))
26 for c in crates['package']: 30 for c in crates['package']:
27 if 'source' in c and 'crates.io' in c['source']: 31 if 'source' in c and 'crates.io' in c['source']:
28 c_list += " crate://crates.io/{}/{} \\ \n".format(c['name'], c['version']) 32 c_list += '\n crate://crates.io/%s/%s \\\' % (c['name'], c['version'])
29 c_list += '"\n' 33 c_list += '\n"\n'
30 return c_list 34 return c_list
31 35
32import os 36import os
33crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n" 37crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
34for root, dirs, files in os.walk('${S}'): 38for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
35 for file in files: 39 for file in files:
36 if file == 'Cargo.lock': 40 if file == 'Cargo.lock':
37 crates += get_crates(os.path.join(root, file)) 41 crates += get_crates(os.path.join(root, file))
38open(os.path.join('${THISDIR}', '${PN}'+"-crates.inc"), 'w').write(crates) 42open(os.path.join('${THISDIR}', '${BPN}'+"-crates.inc"), 'w').write(crates)
39 43
40EOF 44EOF
41} 45}