summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/cargo-update-recipe-crates.bbclass
diff options
context:
space:
mode:
authorFrederic Martinsons <frederic.martinsons@gmail.com>2023-03-31 07:45:27 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-04-01 11:36:26 +0100
commit476890160aafe66d6bfd4737ca49cc425d0a3a4c (patch)
tree86418ad6bb83555074ea76ac85e1d95aae05c518 /meta/classes-recipe/cargo-update-recipe-crates.bbclass
parentad460bb6aac01271eb36efed3ad3e8f4c0407e8d (diff)
downloadpoky-476890160aafe66d6bfd4737ca49cc425d0a3a4c.tar.gz
cargo-update-recipe-crates: force name overrides
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) (From OE-Core rev: 1795e98a04ad09b011afcc7cc3bf6dc49475b19a) Signed-off-by: Frederic Martinsons <frederic.martinsons@gmail.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/cargo-update-recipe-crates.bbclass')
-rw-r--r--meta/classes-recipe/cargo-update-recipe-crates.bbclass35
1 files 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):
38 if not crates_candidates: 38 if not crates_candidates:
39 raise ValueError("Unable to find any candidate crates that use crates.io") 39 raise ValueError("Unable to find any candidate crates that use crates.io")
40 40
41 # Build a list of crates name that have multiple version
42 crates_multiple_vers = []
43 tmp = []
44 for c in crates_candidates:
45 if c['name'] in tmp:
46 crates_multiple_vers.append(c['name'])
47 else:
48 tmp.append(c['name'])
49
50 # Update crates uri and their checksum, to avoid name clashing on the checksum 41 # Update crates uri and their checksum, to avoid name clashing on the checksum
51 # we need to rename crates of the same name but different version 42 # we need to rename crates with name and version to have a unique key
52 cksum_list = '' 43 cksum_list = ''
53 for c in crates_candidates: 44 for c in crates_candidates:
54 if c['name'] in crates_multiple_vers: 45 rename = "%s-%s" % (c['name'], c['version'])
55 rename = "%s-%s" % (c['name'], c['version']) 46 c_list += '\n crate://crates.io/%s/%s;name=%s \\\' % (c['name'], c['version'], rename)
56 c_list += '\n crate://crates.io/%s/%s;name=%s \\\' % (c['name'], c['version'], rename)
57 else:
58 rename = c['name']
59 c_list += '\n crate://crates.io/%s/%s \\\' % (c['name'], c['version'])
60 if 'checksum' in c: 47 if 'checksum' in c:
61 cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum']) 48 cksum_list += '\nSRC_URI[%s.sha256sum] = "%s"' % (rename, c['checksum'])
62 49
@@ -69,12 +56,22 @@ import os
69crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n" 56crates = "# Autogenerated with 'bitbake -c update_crates ${PN}'\n\n"
70found = False 57found = False
71for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'): 58for root, dirs, files in os.walk('${CARGO_LOCK_SRC_DIR}'):
59 # ignore git and patches directories
60 if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.pc')):
61 continue
62 if root.startswith(os.path.join('${CARGO_LOCK_SRC_DIR}', '.git')):
63 continue
72 for file in files: 64 for file in files:
73 if file == 'Cargo.lock': 65 if file == 'Cargo.lock':
74 crates += get_crates(os.path.join(root, file)) 66 try:
75 found = True 67 cargo_lock_path = os.path.join(root, file)
68 crates += get_crates(os.path.join(root, file))
69 except Exception as e:
70 raise ValueError("Cannot parse '%s'" % cargo_lock_path) from e
71 else:
72 found = True
76if not found: 73if not found:
77 raise ValueError("Unable to find Cargo.lock in ${CARGO_LOCK_SRC_DIR}") 74 raise ValueError("Unable to find any Cargo.lock in ${CARGO_LOCK_SRC_DIR}")
78open("${TARGET_FILE}", 'w').write(crates) 75open("${TARGET_FILE}", 'w').write(crates)
79EOF 76EOF
80 77