From: Frederic Martinsons <frederic.martins...@gmail.com>

A project can have multiple Cargo.lock (provides
multiple binaries for example) and each one can
depends on differenct version of the same crates.
Even within the same Cargo.lock file, it is possible
to have different version of same crates.

To avoid conflicts, override the name with the version
for all crates checksum

Moreover, when searching for Cargo.lock, we should ignore
specific dir like .git (no use to walk down there) and .pc
(because it can have a Cargo.lock if this file was patched)

Signed-off-by: Frederic Martinsons <frederic.martins...@gmail.com>
---
 .../cargo-update-recipe-crates.bbclass        | 35 +++++++++----------
 1 file changed, 16 insertions(+), 19 deletions(-)

diff --git a/meta/classes-recipe/cargo-update-recipe-crates.bbclass 
b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
index daa363b0dd..322b4e4d79 100644
--- a/meta/classes-recipe/cargo-update-recipe-crates.bbclass
+++ b/meta/classes-recipe/cargo-update-recipe-crates.bbclass
@@ -38,25 +38,12 @@ def get_crates(f):
     if not crates_candidates:
         raise ValueError("Unable to find any candidate crates that use 
crates.io")
 
-    # Build a list of crates name that have multiple version
-    crates_multiple_vers = []
-    tmp = []
-    for c in crates_candidates:
-        if c['name'] in tmp:
-            crates_multiple_vers.append(c['name'])
-        else:
-            tmp.append(c['name'])
-
     # Update crates uri and their checksum, to avoid name clashing on the 
checksum
-    # we need to rename crates of the same name but different version
+    # we need to rename crates with name and version to have a unique key
     cksum_list = ''
     for c in crates_candidates:
-        if c['name'] in crates_multiple_vers:
-            rename = "%s-%s" % (c['name'], c['version'])
-            c_list += '\n    crate://crates.io/%s/%s;name=%s \\\' % 
(c['name'], c['version'], rename)
-        else:
-            rename = c['name']
-            c_list += '\n    crate://crates.io/%s/%s \\\' % (c['name'], 
c['version'])
+        rename = "%s-%s" % (c['name'], c['version'])
+        c_list += '\n    crate://crates.io/%s/%s;name=%s \\\' % (c['name'], 
c['version'], rename)
         if 'checksum' in c:
             cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, 
c['checksum'])
 
@@ -69,12 +56,22 @@ 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':
-            crates += get_crates(os.path.join(root, file))
-            found = True
+            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 Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
+    raise ValueError("Unable to find any Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
 open("${TARGET_FILE}", 'w').write(crates)
 EOF
 
-- 
2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#179398): 
https://lists.openembedded.org/g/openembedded-core/message/179398
Mute This Topic: https://lists.openembedded.org/mt/97967792/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