mirror of
https://github.com/zeldaret/tww.git
synced 2026-05-22 22:44:17 -04:00
Update from dtk-template
This commit is contained in:
+19
-6
@@ -16,7 +16,15 @@ import argparse
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List
|
||||
from tools.project import *
|
||||
|
||||
from tools.project import (
|
||||
Object,
|
||||
ProgressCategory,
|
||||
ProjectConfig,
|
||||
calculate_progress,
|
||||
generate_build,
|
||||
is_windows,
|
||||
)
|
||||
|
||||
# Game versions
|
||||
DEFAULT_VERSION = 1
|
||||
@@ -124,7 +132,6 @@ config.build_dir = args.build_dir
|
||||
config.dtk_path = args.dtk
|
||||
config.binutils_path = args.binutils
|
||||
config.compilers_path = args.compilers
|
||||
config.debug = args.debug
|
||||
config.generate_map = args.map
|
||||
config.non_matching = args.non_matching
|
||||
config.sjiswrap_path = args.sjiswrap
|
||||
@@ -136,8 +143,8 @@ if args.no_asm:
|
||||
# Tool versions
|
||||
config.binutils_tag = "2.42-1"
|
||||
config.compilers_tag = "20240706"
|
||||
config.dtk_tag = "v0.9.5"
|
||||
config.objdiff_tag = "v2.0.0-beta.5"
|
||||
config.dtk_tag = "v1.0.0"
|
||||
config.objdiff_tag = "v2.2.0"
|
||||
config.sjiswrap_tag = "v1.1.1"
|
||||
config.wibo_tag = "0.6.11"
|
||||
|
||||
@@ -154,8 +161,13 @@ config.asflags = [
|
||||
config.ldflags = [
|
||||
"-fp hardware",
|
||||
"-nodefaults",
|
||||
# "-listclosure", # Uncomment for Wii linkers
|
||||
]
|
||||
if args.debug:
|
||||
config.ldflags.append("-g") # Or -gdwarf-2 for Wii linkers
|
||||
if args.map:
|
||||
config.ldflags.append("-mapunused")
|
||||
# config.ldflags.append("-listclosure") # For Wii linkers
|
||||
|
||||
# Use for any additional files that should cause a re-configure when modified
|
||||
config.reconfig_deps = []
|
||||
|
||||
@@ -191,7 +203,8 @@ cflags_base = [
|
||||
]
|
||||
|
||||
# Debug flags
|
||||
if config.debug:
|
||||
if args.debug:
|
||||
# Or -sym dwarf-2 for Wii compilers
|
||||
cflags_base.extend(["-sym on", "-DDEBUG=1"])
|
||||
else:
|
||||
cflags_base.append("-DNDEBUG=1")
|
||||
|
||||
+42
-46
@@ -131,7 +131,6 @@ class ProjectConfig:
|
||||
self.build_rels: bool = True # Build REL files
|
||||
self.check_sha_path: Optional[Path] = None # Path to version.sha1
|
||||
self.config_path: Optional[Path] = None # Path to config.yml
|
||||
self.debug: bool = False # Build with debug info
|
||||
self.generate_map: bool = False # Generate map file(s)
|
||||
self.asflags: Optional[List[str]] = None # Assembler flags
|
||||
self.ldflags: Optional[List[str]] = None # Linker flags
|
||||
@@ -214,11 +213,13 @@ CHAIN = "cmd /c " if is_windows() else ""
|
||||
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
|
||||
@@ -235,14 +236,14 @@ def load_build_config(
|
||||
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
|
||||
@@ -283,12 +284,7 @@ def generate_build_ninja(
|
||||
# Variables
|
||||
###
|
||||
n.comment("Variables")
|
||||
ldflags = " ".join(config.ldflags or [])
|
||||
if config.generate_map:
|
||||
ldflags += " -mapunused"
|
||||
if config.debug:
|
||||
ldflags += " -g"
|
||||
n.variable("ldflags", ldflags)
|
||||
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))
|
||||
@@ -1194,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",
|
||||
@@ -1248,6 +1243,7 @@ def generate_objdiff_config(
|
||||
src_exists = obj.src_path is not None and obj.src_path.exists()
|
||||
if src_exists:
|
||||
unit_config["base_path"] = obj.src_obj_path
|
||||
unit_config["metadata"]["source_path"] = obj.src_path
|
||||
|
||||
cflags = obj.options["cflags"]
|
||||
reverse_fn_order = False
|
||||
@@ -1305,7 +1301,6 @@ def generate_objdiff_config(
|
||||
{
|
||||
"complete": obj.completed,
|
||||
"reverse_fn_order": reverse_fn_order,
|
||||
"source_path": obj.src_path,
|
||||
"progress_categories": progress_categories,
|
||||
}
|
||||
)
|
||||
@@ -1371,16 +1366,11 @@ def calculate_progress(config: ProjectConfig) -> None:
|
||||
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"]
|
||||
@@ -1390,7 +1380,6 @@ def calculate_progress(config: ProjectConfig) -> 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
|
||||
@@ -1406,9 +1395,13 @@ def calculate_progress(config: ProjectConfig) -> None:
|
||||
self.objects_progress += 1
|
||||
|
||||
def code_frac(self) -> float:
|
||||
if self.code_total == 0:
|
||||
return 1.0
|
||||
return self.code_progress / self.code_total
|
||||
|
||||
def data_frac(self) -> float:
|
||||
if self.data_total == 0:
|
||||
return 1.0
|
||||
return self.data_progress / self.data_total
|
||||
|
||||
progress_units: Dict[str, ProgressUnit] = {}
|
||||
@@ -1461,44 +1454,47 @@ def calculate_progress(config: ProjectConfig) -> None:
|
||||
# Print human-readable progress
|
||||
print("Progress:")
|
||||
|
||||
def print_category(unit: Optional[ProgressUnit]) -> None:
|
||||
if unit is None:
|
||||
for unit in progress_units.values():
|
||||
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} / {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:
|
||||
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(
|
||||
f" {unit.name}: {code_frac:.2%} code, {data_frac:.2%} data ({unit.objects_progress} / {unit.objects_total} 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,
|
||||
)
|
||||
"\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,
|
||||
)
|
||||
|
||||
for progress in progress_units.values():
|
||||
print_category(progress)
|
||||
)
|
||||
|
||||
# Generate and write progress.json
|
||||
progress_json: Dict[str, Any] = {}
|
||||
|
||||
def add_category(category: str, unit: ProgressUnit) -> None:
|
||||
progress_json[category] = {
|
||||
for id, unit in progress_units.items():
|
||||
if len(unit.objects) == 0:
|
||||
continue
|
||||
progress_json[id] = {
|
||||
"code": unit.code_progress,
|
||||
"code/total": unit.code_total,
|
||||
"data": unit.data_progress,
|
||||
"data/total": unit.data_total,
|
||||
}
|
||||
|
||||
for id, progress in progress_units.items():
|
||||
add_category(id, progress)
|
||||
with open(out_path / "progress.json", "w", encoding="utf-8") as w:
|
||||
json.dump(progress_json, w, indent=4)
|
||||
|
||||
Reference in New Issue
Block a user