mirror of
https://github.com/zeldaret/ph
synced 2026-06-16 06:35:36 -04:00
Download tools with Ninja instead of setup.py
This commit is contained in:
+80
-33
@@ -2,21 +2,27 @@
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import ninja_syntax
|
||||
from get_platform import get_platform
|
||||
|
||||
|
||||
DEFAULT_WIBO_PATH = "./wibo"
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(description="Generates build.ninja")
|
||||
parser.add_argument('-w', type=str, default="./wibo", dest="wine", required=False, help="Path to Wine/Wibo (linux only)")
|
||||
parser.add_argument('-w', type=str, default=DEFAULT_WIBO_PATH, dest="wine", required=False, help="Path to Wine/Wibo (linux only)")
|
||||
parser.add_argument("--compiler", type=Path, required=False, help="Path to compiler root directory")
|
||||
parser.add_argument('version', help='Game version')
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
# Config
|
||||
GAME = "ph"
|
||||
DSD_VERSION = 'v0.5.0'
|
||||
WIBO_VERSION = '0.6.16'
|
||||
MWCC_VERSION = "2.0/sp1p5"
|
||||
DECOMP_ME_COMPILER = "mwcc_30_131"
|
||||
CC_FLAGS = " ".join([
|
||||
@@ -65,7 +71,8 @@ src_path = root_path / "src"
|
||||
libs_path = root_path / "libs"
|
||||
extract_path = root_path / "extract"
|
||||
tools_path = root_path / "tools"
|
||||
mwcc_path = tools_path / "mwccarm" / MWCC_VERSION
|
||||
mwcc_root = args.compiler or tools_path / "mwccarm"
|
||||
mwcc_path = mwcc_root / MWCC_VERSION
|
||||
|
||||
|
||||
# Includes
|
||||
@@ -80,25 +87,14 @@ CC_INCLUDES = " ".join(f"-i {include}" for include in includes)
|
||||
|
||||
|
||||
# Platform info
|
||||
EXE = ""
|
||||
WINE = ""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
system = "windows"
|
||||
EXE = ".exe"
|
||||
elif system == "Linux":
|
||||
system = "linux"
|
||||
WINE = args.wine
|
||||
else:
|
||||
print(f"Unknown system '{system}'")
|
||||
platform = get_platform()
|
||||
if platform is None:
|
||||
exit(1)
|
||||
match platform.machine().lower():
|
||||
case "amd64" | "x86_64": machine = "x86_64"
|
||||
case machine:
|
||||
print(f"Unknown machine: {machine}")
|
||||
exit(1)
|
||||
|
||||
|
||||
EXE = platform.exe
|
||||
WINE = args.wine if platform.system != "windows" else ""
|
||||
DSD = str(root_path / f"dsd{EXE}")
|
||||
CC = str(mwcc_path / "mwccarm.exe")
|
||||
LD = str(mwcc_path / "mwldarm.exe")
|
||||
PYTHON = sys.executable
|
||||
|
||||
|
||||
@@ -112,6 +108,12 @@ def main():
|
||||
with build_ninja_path.open("w") as file:
|
||||
n = ninja_syntax.Writer(file)
|
||||
|
||||
n.rule(
|
||||
name="download_tool",
|
||||
command=f'{PYTHON} tools/download_tool.py $tool $tag --path $path'
|
||||
)
|
||||
n.newline()
|
||||
|
||||
if arm7_bios_path.is_file():
|
||||
n.variable("arm7_bios_flag", f"--arm7-bios {arm7_bios_path.relative_to(root_path)}")
|
||||
else:
|
||||
@@ -120,20 +122,20 @@ def main():
|
||||
|
||||
n.rule(
|
||||
name="extract",
|
||||
command="./dsd rom extract --rom $in --output-path $output_path $arm7_bios_flag"
|
||||
command=f"{DSD} rom extract --rom $in --output-path $output_path $arm7_bios_flag"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.rule(
|
||||
name="delink",
|
||||
command="./dsd delink --config-path $config_path"
|
||||
command=f"{DSD} delink --config-path $config_path"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
# -MMD excludes all includes instead of just system includes for some reason, so use -MD instead.
|
||||
mwcc_cmd = f'{WINE} "{mwcc_path}/mwccarm.exe" {CC_FLAGS} {CC_INCLUDES} $cc_flags -d $game_version -MD -c $in -o $basedir'
|
||||
mwcc_implicit = []
|
||||
if system != "windows":
|
||||
mwcc_cmd = f'{WINE} "{CC}" {CC_FLAGS} {CC_INCLUDES} $cc_flags -d $game_version -MD -c $in -o $basedir'
|
||||
mwcc_implicit = [CC]
|
||||
if platform.system != "windows":
|
||||
transform_dep = "tools/transform_dep.py"
|
||||
mwcc_cmd += f" && $python {transform_dep} $basefile.d $basefile.d"
|
||||
mwcc_implicit.append(transform_dep)
|
||||
@@ -146,31 +148,31 @@ def main():
|
||||
|
||||
n.rule(
|
||||
name="lcf",
|
||||
command="./dsd lcf -c $config_path --lcf-file $lcf_file --objects-file $objects_file"
|
||||
command=f"{DSD} lcf -c $config_path --lcf-file $lcf_file --objects-file $objects_file"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.rule(
|
||||
name="mwld",
|
||||
command=f'{WINE} "{mwcc_path}/mwldarm.exe" {LD_FLAGS} @$objects_file $lcf_file -o $out'
|
||||
command=f'{WINE} "{LD}" {LD_FLAGS} @$objects_file $lcf_file -o $out'
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.rule(
|
||||
name="rom_config",
|
||||
command="./dsd rom config --elf $in --config $config_path"
|
||||
command=f"{DSD} rom config --elf $in --config $config_path"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.rule(
|
||||
name="rom_build",
|
||||
command="./dsd rom build --config $in --rom $out $arm7_bios_flag"
|
||||
command=f"{DSD} rom build --config $in --rom $out $arm7_bios_flag"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
n.rule(
|
||||
name="objdiff",
|
||||
command=f"./dsd objdiff --config-path $config_path {DSD_OBJDIFF_ARGS}"
|
||||
command=f"{DSD} objdiff --config-path $config_path {DSD_OBJDIFF_ARGS}"
|
||||
)
|
||||
n.newline()
|
||||
|
||||
@@ -189,17 +191,56 @@ def main():
|
||||
game_build = build_path / game_version
|
||||
game_extract = extract_path / game_version
|
||||
|
||||
add_download_tool_builds(n)
|
||||
add_extract_build(n, game_extract, game_version)
|
||||
add_delink_and_lcf_builds(n, game_config, game_build, game_extract)
|
||||
add_mwcc_builds(n, game_version, game_build, mwcc_implicit)
|
||||
add_mwld_and_rom_builds(n, game_build, game_config, game_version)
|
||||
|
||||
|
||||
def add_download_tool_builds(n: ninja_syntax.Writer):
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=DSD,
|
||||
variables={
|
||||
"tool": "dsd",
|
||||
"tag": DSD_VERSION,
|
||||
"path": DSD,
|
||||
},
|
||||
)
|
||||
n.newline()
|
||||
|
||||
if args.compiler is None:
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=[CC, LD],
|
||||
variables={
|
||||
"tool": "mwccarm",
|
||||
"tag": "latest",
|
||||
"path": tools_path,
|
||||
},
|
||||
)
|
||||
n.newline()
|
||||
|
||||
if platform.system != "windows" and WINE == DEFAULT_WIBO_PATH:
|
||||
n.build(
|
||||
rule="download_tool",
|
||||
outputs=WINE,
|
||||
variables={
|
||||
"tool": "wibo",
|
||||
"tag": WIBO_VERSION,
|
||||
"path": WINE,
|
||||
},
|
||||
)
|
||||
n.newline()
|
||||
|
||||
|
||||
def add_extract_build(n: ninja_syntax.Writer, game_extract: Path, game_version: str):
|
||||
rom_path = extract_path / f'baserom_{GAME}_{game_version}.nds'
|
||||
rom_config = game_extract / 'config.yaml'
|
||||
n.build(
|
||||
inputs=str(rom_path),
|
||||
implicit=DSD,
|
||||
rule="extract",
|
||||
outputs=str(rom_config),
|
||||
variables={
|
||||
@@ -220,6 +261,7 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi
|
||||
elf_file = str(game_build / "arm9.o")
|
||||
n.build(
|
||||
inputs=source_object_files + [lcf_file, objects_file, delink_file],
|
||||
implicit=LD,
|
||||
rule="mwld",
|
||||
outputs=elf_file,
|
||||
variables={
|
||||
@@ -233,6 +275,7 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi
|
||||
rom_config_file = str(game_build / "build" / "rom_config.yaml")
|
||||
n.build(
|
||||
inputs=elf_file,
|
||||
implicit=DSD,
|
||||
rule="rom_config",
|
||||
outputs=rom_config_file,
|
||||
variables={
|
||||
@@ -243,7 +286,8 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi
|
||||
|
||||
rom_file = f"{GAME}_{game_version}.nds"
|
||||
n.build(
|
||||
inputs=[rom_config_file],
|
||||
inputs=rom_config_file,
|
||||
implicit=DSD,
|
||||
rule="rom_build",
|
||||
outputs=rom_file,
|
||||
)
|
||||
@@ -275,6 +319,7 @@ def add_mwcc_builds(n: ninja_syntax.Writer, game_version: str, game_build: Path,
|
||||
elif is_c(source_file): cc_flags.append("-lang=c")
|
||||
n.build(
|
||||
inputs=str(source_file),
|
||||
implicit=mwcc_implicit,
|
||||
rule="mwcc",
|
||||
outputs=str(src_obj_path.with_suffix(".o")),
|
||||
variables={
|
||||
@@ -283,7 +328,6 @@ def add_mwcc_builds(n: ninja_syntax.Writer, game_version: str, game_build: Path,
|
||||
"basedir": os.path.dirname(src_obj_path),
|
||||
"basefile": str(src_obj_path.with_suffix("")),
|
||||
},
|
||||
implicit=mwcc_implicit,
|
||||
)
|
||||
n.newline()
|
||||
|
||||
@@ -323,6 +367,7 @@ def add_delink_and_lcf_builds(n: ninja_syntax.Writer, game_config: Path, game_bu
|
||||
delinks_path = game_build / "delinks"
|
||||
n.build(
|
||||
inputs=delinks_files + relocs_files + symbols_files + [rom_config],
|
||||
implicit=DSD,
|
||||
rule="delink",
|
||||
outputs=str(delinks_path / "delink.yaml"),
|
||||
variables={
|
||||
@@ -342,6 +387,7 @@ def add_delink_and_lcf_builds(n: ninja_syntax.Writer, game_config: Path, game_bu
|
||||
objects_file = game_build / "objects.txt"
|
||||
n.build(
|
||||
inputs=delinks_files + [str(rom_config)],
|
||||
implicit=DSD,
|
||||
rule="lcf",
|
||||
outputs=[str(lcf_file), str(objects_file)],
|
||||
variables={
|
||||
@@ -354,6 +400,7 @@ def add_delink_and_lcf_builds(n: ninja_syntax.Writer, game_config: Path, game_bu
|
||||
|
||||
n.build(
|
||||
inputs=delinks_files + relocs_files + symbols_files,
|
||||
implicit=DSD,
|
||||
rule="objdiff",
|
||||
outputs="objdiff.json",
|
||||
variables={
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from get_platform import get_platform
|
||||
import zipfile
|
||||
import io
|
||||
import requests
|
||||
import stat
|
||||
|
||||
root_path = Path(__file__).parent.parent
|
||||
|
||||
|
||||
platform = get_platform()
|
||||
if platform is None:
|
||||
exit(1)
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("tool")
|
||||
parser.add_argument("tag")
|
||||
parser.add_argument("--path", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
def dsd_url(tag: str) -> str:
|
||||
return f'https://github.com/AetiasHax/ds-decomp/releases/download/{tag}/dsd-{platform.system}-{platform.machine}{platform.exe}'
|
||||
|
||||
def mwccarm_url(tag: str) -> str:
|
||||
return 'http://decomp.aetias.com/files/mwccarm.zip'
|
||||
|
||||
def wibo_url(tag: str) -> str:
|
||||
return f'https://github.com/decompals/wibo/releases/download/{tag}/wibo'
|
||||
|
||||
TOOLS = {
|
||||
"dsd": dsd_url,
|
||||
"mwccarm": mwccarm_url,
|
||||
"wibo": wibo_url,
|
||||
}
|
||||
|
||||
|
||||
download_url = TOOLS[args.tool](args.tag)
|
||||
print(f'\nDownloading {args.tool} {args.tag}...')
|
||||
response = requests.get(download_url)
|
||||
if download_url.endswith('.zip'):
|
||||
zip_file = zipfile.ZipFile(io.BytesIO(response.content))
|
||||
zip_file.extractall(args.path)
|
||||
else:
|
||||
out_path: Path = args.path
|
||||
with out_path.open('wb') as f:
|
||||
f.write(response.content)
|
||||
out_path.chmod(out_path.stat().st_mode | stat.S_IEXEC)
|
||||
@@ -0,0 +1,31 @@
|
||||
import platform
|
||||
|
||||
|
||||
class Platform:
|
||||
def __init__(self, *, system: str, machine: str, exe: str):
|
||||
self.system = system
|
||||
'''Name of operating system: "windows" or "linux"'''
|
||||
self.machine = machine
|
||||
'''Name of machine architecture: "x86_64"'''
|
||||
self.exe = exe
|
||||
'''Executable file extension: ".exe" for Windows, "" otherwise'''
|
||||
|
||||
|
||||
def get_platform() -> Platform | None:
|
||||
exe = ""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
system = "windows"
|
||||
exe = ".exe"
|
||||
elif system == "Linux":
|
||||
system = "linux"
|
||||
else:
|
||||
print(f"Unknown system '{system}'")
|
||||
return None
|
||||
match platform.machine().lower():
|
||||
case "amd64" | "x86_64": machine = "x86_64"
|
||||
case machine:
|
||||
print(f"Unknown machine: {machine}")
|
||||
return None
|
||||
|
||||
return Platform(system=system, machine=machine, exe=exe)
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import zipfile
|
||||
import io
|
||||
from pathlib import Path
|
||||
import platform
|
||||
import stat
|
||||
|
||||
DSD_VERSION = 'v0.5.0'
|
||||
WIBO_VERSION = '0.6.16'
|
||||
|
||||
|
||||
tools_path = Path(__file__).parent
|
||||
root_path = tools_path.parent
|
||||
|
||||
|
||||
EXE = ""
|
||||
system = platform.system()
|
||||
if system == "Windows":
|
||||
system = "windows"
|
||||
EXE = ".exe"
|
||||
elif system == "Linux":
|
||||
system = "linux"
|
||||
else:
|
||||
print(f"Unknown system '{system}'")
|
||||
exit(1)
|
||||
match platform.machine().lower():
|
||||
case 'amd64' | 'x86_64': machine = 'x86_64'
|
||||
case machine:
|
||||
print(f'Unknown machine: {machine}')
|
||||
exit(1)
|
||||
|
||||
|
||||
print('\nInstalling dsd...')
|
||||
response = requests.get(f'https://github.com/AetiasHax/ds-decomp/releases/download/{DSD_VERSION}/dsd-{system}-{machine}{EXE}')
|
||||
dsd_path = root_path / f'dsd{EXE}'
|
||||
with open(dsd_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
dsd_path.chmod(dsd_path.stat().st_mode | stat.S_IEXEC)
|
||||
|
||||
|
||||
print('\nInstalling toolchain...')
|
||||
response = requests.get('http://decomp.aetias.com/files/mwccarm.zip')
|
||||
zip_file = zipfile.ZipFile(io.BytesIO(response.content))
|
||||
zip_file.extractall(tools_path)
|
||||
|
||||
|
||||
if system == "linux":
|
||||
print('\nInstalling wibo...')
|
||||
response = requests.get(f'https://github.com/decompals/wibo/releases/download/{WIBO_VERSION}/wibo')
|
||||
wibo_path = root_path / 'wibo'
|
||||
with open(wibo_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
wibo_path.chmod(wibo_path.stat().st_mode | stat.S_IEXEC)
|
||||
|
||||
Reference in New Issue
Block a user