[PATCH 4/9] scripts: prepare for introduction of CrateSource class

Paolo Bonzini <[email protected]>
Newsgroups org.nongnu.qemu-rust,org.nongnu.qemu-devel
Message-ID <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
---
 scripts/get-wraps-from-cargo-registry.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/scripts/get-wraps-from-cargo-registry.py b/scripts/get-wraps-from-cargo-registry.py
index 8b45c1551f5..8114f0731be 100755
--- a/scripts/get-wraps-from-cargo-registry.py
+++ b/scripts/get-wraps-from-cargo-registry.py
@@ -48,6 +48,14 @@ def find_installed_crate(self, namever: str) -> str | None:
         matches = sorted(glob.glob(f"{path}.*"))
         return os.path.basename(matches[0]) if matches else None
 
+    def rewrite_source(self, section: configparser.SectionProxy, orig_namever: str, registry_namever: str) -> bool:
+        # the registry already holds the extracted sources, so Meson does not
+        # download anything: drop the source_* keys.
+        for key in list(section.keys()):
+            if key.startswith("source"):
+                del section[key]
+        return True
+
     def compare_build_rs(self, orig_dir: str, source_namever: str) -> None:
         """Warn if the build.rs in the original directory differs from the registry version."""
         orig_build_rs = os.path.join(orig_dir, "build.rs")
@@ -82,7 +90,8 @@ def update_subproject(self, wrap_file: str, source_namever: str) -> None:
         if "wrap-file" not in config:
             return
 
-        orig_dir = config["wrap-file"]["directory"]
+        section = config["wrap-file"]
+        orig_dir = section["directory"]
 
         if self.dry_run:
             if orig_dir == source_namever:
@@ -92,10 +101,10 @@ def update_subproject(self, wrap_file: str, source_namever: str) -> None:
             self.changes += 1
             return
 
-        config["wrap-file"]["directory"] = source_namever
-        for key in list(config["wrap-file"].keys()):
-            if key.startswith("source"):
-                del config["wrap-file"][key]
+        section["directory"] = source_namever
+        if self.rewrite_source(section, orig_dir, source_namever):
+            with open(wrap_file, "w") as f:
+                config.write(f)
 
         with open(wrap_file, "w") as f:
             config.write(f)
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.