Skip to content

Commit

Permalink
Update dtk-template and objdiff (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper authored Sep 12, 2024
1 parent 1180e1f commit 3d0adbc
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 37 deletions.
18 changes: 13 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,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 @@ -135,8 +134,8 @@
# 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"

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

Expand Down Expand Up @@ -184,7 +189,10 @@
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")
Expand Down
72 changes: 40 additions & 32 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 @@ -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))
Expand Down Expand Up @@ -1236,14 +1230,19 @@ def add_unit(
"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:
Expand All @@ -1263,12 +1262,14 @@ def keep_flag(flag):
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']}")
Expand All @@ -1281,20 +1282,27 @@ def keep_flag(flag):
"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
Expand Down Expand Up @@ -1392,9 +1400,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 @@ -1447,9 +1459,9 @@ 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 unit.objects_total == 0:
continue

code_frac = unit.code_frac()
data_frac = unit.data_frac()
Expand All @@ -1470,21 +1482,17 @@ def print_category(unit: Optional[ProgressUnit]) -> 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)

0 comments on commit 3d0adbc

Please sign in to comment.