Skip to content

Commit

Permalink
Missing dtk-template changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SeekyCt committed Sep 29, 2024
1 parent db551d3 commit f7588f7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 28 deletions.
1 change: 1 addition & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from tools.project import (
Object,
ProgressCategory,
ProjectConfig,
calculate_progress,
generate_build,
Expand Down
58 changes: 30 additions & 28 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,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 @@ -234,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 @@ -282,7 +284,7 @@ def generate_build_ninja(
# Variables
###
n.comment("Variables")
n.variable("ldflags", " ".join(config.ldflags or []))
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 @@ -1188,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 @@ -1365,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 @@ -1384,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 Down Expand Up @@ -1460,32 +1455,39 @@ def add_unit(id: str, unit: Dict[str, Any]) -> None:
print("Progress:")

for unit in progress_units.values():
if unit.objects_total == 0:
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,
)

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] = {}
for id, unit in progress_units.items():
if unit.objects_total == 0:
if len(unit.objects) == 0:
continue
progress_json[id] = {
"code": unit.code_progress,
Expand Down

0 comments on commit f7588f7

Please sign in to comment.