Support specifying a dtk binary (#14)

This commit is contained in:
Robin Avery 2024-03-04 20:13:10 -05:00 committed by GitHub
parent 6debc74abf
commit 1d3192a4aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 34 deletions

View File

@ -12,11 +12,11 @@
# Append --help to see available options. # Append --help to see available options.
### ###
import sys
import argparse import argparse
import sys
from pathlib import Path from pathlib import Path
from typing import Dict, List, Any from typing import Any, Dict, List
from tools.project import ( from tools.project import (
Object, Object,
ProjectConfig, ProjectConfig,
@ -31,91 +31,83 @@ VERSIONS = [
"GAMEID", # 0 "GAMEID", # 0
] ]
if len(VERSIONS) > 1:
versions_str = ", ".join(VERSIONS[:-1]) + f" or {VERSIONS[-1]}"
else:
versions_str = VERSIONS[0]
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"mode", "mode",
choices=["configure", "progress"],
default="configure", default="configure",
help="configure or progress (default: configure)", help="script mode (default: configure)",
nargs="?", nargs="?",
) )
parser.add_argument( parser.add_argument(
"--version", "--version",
dest="version", choices=VERSIONS,
type=str.upper,
default=VERSIONS[DEFAULT_VERSION], default=VERSIONS[DEFAULT_VERSION],
help=f"version to build ({versions_str})", help=f"version to build",
) )
parser.add_argument( parser.add_argument(
"--build-dir", "--build-dir",
dest="build_dir", metavar="DIR",
type=Path, type=Path,
default=Path("build"), default=Path("build"),
help="base build directory (default: build)", help="base build directory (default: build)",
) )
parser.add_argument( parser.add_argument(
"--binutils", "--binutils",
dest="binutils", metavar="BINARY",
type=Path, type=Path,
help="path to binutils (optional)", help="path to binutils (optional)",
) )
parser.add_argument( parser.add_argument(
"--compilers", "--compilers",
dest="compilers", metavar="DIR",
type=Path, type=Path,
help="path to compilers (optional)", help="path to compilers (optional)",
) )
parser.add_argument( parser.add_argument(
"--map", "--map",
dest="map",
action="store_true", action="store_true",
help="generate map file(s)", help="generate map file(s)",
) )
parser.add_argument( parser.add_argument(
"--debug", "--debug",
dest="debug",
action="store_true", action="store_true",
help="build with debug info (non-matching)", help="build with debug info (non-matching)",
) )
if not is_windows(): if not is_windows():
parser.add_argument( parser.add_argument(
"--wrapper", "--wrapper",
dest="wrapper", metavar="BINARY",
type=Path, type=Path,
help="path to wibo or wine (optional)", help="path to wibo or wine (optional)",
) )
parser.add_argument( parser.add_argument(
"--build-dtk", "--dtk",
dest="build_dtk", metavar="BINARY | DIR",
type=Path, type=Path,
help="path to decomp-toolkit source (optional)", help="path to decomp-toolkit binary or source (optional)",
) )
parser.add_argument( parser.add_argument(
"--sjiswrap", "--sjiswrap",
dest="sjiswrap", metavar="EXE",
type=Path, type=Path,
help="path to sjiswrap.exe (optional)", help="path to sjiswrap.exe (optional)",
) )
parser.add_argument( parser.add_argument(
"--verbose", "--verbose",
dest="verbose",
action="store_true", action="store_true",
help="print verbose output", help="print verbose output",
) )
args = parser.parse_args() args = parser.parse_args()
config = ProjectConfig() config = ProjectConfig()
config.version = args.version.upper() config.version = args.version
if config.version not in VERSIONS:
sys.exit(f"Invalid version '{config.version}', expected {versions_str}")
version_num = VERSIONS.index(config.version) version_num = VERSIONS.index(config.version)
# Apply arguments # Apply arguments
config.build_dir = args.build_dir config.build_dir = args.build_dir
config.build_dtk_path = args.build_dtk config.dtk_path = args.dtk
config.binutils_path = args.binutils config.binutils_path = args.binutils
config.compilers_path = args.compilers config.compilers_path = args.compilers
config.debug = args.debug config.debug = args.debug

View File

@ -60,7 +60,7 @@ class ProjectConfig:
self.binutils_tag: Optional[str] = None # Git tag self.binutils_tag: Optional[str] = None # Git tag
self.binutils_path: Optional[Path] = None # If None, download self.binutils_path: Optional[Path] = None # If None, download
self.dtk_tag: Optional[str] = None # Git tag self.dtk_tag: Optional[str] = None # Git tag
self.build_dtk_path: Optional[Path] = None # If None, download self.dtk_path: Optional[Path] = None # If None, download
self.compilers_tag: Optional[str] = None # 1 self.compilers_tag: Optional[str] = None # 1
self.compilers_path: Optional[Path] = None # If None, download self.compilers_path: Optional[Path] = None # If None, download
self.wibo_tag: Optional[str] = None # Git tag self.wibo_tag: Optional[str] = None # Git tag
@ -82,9 +82,9 @@ class ProjectConfig:
self.warn_missing_config: bool = False # Warn on missing unit configuration self.warn_missing_config: bool = False # Warn on missing unit configuration
self.warn_missing_source: bool = False # Warn on missing source file self.warn_missing_source: bool = False # Warn on missing source file
self.rel_strip_partial: bool = True # Generate PLFs with -strip_partial self.rel_strip_partial: bool = True # Generate PLFs with -strip_partial
self.rel_empty_file: Optional[str] = ( self.rel_empty_file: Optional[
None # Object name for generating empty RELs str
) ] = None # Object name for generating empty RELs
self.shift_jis = ( self.shift_jis = (
True # Convert source files from UTF-8 to Shift JIS automatically True # Convert source files from UTF-8 to Shift JIS automatically
) )
@ -242,7 +242,7 @@ def generate_build_ninja(
deps="gcc", deps="gcc",
) )
if config.build_dtk_path: if config.dtk_path:
dtk = build_tools_path / "release" / f"dtk{EXE}" dtk = build_tools_path / "release" / f"dtk{EXE}"
n.rule( n.rule(
name="cargo", name="cargo",
@ -254,8 +254,8 @@ def generate_build_ninja(
n.build( n.build(
outputs=dtk, outputs=dtk,
rule="cargo", rule="cargo",
inputs=config.build_dtk_path / "Cargo.toml", inputs=config.dtk_path / "Cargo.toml",
implicit=config.build_dtk_path / "Cargo.lock", implicit=config.dtk_path / "Cargo.lock",
variables={ variables={
"bin": "dtk", "bin": "dtk",
"target": build_tools_path, "target": build_tools_path,
@ -559,7 +559,6 @@ def generate_build_ninja(
def c_build( def c_build(
obj: Object, options: Dict[str, Any], lib_name: str, src_path: Path obj: Object, options: Dict[str, Any], lib_name: str, src_path: Path
) -> Optional[Path]: ) -> Optional[Path]:
cflags_str = make_flags_str(options["cflags"]) cflags_str = make_flags_str(options["cflags"])
if options["extra_cflags"] is not None: if options["extra_cflags"] is not None:
extra_cflags_str = make_flags_str(options["extra_cflags"]) extra_cflags_str = make_flags_str(options["extra_cflags"])