addtask do_update_crates after do_patch
do_update_crates[depends] = "python3-native:do_populate_sysroot"
+# The directory where to search for Cargo.lock files
+CARGO_LOCK_SRC_DIR ??= "${S}"
+
do_update_crates() {
nativepython3 - <<EOF
def get_crates(f):
import tomllib
- c_list = 'SRC_URI += " \\ \n'
+ c_list = '# from %s' % os.path.relpath(f, '${CARGO_LOCK_SRC_DIR}')
+ c_list += '\nSRC_URI += " \\\'
crates = tomllib.load(open(f, 'rb'))
for c in crates['package']:
if 'source' in c and 'crates.io' in c['source']:
- c_list += " crate://crates.io/{}/{} \\ \n".format(c['name'], c['version'])
- c_list += '"\n'
+ c_list += '\n crate://crates.io/%s/%s \\\' % (c['name'], c['version'])
+ c_list += '\n"\n'
return c_list
import os
crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
-for root, dirs, files in os.walk('${S}'):
+for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
for file in files:
if file == 'Cargo.lock':
crates += get_crates(os.path.join(root, file))
-open(os.path.join('${THISDIR}', '${PN}'+"-crates.inc"), 'w').write(crates)
+open(os.path.join('${THISDIR}', '${BPN}'+"-crates.inc"), 'w').write(crates)
EOF
}