[PATCH 10/32] sync_qemu_models_i386: Update index.xml

Jiri Denemark posted 32 patches 2 weeks ago
There is a newer version of this series
[PATCH 10/32] sync_qemu_models_i386: Update index.xml
Posted by Jiri Denemark 2 weeks ago
Add all newly generated CPU models to the appropriate section of
index.xml.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/cpu_map/sync_qemu_models_i386.py | 40 ++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/cpu_map/sync_qemu_models_i386.py b/src/cpu_map/sync_qemu_models_i386.py
index 75d86144d0..40d71e66be 100755
--- a/src/cpu_map/sync_qemu_models_i386.py
+++ b/src/cpu_map/sync_qemu_models_i386.py
@@ -534,6 +534,35 @@ def output_model(f, extra, model):
     f.write("</cpus>\n")
 
 
+def update_index(outdir, models):
+    index = os.path.join(outdir, "index.xml")
+    xml = lxml.etree.parse(index)
+
+    for vendor, files in models.items():
+        groups = xml.xpath(f"//arch[@name='x86']/group[@vendor='{vendor}']")
+        if not groups:
+            continue
+
+        group = groups[-1]
+        last = group.getchildren()[-1]
+        group_indent = last.tail
+        indent = f"{group_indent}  "
+        last.tail = indent
+
+        for file in files:
+            include = lxml.etree.SubElement(group, "include", filename=file)
+            include.tail = indent
+
+        group.getchildren()[-1].tail = group_indent
+
+    out = lxml.etree.tostring(xml, encoding="UTF-8")
+    out = out.decode("UTF-8").replace('"', "'")
+
+    with open(index, "w") as f:
+        f.write(out)
+        f.write("\n")
+
+
 def main():
     parser = argparse.ArgumentParser(
         description="Synchronize x86 cpu models from QEMU i386 target.")
@@ -574,6 +603,8 @@ def main():
     for model in models_json:
         models.extend(expand_model(model))
 
+    files = dict()
+
     for model in models:
         base = os.path.join(args.outdir, f"x86_{model['name']}")
         name = f"{base}.xml"
@@ -582,9 +613,18 @@ def main():
             # Ignore existing models as CPU models in libvirt should never
             # change once released.
             continue
+
+        vendor = model['vendor']
+        if vendor:
+            if vendor not in files:
+                files[vendor] = []
+            files[vendor].append(name)
+
         with open(name, "wt") as f:
             output_model(f, f"{base}.extra", model)
 
+    update_index(args.outdir, files)
+
     features = set()
     for model in models:
         features.update(model["features"])
-- 
2.47.0
Re: [PATCH 10/32] sync_qemu_models_i386: Update index.xml
Posted by Daniel P. Berrangé 1 week, 6 days ago
On Tue, Nov 19, 2024 at 07:49:46PM +0100, Jiri Denemark wrote:
> Add all newly generated CPU models to the appropriate section of
> index.xml.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/cpu_map/sync_qemu_models_i386.py | 40 ++++++++++++++++++++++++++++
>  1 file changed, 40 insertions(+)
> 
> diff --git a/src/cpu_map/sync_qemu_models_i386.py b/src/cpu_map/sync_qemu_models_i386.py
> index 75d86144d0..40d71e66be 100755
> --- a/src/cpu_map/sync_qemu_models_i386.py
> +++ b/src/cpu_map/sync_qemu_models_i386.py
> @@ -534,6 +534,35 @@ def output_model(f, extra, model):
>      f.write("</cpus>\n")
>  
>  
> +def update_index(outdir, models):
> +    index = os.path.join(outdir, "index.xml")
> +    xml = lxml.etree.parse(index)
> +
> +    for vendor, files in models.items():
> +        groups = xml.xpath(f"//arch[@name='x86']/group[@vendor='{vendor}']")
> +        if not groups:
> +            continue
> +
> +        group = groups[-1]
> +        last = group.getchildren()[-1]
> +        group_indent = last.tail
> +        indent = f"{group_indent}  "
> +        last.tail = indent
> +
> +        for file in files:
> +            include = lxml.etree.SubElement(group, "include", filename=file)

I'm presuming this is the bit that it adding fully qualified paths
to the index.xml. 'file' needs stripping to its bare name.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|