Preserve objdiff.json symbol_mappings when generating

This commit is contained in:
Luke Street 2024-10-08 20:35:33 -06:00
parent 0da3b202a3
commit 3d1b306acb
1 changed files with 31 additions and 4 deletions

View File

@ -1177,6 +1177,13 @@ def generate_objdiff_config(
if build_config is None:
return
# Load existing objdiff.json
existing_units = {}
if Path("objdiff.json").is_file():
with open("objdiff.json", "r", encoding="utf-8") as r:
existing_config = json.load(r)
existing_units = {unit["name"]: unit for unit in existing_config["units"]}
objdiff_config: Dict[str, Any] = {
"min_version": "2.0.0-beta.5",
"custom_make": "ninja",
@ -1234,15 +1241,27 @@ def generate_objdiff_config(
) -> None:
obj_path, obj_name = build_obj["object"], build_obj["name"]
base_object = Path(obj_name).with_suffix("")
name = str(Path(module_name) / base_object).replace(os.sep, "/")
unit_config: Dict[str, Any] = {
"name": Path(module_name) / base_object,
"name": name,
"target_path": obj_path,
"base_path": None,
"scratch": None,
"metadata": {
"auto_generated": build_obj["autogenerated"],
"complete": None,
"reverse_fn_order": None,
"source_path": None,
"progress_categories": progress_categories,
"auto_generated": build_obj["autogenerated"],
},
"symbol_mappings": None,
}
# Preserve existing symbol mappings
existing_unit = existing_units.get(name)
if existing_unit is not None:
unit_config["symbol_mappings"] = existing_unit.get("symbol_mappings")
obj = objects.get(obj_name)
if obj is None:
objdiff_config["units"].append(unit_config)
@ -1352,13 +1371,21 @@ def generate_objdiff_config(
for category in config.progress_categories:
add_category(category.id, category.name)
def cleandict(d):
if isinstance(d, dict):
return {k: cleandict(v) for k, v in d.items() if v is not None}
elif isinstance(d, list):
return [cleandict(v) for v in d]
else:
return d
# Write objdiff.json
with open("objdiff.json", "w", encoding="utf-8") as w:
def unix_path(input: Any) -> str:
return str(input).replace(os.sep, "/") if input else ""
json.dump(objdiff_config, w, indent=4, default=unix_path)
json.dump(cleandict(objdiff_config), w, indent=2, default=unix_path)
# Calculate, print and write progress to progress.json
@ -1480,4 +1507,4 @@ def calculate_progress(config: ProjectConfig) -> None:
add_category(category["id"], category["measures"])
with open(out_path / "progress.json", "w", encoding="utf-8") as w:
json.dump(progress_json, w, indent=4)
json.dump(progress_json, w, indent=2)