Skip to content

Commit

Permalink
Update dtk and dtk-template
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Nov 1, 2024
1 parent 8911dab commit dc64d54
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
6 changes: 3 additions & 3 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
config.dtk_tag = "v1.1.4"
config.objdiff_tag = "v2.3.2"
config.sjiswrap_tag = "v1.1.1"
config.dtk_tag = "v1.2.0"
config.objdiff_tag = "v2.3.4"
config.sjiswrap_tag = "v1.2.0"
config.wibo_tag = "0.6.11"

# Project
Expand Down
23 changes: 9 additions & 14 deletions tools/ninja_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,10 @@
import os
from io import StringIO
from pathlib import Path
from typing import Dict, List, Match, Optional, Tuple, Union
from typing import Dict, Iterable, List, Match, Optional, Tuple, Union

NinjaPath = Union[str, Path]
NinjaPaths = Union[
List[str],
List[Path],
List[NinjaPath],
List[Optional[str]],
List[Optional[Path]],
List[Optional[NinjaPath]],
]
NinjaPaths = Iterable[Optional[NinjaPath]]
NinjaPathOrPaths = Union[NinjaPath, NinjaPaths]


Expand Down Expand Up @@ -118,8 +111,8 @@ def build(
pool: Optional[str] = None,
dyndep: Optional[NinjaPath] = None,
) -> List[str]:
outputs = serialize_paths(outputs)
out_outputs = [escape_path(x) for x in outputs]
str_outputs = serialize_paths(outputs)
out_outputs = [escape_path(x) for x in str_outputs]
all_inputs = [escape_path(x) for x in serialize_paths(inputs)]

if implicit:
Expand Down Expand Up @@ -154,7 +147,7 @@ def build(
for key, val in iterator:
self.variable(key, val, indent=1)

return outputs
return str_outputs

def include(self, path: str) -> None:
self._line("include %s" % path)
Expand Down Expand Up @@ -225,9 +218,11 @@ def serialize_path(input: Optional[NinjaPath]) -> str:


def serialize_paths(input: Optional[NinjaPathOrPaths]) -> List[str]:
if isinstance(input, list):
if isinstance(input, str) or isinstance(input, Path):
return [serialize_path(input)] if input else []
elif input is not None:
return [serialize_path(path) for path in input if path]
return [serialize_path(input)] if input else []
return []


def escape(string: str) -> str:
Expand Down
45 changes: 29 additions & 16 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def write_cargo_rule():
)
n.newline()

def write_custom_step(step: str) -> List[str | Path]:
def write_custom_step(step: str, prev_step: Optional[str] = None) -> None:
implicit: List[str | Path] = []
if config.custom_build_steps and step in config.custom_build_steps:
n.comment(f"Custom build steps ({step})")
Expand All @@ -657,7 +657,12 @@ def write_custom_step(step: str) -> List[str | Path]:
dyndep=custom_step.get("dyndep", None),
)
n.newline()
return implicit
n.build(
outputs=step,
rule="phony",
inputs=implicit,
order_only=prev_step,
)

n.comment("Host build")
n.variable("host_cflags", "-I include -Wno-trigraphs")
Expand All @@ -678,7 +683,7 @@ def write_custom_step(step: str) -> List[str | Path]:
n.newline()

# Add all build steps needed before we compile (e.g. processing assets)
precompile_implicit = write_custom_step("pre-compile")
write_custom_step("pre-compile")

###
# Source files
Expand Down Expand Up @@ -726,13 +731,12 @@ def write(self, n: ninja_syntax.Writer) -> None:
rule="link",
inputs=self.inputs,
implicit=[
*precompile_implicit,
self.ldscript,
*mwld_implicit,
*postcompile_implicit,
],
implicit_outputs=elf_map,
variables={"ldflags": elf_ldflags},
order_only="post-compile",
)
else:
preplf_path = build_path / self.name / f"{self.name}.preplf"
Expand All @@ -759,6 +763,7 @@ def write(self, n: ninja_syntax.Writer) -> None:
implicit=mwld_implicit,
implicit_outputs=preplf_map,
variables={"ldflags": preplf_ldflags},
order_only="post-compile",
)
n.build(
outputs=plf_path,
Expand All @@ -767,6 +772,7 @@ def write(self, n: ninja_syntax.Writer) -> None:
implicit=[self.ldscript, preplf_path, *mwld_implicit],
implicit_outputs=plf_map,
variables={"ldflags": plf_ldflags},
order_only="post-compile",
)
n.newline()

Expand Down Expand Up @@ -822,6 +828,7 @@ def c_build(obj: Object, src_path: Path) -> Optional[Path]:
implicit=(
mwcc_sjis_implicit if obj.options["shift_jis"] else mwcc_implicit
),
order_only="pre-compile",
)

# Add ctx build rule
Expand All @@ -843,6 +850,7 @@ def c_build(obj: Object, src_path: Path) -> Optional[Path]:
"basedir": os.path.dirname(obj.host_obj_path),
"basefile": obj.host_obj_path.with_suffix(""),
},
order_only="pre-compile",
)
if obj.options["add_to_all"]:
host_source_inputs.append(obj.host_obj_path)
Expand Down Expand Up @@ -877,6 +885,7 @@ def asm_build(
inputs=src_path,
variables={"asflags": asflags_str},
implicit=gnu_as_implicit,
order_only="pre-compile",
)
n.newline()

Expand Down Expand Up @@ -966,7 +975,7 @@ def add_unit(build_obj, link_step: LinkStep):
sys.exit(f"Linker {mw_path} does not exist")

# Add all build steps needed before we link and after compiling objects
postcompile_implicit = write_custom_step("post-compile")
write_custom_step("post-compile", "pre-compile")

###
# Link
Expand All @@ -977,7 +986,7 @@ def add_unit(build_obj, link_step: LinkStep):
n.newline()

# Add all build steps needed after linking and before GC/Wii native format generation
postlink_implicit = write_custom_step("post-link")
write_custom_step("post-link", "post-compile")

###
# Generate DOL
Expand All @@ -986,7 +995,8 @@ def add_unit(build_obj, link_step: LinkStep):
outputs=link_steps[0].output(),
rule="elf2dol",
inputs=link_steps[0].partial_output(),
implicit=[*postlink_implicit, dtk],
implicit=dtk,
order_only="post-link",
)

###
Expand Down Expand Up @@ -1048,11 +1058,12 @@ def add_unit(build_obj, link_step: LinkStep):
"rspfile": config.out_path() / f"rel{idx}.rsp",
"names": rel_names_arg,
},
order_only="post-link",
)
n.newline()

# Add all build steps needed post-build (re-building archives and such)
postbuild_implicit = write_custom_step("post-build")
write_custom_step("post-build", "post-link")

###
# Helper rule for building all source files
Expand Down Expand Up @@ -1091,7 +1102,8 @@ def add_unit(build_obj, link_step: LinkStep):
outputs=ok_path,
rule="check",
inputs=config.check_sha_path,
implicit=[dtk, *link_outputs, *postbuild_implicit],
implicit=[dtk, *link_outputs],
order_only="post-build",
)
n.newline()

Expand All @@ -1113,6 +1125,7 @@ def add_unit(build_obj, link_step: LinkStep):
python_lib,
report_path,
],
order_only="post-build",
)

###
Expand All @@ -1124,11 +1137,11 @@ def add_unit(build_obj, link_step: LinkStep):
command=f"{objdiff} report generate -o $out",
description="REPORT",
)
report_implicit: List[str | Path] = [objdiff, "all_source"]
n.build(
outputs=report_path,
rule="report",
implicit=report_implicit,
implicit=[objdiff, "all_source"],
order_only="post-build",
)

###
Expand Down Expand Up @@ -1386,7 +1399,7 @@ def keep_flag(flag):
progress_categories.append(category_opt)
unit_config["metadata"].update(
{
"complete": obj.completed,
"complete": obj.completed if src_exists else None,
"reverse_fn_order": reverse_fn_order,
"progress_categories": progress_categories,
}
Expand Down Expand Up @@ -1680,7 +1693,7 @@ def convert_numbers(data: Dict[str, Any]) -> None:
data[key] = int(value)

convert_numbers(report_data["measures"])
for category in report_data["categories"]:
for category in report_data.get("categories", []):
convert_numbers(category["measures"])

# Output to GitHub Actions job summary, if available
Expand Down Expand Up @@ -1722,7 +1735,7 @@ def print_category(name: str, measures: Dict[str, Any]) -> None:
)

print_category("All", report_data["measures"])
for category in report_data["categories"]:
for category in report_data.get("categories", []):
if config.print_progress_categories is True or (
isinstance(config.print_progress_categories, list)
and category["id"] in config.print_progress_categories
Expand Down Expand Up @@ -1780,7 +1793,7 @@ def add_category(id: str, measures: Dict[str, Any]) -> None:
else:
# Support for old behavior where "dol" was the main category
add_category("dol", report_data["measures"])
for category in report_data["categories"]:
for category in report_data.get("categories", []):
add_category(category["id"], category["measures"])

with open(out_path / "progress.json", "w", encoding="utf-8") as w:
Expand Down

0 comments on commit dc64d54

Please sign in to comment.