scripts: prepare for introduction of CrateSource class
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Paolo Bonzini committed
Aug 21, 2026 at 09:39 UTC
784f78a9879a86ec8ea989163d00be936046ba5d
1 file changed
+14
-5
scripts/get-wraps-from-cargo-registry.py
+14
-5
@@ -48,6 +48,14 @@ class UpdateSubprojects:
48
matches = sorted(glob.glob(f"{path}.*"))
49
return os.path.basename(matches[0]) if matches else None
50
51
+ def rewrite_source(self, section: configparser.SectionProxy, orig_namever: str, registry_namever: str) -> bool:
52
+ # the registry already holds the extracted sources, so Meson does not
53
+ # download anything: drop the source_* keys.
54
+ for key in list(section.keys()):
55
+ if key.startswith("source"):
56
+ del section[key]
57
+ return True
58
+
59
def compare_build_rs(self, orig_dir: str, source_namever: str) -> None:
60
"""Warn if the build.rs in the original directory differs from the registry version."""
61
orig_build_rs = os.path.join(orig_dir, "build.rs")
@@ -82,7 +90,8 @@ class UpdateSubprojects:
90
if "wrap-file" not in config:
91
return
92
85
- orig_dir = config["wrap-file"]["directory"]
93
+ section = config["wrap-file"]
94
+ orig_dir = section["directory"]
95
96
if self.dry_run:
97
if orig_dir == source_namever:
@@ -92,10 +101,10 @@ class UpdateSubprojects:
101
self.changes += 1
102
return
103
95
- config["wrap-file"]["directory"] = source_namever
96
- for key in list(config["wrap-file"].keys()):
97
- if key.startswith("source"):
98
- del config["wrap-file"][key]
104
+ section["directory"] = source_namever
105
+ if self.rewrite_source(section, orig_dir, source_namever):
106
+ with open(wrap_file, "w") as f:
107
+ config.write(f)
108
109
with open(wrap_file, "w") as f:
110
config.write(f)