sync_qemu_models_i386: Update index.xml

Add all newly generated CPU models to the appropriate section of
index.xml.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Jiri Denemark 2024-10-21 15:41:50 +02:00
parent e2e7602a22
commit 7133d72eff

View File

@ -533,6 +533,35 @@ def output_model(f, extra, model):
f.write("</cpus>\n") 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[@name='{vendor} CPU models']")
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(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Synchronize x86 cpu models from QEMU i386 target.") description="Synchronize x86 cpu models from QEMU i386 target.")
@ -573,6 +602,8 @@ def main():
for model in models_json: for model in models_json:
models.extend(expand_model(model)) models.extend(expand_model(model))
files = dict()
for model in models: for model in models:
name = f"x86_{model['name']}.xml" name = f"x86_{model['name']}.xml"
path = os.path.join(args.outdir, name) path = os.path.join(args.outdir, name)
@ -582,10 +613,18 @@ def main():
# change once released. # change once released.
continue continue
vendor = model['vendor']
if vendor:
if vendor not in files:
files[vendor] = []
files[vendor].append(name)
extra = os.path.join(args.outdir, f"x86_{model['name']}.extra") extra = os.path.join(args.outdir, f"x86_{model['name']}.extra")
with open(path, "wt") as f: with open(path, "wt") as f:
output_model(f, extra, model) output_model(f, extra, model)
update_index(args.outdir, files)
features = set() features = set()
for model in models: for model in models:
features.update(model["features"]) features.update(model["features"])