From f7588f76b3f88441a61cce491824d22d3518dafe Mon Sep 17 00:00:00 2001 From: Seeky <58006653+SeekyCt@users.noreply.github.com> Date: Sun, 29 Sep 2024 21:18:23 +0100 Subject: [PATCH] Missing dtk-template changes --- configure.py | 1 + tools/project.py | 58 +++++++++++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/configure.py b/configure.py index c64e806..d69e9f9 100644 --- a/configure.py +++ b/configure.py @@ -19,6 +19,7 @@ from tools.project import ( Object, + ProgressCategory, ProjectConfig, calculate_progress, generate_build, diff --git a/tools/project.py b/tools/project.py index c98b9d9..55f9105 100644 --- a/tools/project.py +++ b/tools/project.py @@ -213,11 +213,13 @@ def is_windows() -> bool: EXE = ".exe" if is_windows() else "" -def make_flags_str(cflags: Union[str, List[str]]) -> str: - if isinstance(cflags, list): - return " ".join(cflags) +def make_flags_str(flags: Optional[Union[str, List[str]]]) -> str: + if flags is None: + return "" + elif isinstance(flags, list): + return " ".join(flags) else: - return cflags + return flags # Load decomp-toolkit generated config.json @@ -234,14 +236,14 @@ def versiontuple(v: str) -> Tuple[int, ...]: build_config: Dict[str, Any] = json.load(f) config_version = build_config.get("version") if config_version is None: - # Invalid config.json + print("Invalid config.json, regenerating...") f.close() os.remove(build_config_path) return None dtk_version = str(config.dtk_tag)[1:] # Strip v if versiontuple(config_version) < versiontuple(dtk_version): - # Outdated config.json + print("Outdated config.json, regenerating...") f.close() os.remove(build_config_path) return None @@ -282,7 +284,7 @@ def generate_build_ninja( # Variables ### n.comment("Variables") - n.variable("ldflags", " ".join(config.ldflags or [])) + n.variable("ldflags", make_flags_str(config.ldflags)) if config.linker_version is None: sys.exit("ProjectConfig.linker_version missing") n.variable("mw_version", Path(config.linker_version)) @@ -1188,7 +1190,6 @@ def generate_objdiff_config( } # decomp.me compiler name mapping - # Commented out versions have not been added to decomp.me yet COMPILER_MAP = { "GC/1.0": "mwcc_233_144", "GC/1.1": "mwcc_233_159", @@ -1365,16 +1366,11 @@ class ProgressUnit: def __init__(self, name: str) -> None: self.name: str = name self.code_total: int = 0 - self.code_fancy_frac: int = config.progress_code_fancy_frac - self.code_fancy_item: str = config.progress_code_fancy_item self.code_progress: int = 0 self.data_total: int = 0 - self.data_fancy_frac: int = config.progress_data_fancy_frac - self.data_fancy_item: str = config.progress_data_fancy_item self.data_progress: int = 0 - self.objects_progress: int = 0 - self.objects_total: int = 0 self.objects: Set[Object] = set() + self.objects_progress: int = 0 def add(self, build_obj: Dict[str, Any]) -> None: self.code_total += build_obj["code_size"] @@ -1384,7 +1380,6 @@ def add(self, build_obj: Dict[str, Any]) -> None: include_object = build_obj["name"] not in self.objects if include_object: self.objects.add(build_obj["name"]) - self.objects_total += 1 if build_obj["autogenerated"]: # Skip autogenerated objects @@ -1460,32 +1455,39 @@ def add_unit(id: str, unit: Dict[str, Any]) -> None: print("Progress:") for unit in progress_units.values(): - if unit.objects_total == 0: + if len(unit.objects) == 0: continue code_frac = unit.code_frac() data_frac = unit.data_frac() print( - f" {unit.name}: {code_frac:.2%} code, {data_frac:.2%} data ({unit.objects_progress} / {unit.objects_total} files)" + f" {unit.name}: {code_frac:.2%} code, {data_frac:.2%} data ({unit.objects_progress} / {len(unit.objects)} files)" ) print(f" Code: {unit.code_progress} / {unit.code_total} bytes") print(f" Data: {unit.data_progress} / {unit.data_total} bytes") - if config.progress_use_fancy: - print( - "\nYou have {} out of {} {} and {} out of {} {}.".format( - math.floor(code_frac * unit.code_fancy_frac), - unit.code_fancy_frac, - unit.code_fancy_item, - math.floor(data_frac * unit.data_fancy_frac), - unit.data_fancy_frac, - unit.data_fancy_item, - ) + + if config.progress_use_fancy: + unit = progress_units.get("all") or progress_units.get("dol") + if unit is None or len(unit.objects) == 0: + return + + code_frac = unit.code_frac() + data_frac = unit.data_frac() + print( + "\nYou have {} out of {} {} and {} out of {} {}.".format( + math.floor(code_frac * config.progress_code_fancy_frac), + config.progress_code_fancy_frac, + config.progress_code_fancy_item, + math.floor(data_frac * config.progress_data_fancy_frac), + config.progress_data_fancy_frac, + config.progress_data_fancy_item, ) + ) # Generate and write progress.json progress_json: Dict[str, Any] = {} for id, unit in progress_units.items(): - if unit.objects_total == 0: + if len(unit.objects) == 0: continue progress_json[id] = { "code": unit.code_progress,