Skip to content

Commit

Permalink
Sync dtk-template
Browse files Browse the repository at this point in the history
Update to 16efd6a02546684172234600194ce3b9d08307a5
  • Loading branch information
SeekyCt committed Sep 13, 2024
1 parent 8bb038e commit d2db8b4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
12 changes: 7 additions & 5 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
config.objdiff_path = args.objdiff
config.binutils_path = args.binutils
config.compilers_path = args.compilers
config.debug = args.debug
config.generate_map = args.map or True
config.non_matching = args.non_matching
config.sjiswrap_path = args.sjiswrap
Expand All @@ -137,7 +136,7 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v0.9.4"
config.dtk_tag = "v0.9.5"
config.objdiff_tag = "v2.0.0-beta.5"
config.sjiswrap_tag = "v1.1.1"
config.wibo_tag = "0.6.11"
Expand All @@ -155,9 +154,12 @@
config.ldflags = [
"-fp hardware",
"-nodefaults",
# "-warn off",
# "-listclosure", # Uncomment for Wii linkers
]
if args.debug:
config.ldflags.append("-g")
if args.map:
config.ldflags.append("-mapunused")

# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []

Expand Down Expand Up @@ -195,7 +197,7 @@
]

# Debug flags
if config.debug:
if args.debug:
cflags_base.extend(["-sym on", "-DDEBUG=1"])
else:
cflags_base.append("-DNDEBUG=1")
Expand Down
65 changes: 36 additions & 29 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,13 +1262,14 @@ def keep_flag(flag):
cflags = list(filter(keep_flag, cflags))

# Add appropriate lang flag
if not any(flag.startswith("-lang") for flag in cflags):
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 @@ -1282,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 @@ -1393,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 @@ -1448,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 @@ -1471,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 d2db8b4

Please sign in to comment.