diff options
| -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 | } |
