Rather than searching for Cargo.lock, just use CARGO_LOCK_PATH, since we
have to know where the lock file is, else cargo_common_do_patch_paths
will fail. There should only ever be one lock file associated with a
project, so trying to aggregate across all of them makes no sense.

Signed-off-by: Alex Kiernan <alex.kier...@gmail.com>
---

 .../cargo-update-recipe-crates.bbclass        | 30 +++++--------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass 
b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index 8980137d02cf..59415ee8cb45 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -4,6 +4,8 @@
 # SPDX-License-Identifier: MIT
 #
 
+inherit cargo_common
+
 ##
 ## Purpose:
 ## This class is used to update the list of crates in SRC_URI
@@ -18,9 +20,6 @@ do_update_crates[depends] = 
"python3-native:do_populate_sysroot"
 do_update_crates[nostamp] = "1"
 do_update_crates[doc] = "Update the recipe by reading Cargo.lock and write in 
${THISDIR}/${BPN}-crates.inc"
 
-# The directory where to search for Cargo.lock files
-CARGO_LOCK_SRC_DIR ??= "${S}"
-
 do_update_crates() {
     TARGET_FILE="${THISDIR}/${BPN}-crates.inc"
 
@@ -28,8 +27,7 @@ do_update_crates() {
 
 def get_crates(f):
     import tomllib
-    c_list = '# from %s' % os.path.relpath(f, '${CARGO_LOCK_SRC_DIR}')
-    c_list += '\nSRC_URI += " \\\'
+    c_list = 'SRC_URI += " \\\'
     crates = tomllib.load(open(f, 'rb'))
 
     # Build a list with crates info that have crates.io in the source
@@ -55,23 +53,11 @@ def get_crates(f):
 import os
 crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
 found = False
-for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
-    # ignore git and patches directories
-    if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.pc')):
-        continue
-    if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.git')):
-        continue
-    for file in files:
-        if file == 'Cargo.lock':
-            try:
-                cargo_lock_path = os.path.join(root, file)
-                crates += get_crates(os.path.join(root, file))
-            except Exception as e:
-                raise ValueError("Cannot parse '%s'" % cargo_lock_path) from e
-            else:
-                found = True
-if not found:
-    raise ValueError("Unable to find any Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
+try:
+    cargo_lock_path = '${CARGO_LOCK_PATH}'
+    crates += get_crates(cargo_lock_path)
+except Exception as e:
+    raise ValueError("Cannot parse '%s'" % cargo_lock_path) from e
 open("${TARGET_FILE}", 'w').write(crates)
 EOF
 
-- 
2.39.0

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#192116): 
https://lists.openembedded.org/g/openembedded-core/message/192116
Mute This Topic: https://lists.openembedded.org/mt/103094777/21656
Group Owner: openembedded-core+ow...@lists.openembedded.org
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to