mirror of
https://github.com/encounter/dtk-template.git
synced 2025-12-17 00:47:23 +00:00
Update tools & format with ruff
This commit is contained in:
@@ -106,7 +106,7 @@ parser.add_argument(
|
|||||||
"--ninja",
|
"--ninja",
|
||||||
metavar="BINARY",
|
metavar="BINARY",
|
||||||
type=Path,
|
type=Path,
|
||||||
help="path to ninja binary (optional)"
|
help="path to ninja binary (optional)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--verbose",
|
"--verbose",
|
||||||
@@ -158,8 +158,8 @@ if not config.non_matching:
|
|||||||
# Tool versions
|
# Tool versions
|
||||||
config.binutils_tag = "2.42-1"
|
config.binutils_tag = "2.42-1"
|
||||||
config.compilers_tag = "20250812"
|
config.compilers_tag = "20250812"
|
||||||
config.dtk_tag = "v1.7.0"
|
config.dtk_tag = "v1.7.1"
|
||||||
config.objdiff_tag = "v3.4.0"
|
config.objdiff_tag = "v3.4.1"
|
||||||
config.sjiswrap_tag = "v1.2.2"
|
config.sjiswrap_tag = "v1.2.2"
|
||||||
config.wibo_tag = "1.0.0-beta.4"
|
config.wibo_tag = "1.0.0-beta.4"
|
||||||
|
|
||||||
@@ -312,6 +312,7 @@ def link_order_callback(module_id: int, objects: List[str]) -> List[str]:
|
|||||||
return objects + ["dummy.c"]
|
return objects + ["dummy.c"]
|
||||||
return objects
|
return objects
|
||||||
|
|
||||||
|
|
||||||
# Uncomment to enable the link order callback.
|
# Uncomment to enable the link order callback.
|
||||||
# config.link_order_callback = link_order_callback
|
# config.link_order_callback = link_order_callback
|
||||||
|
|
||||||
|
|||||||
@@ -18,11 +18,10 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
|
IO,
|
||||||
Any,
|
Any,
|
||||||
Callable,
|
Callable,
|
||||||
cast,
|
|
||||||
Dict,
|
Dict,
|
||||||
IO,
|
|
||||||
Iterable,
|
Iterable,
|
||||||
List,
|
List,
|
||||||
Optional,
|
Optional,
|
||||||
@@ -30,6 +29,7 @@ from typing import (
|
|||||||
Tuple,
|
Tuple,
|
||||||
TypedDict,
|
TypedDict,
|
||||||
Union,
|
Union,
|
||||||
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
from . import ninja_syntax
|
from . import ninja_syntax
|
||||||
@@ -167,7 +167,9 @@ class ProjectConfig:
|
|||||||
self.asflags: Optional[List[str]] = None # Assembler flags
|
self.asflags: Optional[List[str]] = None # Assembler flags
|
||||||
self.ldflags: Optional[List[str]] = None # Linker flags
|
self.ldflags: Optional[List[str]] = None # Linker flags
|
||||||
self.libs: Optional[List[Library]] = None # List of libraries
|
self.libs: Optional[List[Library]] = None # List of libraries
|
||||||
self.precompiled_headers: Optional[List[PrecompiledHeader]] = None # List of precompiled headers
|
self.precompiled_headers: Optional[List[PrecompiledHeader]] = (
|
||||||
|
None # List of precompiled headers
|
||||||
|
)
|
||||||
self.linker_version: Optional[str] = None # mwld version
|
self.linker_version: Optional[str] = None # mwld version
|
||||||
self.version: Optional[str] = None # Version name
|
self.version: Optional[str] = None # Version name
|
||||||
self.warn_missing_config: bool = False # Warn on missing unit configuration
|
self.warn_missing_config: bool = False # Warn on missing unit configuration
|
||||||
@@ -198,12 +200,12 @@ class ProjectConfig:
|
|||||||
self.link_order_callback: Optional[Callable[[int, List[str]], List[str]]] = (
|
self.link_order_callback: Optional[Callable[[int, List[str]], List[str]]] = (
|
||||||
None # Callback to add/remove/reorder units within a module
|
None # Callback to add/remove/reorder units within a module
|
||||||
)
|
)
|
||||||
self.context_exclude_globs: List[str] = (
|
self.context_exclude_globs: List[
|
||||||
[] # Globs to exclude from context files
|
str
|
||||||
)
|
] = [] # Globs to exclude from context files
|
||||||
self.context_defines: List[str] = (
|
self.context_defines: List[
|
||||||
[] # Macros to define at the top of context files
|
str
|
||||||
)
|
] = [] # Macros to define at the top of context files
|
||||||
|
|
||||||
# Progress output and report.json config
|
# Progress output and report.json config
|
||||||
self.progress = True # Enable report.json generation and CLI progress output
|
self.progress = True # Enable report.json generation and CLI progress output
|
||||||
@@ -680,9 +682,11 @@ def generate_build_ninja(
|
|||||||
mwcc_pch_sjis_implicit: List[Optional[Path]] = [*mwcc_implicit, sjiswrap]
|
mwcc_pch_sjis_implicit: List[Optional[Path]] = [*mwcc_implicit, sjiswrap]
|
||||||
|
|
||||||
# MWCC with extab post-processing
|
# MWCC with extab post-processing
|
||||||
mwcc_extab_cmd = f"{CHAIN}{mwcc_cmd} && {dtk} extab clean --padding \"$extab_padding\" $out $out"
|
mwcc_extab_cmd = (
|
||||||
|
f'{CHAIN}{mwcc_cmd} && {dtk} extab clean --padding "$extab_padding" $out $out'
|
||||||
|
)
|
||||||
mwcc_extab_implicit: List[Optional[Path]] = [*mwcc_implicit, dtk]
|
mwcc_extab_implicit: List[Optional[Path]] = [*mwcc_implicit, dtk]
|
||||||
mwcc_sjis_extab_cmd = f"{CHAIN}{mwcc_sjis_cmd} && {dtk} extab clean --padding \"$extab_padding\" $out $out"
|
mwcc_sjis_extab_cmd = f'{CHAIN}{mwcc_sjis_cmd} && {dtk} extab clean --padding "$extab_padding" $out $out'
|
||||||
mwcc_sjis_extab_implicit: List[Optional[Path]] = [*mwcc_sjis_implicit, dtk]
|
mwcc_sjis_extab_implicit: List[Optional[Path]] = [*mwcc_sjis_implicit, dtk]
|
||||||
|
|
||||||
# MWLD
|
# MWLD
|
||||||
@@ -820,7 +824,11 @@ def generate_build_ninja(
|
|||||||
)
|
)
|
||||||
n.newline()
|
n.newline()
|
||||||
|
|
||||||
def write_custom_step(step: str, prev_step: Optional[str] = None, extra_inputs: Optional[List[str]] = None) -> None:
|
def write_custom_step(
|
||||||
|
step: str,
|
||||||
|
prev_step: Optional[str] = None,
|
||||||
|
extra_inputs: Optional[List[str]] = None,
|
||||||
|
) -> None:
|
||||||
implicit: List[Union[str, Path]] = []
|
implicit: List[Union[str, Path]] = []
|
||||||
if config.custom_build_steps and step in config.custom_build_steps:
|
if config.custom_build_steps and step in config.custom_build_steps:
|
||||||
n.comment(f"Custom build steps ({step})")
|
n.comment(f"Custom build steps ({step})")
|
||||||
@@ -854,7 +862,9 @@ def generate_build_ninja(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Add all build steps needed before we compile (e.g. processing assets)
|
# Add all build steps needed before we compile (e.g. processing assets)
|
||||||
pch_out_names = [get_pch_out_name(config, pch) for pch in config.precompiled_headers or []]
|
pch_out_names = [
|
||||||
|
get_pch_out_name(config, pch) for pch in config.precompiled_headers or []
|
||||||
|
]
|
||||||
write_custom_step("pre-compile", extra_inputs=pch_out_names)
|
write_custom_step("pre-compile", extra_inputs=pch_out_names)
|
||||||
|
|
||||||
###
|
###
|
||||||
@@ -974,7 +984,11 @@ def generate_build_ninja(
|
|||||||
n.comment(f"Precompiled header {pch_out_name}")
|
n.comment(f"Precompiled header {pch_out_name}")
|
||||||
n.build(
|
n.build(
|
||||||
outputs=pch_out_abs_path,
|
outputs=pch_out_abs_path,
|
||||||
rule="mwcc_pch_sjis" if pch.get("shift_jis", config.shift_jis) else "mwcc_pch",
|
rule=(
|
||||||
|
"mwcc_pch_sjis"
|
||||||
|
if pch.get("shift_jis", config.shift_jis)
|
||||||
|
else "mwcc_pch"
|
||||||
|
),
|
||||||
inputs=f"include/{src_path_rel_str}",
|
inputs=f"include/{src_path_rel_str}",
|
||||||
variables={
|
variables={
|
||||||
"mw_version": Path(pch["mw_version"]),
|
"mw_version": Path(pch["mw_version"]),
|
||||||
@@ -1027,14 +1041,18 @@ def generate_build_ninja(
|
|||||||
if obj.options["shift_jis"] and obj.options["extab_padding"] is not None:
|
if obj.options["shift_jis"] and obj.options["extab_padding"] is not None:
|
||||||
build_rule = "mwcc_sjis_extab"
|
build_rule = "mwcc_sjis_extab"
|
||||||
build_implcit = mwcc_sjis_extab_implicit
|
build_implcit = mwcc_sjis_extab_implicit
|
||||||
variables["extab_padding"] = "".join(f"{i:02x}" for i in obj.options["extab_padding"])
|
variables["extab_padding"] = "".join(
|
||||||
|
f"{i:02x}" for i in obj.options["extab_padding"]
|
||||||
|
)
|
||||||
elif obj.options["shift_jis"]:
|
elif obj.options["shift_jis"]:
|
||||||
build_rule = "mwcc_sjis"
|
build_rule = "mwcc_sjis"
|
||||||
build_implcit = mwcc_sjis_implicit
|
build_implcit = mwcc_sjis_implicit
|
||||||
elif obj.options["extab_padding"] is not None:
|
elif obj.options["extab_padding"] is not None:
|
||||||
build_rule = "mwcc_extab"
|
build_rule = "mwcc_extab"
|
||||||
build_implcit = mwcc_extab_implicit
|
build_implcit = mwcc_extab_implicit
|
||||||
variables["extab_padding"] = "".join(f"{i:02x}" for i in obj.options["extab_padding"])
|
variables["extab_padding"] = "".join(
|
||||||
|
f"{i:02x}" for i in obj.options["extab_padding"]
|
||||||
|
)
|
||||||
n.comment(f"{obj.name}: {lib_name} (linked {obj.completed})")
|
n.comment(f"{obj.name}: {lib_name} (linked {obj.completed})")
|
||||||
n.build(
|
n.build(
|
||||||
outputs=obj.src_obj_path,
|
outputs=obj.src_obj_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user