From 5476f3b62e7c9383f49e2a8fde8c1446c961ad84 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Mon, 30 Dec 2024 18:03:43 -0700 Subject: [PATCH] Adjust link_order_callback API --- configure.py | 11 ++++++++--- tools/project.py | 28 ++++++++++++++++------------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/configure.py b/configure.py index 2d966f02..b54f688f 100755 --- a/configure.py +++ b/configure.py @@ -15,9 +15,10 @@ import argparse import sys from pathlib import Path -from typing import List +from typing import List, Sequence, Union from tools.project import ( + BuildConfigUnit, Object, ProgressCategory, ProjectConfig, @@ -1409,9 +1410,13 @@ for lib in config.libs: obj.options["extra_clang_flags"].append("-Wno-return-type") -def link_order_callback(module_id: int, units: List[str]) -> List[str]: +def link_order_callback( + module_id: int, units: List[str] +) -> Sequence[Union[str, BuildConfigUnit]]: if module_id == 0: # DOL - return units + ["dummy.c"] + return units + [ + {"object": "dummy.o", "name": "dummy.c", "autogenerated": False} + ] return units diff --git a/tools/project.py b/tools/project.py index a069deb7..d50adab7 100644 --- a/tools/project.py +++ b/tools/project.py @@ -20,6 +20,7 @@ from pathlib import Path from typing import ( Any, Callable, + Sequence, cast, Dict, IO, @@ -192,9 +193,9 @@ class ProjectConfig: self.scratch_preset_id: Optional[int] = ( None # Default decomp.me preset ID for scratches ) - self.link_order_callback: Optional[Callable[[int, List[str]], List[str]]] = ( - None # Callback to add/remove/reorder units within a module - ) + self.link_order_callback: Optional[ + Callable[[int, List[str]], Sequence[Union[str, BuildConfigUnit]]] + ] = None # Callback to add/remove/reorder units within a module # Progress output, progress.json and report.json config self.progress = True # Enable report.json generation and CLI progress output @@ -371,16 +372,19 @@ def load_build_config( modules: List[BuildConfigModule] = [build_config, *build_config["modules"]] for module in modules: unit_names = list(map(lambda u: u["name"], module["units"])) - unit_names = config.link_order_callback(module["module_id"], unit_names) + new_units = config.link_order_callback(module["module_id"], unit_names) units: List[BuildConfigUnit] = [] - for unit_name in unit_names: - # Find existing unit or create a new one - unit = next( - (u for u in module["units"] if u["name"] == unit_name), None - ) - if not unit: - unit = {"object": None, "name": unit_name, "autogenerated": False} - units.append(unit) + for new_unit in new_units: + if isinstance(new_unit, str): + units.append( + # Find existing unit or create a new one + next( + (u for u in module["units"] if u["name"] == new_unit), + {"object": None, "name": new_unit, "autogenerated": False}, + ) + ) + else: + units.append(new_unit) module["units"] = units return build_config