diff options
author | Martin Jansa <Martin.Jansa@gmail.com> | 2022-11-02 09:12:07 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-11-03 07:46:47 +0000 |
commit | 99350f44b2b215bd84f873a6ce653c4d386db8b0 (patch) | |
tree | 77279d678fff592c71e6f221931fca81d0abe193 /meta/classes-recipe | |
parent | 5c31bd2cff020a58a69cce0c810d9dd00a2987ee (diff) | |
download | poky-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')
-rw-r--r-- | meta/classes-recipe/cargo-update-recipe-crates.bbclass | 14 |
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 @@ | |||
16 | addtask do_update_crates after do_patch | 16 | addtask do_update_crates after do_patch |
17 | do_update_crates[depends] = "python3-native:do_populate_sysroot" | 17 | do_update_crates[depends] = "python3-native:do_populate_sysroot" |
18 | 18 | ||
19 | # The directory where to search for Cargo.lock files | ||
20 | CARGO_LOCK_SRC_DIR ??= "${S}" | ||
21 | |||
19 | do_update_crates() { | 22 | do_update_crates() { |
20 | nativepython3 - <<EOF | 23 | nativepython3 - <<EOF |
21 | 24 | ||
22 | def get_crates(f): | 25 | def 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 | ||
32 | import os | 36 | import os |
33 | crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n" | 37 | crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n" |
34 | for root, dirs, files in os.walk('${S}'): | 38 | for 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)) |
38 | open(os.path.join('${THISDIR}', '${PN}'+"-crates.inc"), 'w').write(crates) | 42 | open(os.path.join('${THISDIR}', '${BPN}'+"-crates.inc"), 'w').write(crates) |
39 | 43 | ||
40 | EOF | 44 | EOF |
41 | } | 45 | } |