Skip to content

Commit

Permalink
Update from dtk-template
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Sep 29, 2024
1 parent 431e1c1 commit e04a8da
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 50 deletions.
25 changes: 19 additions & 6 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@
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
Expand Down Expand Up @@ -124,7 +132,6 @@
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
Expand All @@ -136,8 +143,8 @@
# 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"

Expand All @@ -154,8 +161,13 @@
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 = []

Expand Down Expand Up @@ -191,7 +203,8 @@
]

# 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")
Expand Down
84 changes: 40 additions & 44 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def __init__(self) -> None:
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
Expand Down Expand Up @@ -214,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
Expand All @@ -235,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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1248,6 +1243,7 @@ def add_unit(
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
Expand Down Expand Up @@ -1305,7 +1301,6 @@ def keep_flag(flag):
{
"complete": obj.completed,
"reverse_fn_order": reverse_fn_order,
"source_path": obj.src_path,
"progress_categories": progress_categories,
}
)
Expand Down Expand Up @@ -1371,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"]
Expand All @@ -1390,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
Expand All @@ -1406,9 +1395,13 @@ def add(self, build_obj: Dict[str, Any]) -> 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] = {}
Expand Down Expand Up @@ -1461,44 +1454,47 @@ def add_unit(id: str, unit: Dict[str, Any]) -> None:
# Print human-readable progress
print("Progress:")

def print_category(unit: Optional[ProgressUnit]) -> None:
if unit is None:
return
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} / {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,
)
)

for progress in progress_units.values():
print_category(progress)
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] = {}

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)

0 comments on commit e04a8da

Please sign in to comment.