Update dtk-template and objdiff (#19)

This commit is contained in:
robojumper
2024-09-12 22:40:20 +02:00
committed by GitHub
parent 1180e1f486
commit 3d0adbc874
2 changed files with 53 additions and 37 deletions
+13 -5
View File
@@ -123,7 +123,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
@@ -135,8 +134,8 @@ if not config.non_matching:
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v0.9.4"
config.objdiff_tag = "v2.0.0-beta.5"
config.dtk_tag = "v0.9.5"
config.objdiff_tag = "v2.0.0"
config.sjiswrap_tag = "v1.1.1"
config.wibo_tag = "0.6.11"
@@ -154,8 +153,14 @@ config.linker_version = "Wii/1.6"
config.ldflags = [
"-fp hardware",
"-nodefaults",
"-listclosure", # Uncomment for Wii linkers
]
if args.debug:
# config.ldflags.append("-g")
config.ldflags.append("-gdwarf-2") # -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 = []
@@ -184,7 +189,10 @@ cflags_base = [
f"-i build/{config.version}/include",
f"-DVERSION={version_num}",
]
if config.debug:
# Debug flags
if args.debug:
# Or -sym dwarf-2 for Wii compilers
cflags_base.extend(["-sym on", "-DDEBUG=1"])
else:
cflags_base.append("-DNDEBUG=1")
+40 -32
View File
@@ -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
@@ -283,12 +282,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", " ".join(config.ldflags or []))
if config.linker_version is None:
sys.exit("ProjectConfig.linker_version missing")
n.variable("mw_version", Path(config.linker_version))
@@ -1236,14 +1230,19 @@ def generate_objdiff_config(
"target_path": obj_path,
"metadata": {
"auto_generated": build_obj["autogenerated"],
"progress_categories": progress_categories,
},
}
obj = objects.get(obj_name)
if obj is None or not obj.src_path or not obj.src_path.exists():
if obj is None:
objdiff_config["units"].append(unit_config)
return
src_exists = obj.src_path is not None and obj.src_path.exists()
if src_exists:
unit_config["base_path"] = obj.src_obj_path
cflags = obj.options["cflags"]
reverse_fn_order = False
if type(cflags) is list:
@@ -1263,12 +1262,14 @@ def generate_objdiff_config(
cflags = list(filter(keep_flag, cflags))
# Add appropriate lang flag
if obj.src_path.suffix in (".cp", ".cpp"):
cflags.insert(0, "-lang=c++")
else:
cflags.insert(0, "-lang=c")
if obj.src_path is not None and not any(
flag.startswith("-lang") for flag in cflags
):
if obj.src_path.suffix in (".cp", ".cpp"):
cflags.insert(0, "-lang=c++")
else:
cflags.insert(0, "-lang=c")
unit_config["base_path"] = obj.src_obj_path
compiler_version = COMPILER_MAP.get(obj.options["mw_version"])
if compiler_version is None:
print(f"Missing scratch compiler mapping for {obj.options['mw_version']}")
@@ -1281,20 +1282,27 @@ def generate_objdiff_config(
"platform": "gc_wii",
"compiler": compiler_version,
"c_flags": cflags_str,
"ctx_path": obj.ctx_path,
"build_ctx": True,
}
if src_exists:
unit_config["scratch"].update(
{
"ctx_path": obj.ctx_path,
"build_ctx": True,
}
)
category_opt: List[str] | str = obj.options["progress_category"]
if isinstance(category_opt, list):
progress_categories.extend(category_opt)
elif category_opt is not None:
progress_categories.append(category_opt)
unit_config["metadata"].update({
"complete": obj.completed,
"reverse_fn_order": reverse_fn_order,
"source_path": obj.src_path,
"progress_categories": progress_categories,
})
unit_config["metadata"].update(
{
"complete": obj.completed,
"reverse_fn_order": reverse_fn_order,
"source_path": obj.src_path,
"progress_categories": progress_categories,
}
)
objdiff_config["units"].append(unit_config)
# Add DOL units
@@ -1392,9 +1400,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] = {}
@@ -1447,9 +1459,9 @@ def calculate_progress(config: ProjectConfig) -> 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 unit.objects_total == 0:
continue
code_frac = unit.code_frac()
data_frac = unit.data_frac()
@@ -1470,21 +1482,17 @@ def calculate_progress(config: ProjectConfig) -> None:
)
)
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 unit.objects_total == 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)