From d09507c60cc6734c85a9f1aadfcd5e02dbd79563 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Mon, 30 Jan 2023 00:31:09 -0800 Subject: [PATCH 1/5] tp.py: setup: refactor lmgr326b.dll copy, and also do it for 1.2.5e --- tools/tp.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tools/tp.py b/tools/tp.py index 74f5b2ad9e3..9a60fcfbf7e 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -202,14 +202,12 @@ def setup(debug: bool, game_path: Path, tools_path: Path): ) sys.exit(1) - c27_lmgr326b = c27.joinpath("Lmgr326b.dll") - if not c27_lmgr326b.exists() or not c27_lmgr326b.is_file(): - c27_lmgr326b = c27.joinpath("lmgr326b.dll") - if not c27_lmgr326b.exists() or not c27_lmgr326b.is_file(): - c27_lmgr326b = c27.joinpath("LMGR326B.dll") - if not c27_lmgr326b.exists() or not c27_lmgr326b.is_file(): - c27_lmgr326b = c27.joinpath("LMGR326B.DLL") - if not c27_lmgr326b.exists() or not c27_lmgr326b.is_file(): + c27_lmgr326b = None + for name in os.listdir(c27): + if name.lower() == "lmgr326b.dll": + c27_lmgr326b = c27.joinpath(name) + break + if not c27_lmgr326b or not c27_lmgr326b.is_file(): LOG.error( ( f"Unable to find 'lmgr326b.dll' in '{c27}': missing file '{c27_lmgr326b}'\n" @@ -218,15 +216,15 @@ def setup(debug: bool, game_path: Path, tools_path: Path): ) sys.exit(1) - c27_lmgr326b_cc = c27.joinpath("LMGR326B.dll") - if not c27_lmgr326b_cc.exists() or not c27_lmgr326b_cc.is_file(): - LOG.debug(f"copy: '{c27_lmgr326b}', to: '{c27_lmgr326b_cc}'") - shutil.copy(c27_lmgr326b, c27_lmgr326b_cc) + def copy_lmgr326b(path: Path): + lmgr326b_cc = path.joinpath("LMGR326B.dll") + if not lmgr326b_cc.is_file(): + LOG.debug(f"copy: '{c27_lmgr326b}', to: '{lmgr326b_cc}'") + shutil.copy(c27_lmgr326b, lmgr326b_cc) - c125_lmgr326b_cc = c125.joinpath("LMGR326B.dll") - if not c125_lmgr326b_cc.exists() or not c125_lmgr326b_cc.is_file(): - LOG.debug(f"copy: '{c27_lmgr326b}', to: '{c125_lmgr326b_cc}'") - shutil.copy(c27_lmgr326b, c125_lmgr326b_cc) + copy_lmgr326b(c27) + copy_lmgr326b(c125) + copy_lmgr326b(c125e) c27_mwcceppc = c27.joinpath("mwcceppc.exe") if not c27_mwcceppc.exists() or not c27_mwcceppc.is_file(): From 6b031acca9c3ceb5e5d6bd2a4c1ae53407f36672 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Mon, 30 Jan 2023 00:47:12 -0800 Subject: [PATCH 2/5] Makefile: 'tools' target should depend on 'dirs' --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fe9759de1c3..e112a5d7045 100644 --- a/Makefile +++ b/Makefile @@ -152,7 +152,7 @@ clean_rels: rm -f -d -r $(BUILD_DIR)/rel rm -f $(BUILD_PATH)/*.rel -tools: $(ELF2DOL) $(YAZ0) +tools: dirs $(ELF2DOL) $(YAZ0) assets: @mkdir -p game From 5d49bb7777719ab2438b3d8722174362aa8f98f3 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Mon, 30 Jan 2023 01:10:07 -0800 Subject: [PATCH 3/5] tp.py: setup: Add execute flag to compilers on posix systems --- tools/tp.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/tp.py b/tools/tp.py index 9a60fcfbf7e..ede633b5ea0 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -295,6 +295,10 @@ def setup(debug: bool, game_path: Path, tools_path: Path): ) sys.exit(1) + # add execute flag to compilers for WSL + if os.name == 'posix': + subprocess.run(['chmod', '+x'] + list(compilers.glob("*/*.exe"))) + # text = Text("--- Extracting game assets") text.stylize("bold magenta") From 61fc276734b09e874c174f7f35790f4c9924c805 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Mon, 30 Jan 2023 01:13:27 -0800 Subject: [PATCH 4/5] requirements.txt: remove standard libraries that pip cannot install --- tools/requirements.txt | 2 -- tools/tp.py | 10 ++++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/tools/requirements.txt b/tools/requirements.txt index 6062e07974f..d6052029675 100644 --- a/tools/requirements.txt +++ b/tools/requirements.txt @@ -9,5 +9,3 @@ python-Levenshtein cxxfilt pyelftools requests -zipfile -shutil \ No newline at end of file diff --git a/tools/tp.py b/tools/tp.py index ede633b5ea0..48f0105acd8 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -4,16 +4,19 @@ tp.py - Various tools used for the zeldaret/tp project. """ +import hashlib +import io import os import sys import time -import struct import json import subprocess +import logging import multiprocessing as mp import shutil import platform import stat +import zipfile from dataclasses import dataclass, field from typing import Dict, List, Set, Tuple @@ -21,16 +24,11 @@ from pathlib import Path try: import click - import logging - import hashlib import libdol import librel import libarc - import io import extract_game_assets import requests - import zipfile - import shutil from rich.logging import RichHandler from rich.console import Console From cd4a37fdd4edec0c6f921536eaf821515ee9df14 Mon Sep 17 00:00:00 2001 From: Jcw87 Date: Mon, 30 Jan 2023 09:19:24 -0800 Subject: [PATCH 5/5] tp.py: setup: call 'make tools' --- tools/tp.py | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/tools/tp.py b/tools/tp.py index 48f0105acd8..0e8a5585ca3 100644 --- a/tools/tp.py +++ b/tools/tp.py @@ -22,20 +22,8 @@ from dataclasses import dataclass, field from typing import Dict, List, Set, Tuple from pathlib import Path -try: - import click - import libdol - import librel - import libarc - import extract_game_assets - import requests - from rich.logging import RichHandler - from rich.console import Console - from rich.progress import Progress - from rich.text import Text - from rich.table import Table -except ImportError as e: +def _handle_import_error(ex: ImportError): MISSING_PREREQUISITES = ( f"Missing prerequisite python module {e}.\n" f"Run `python3 -m pip install --user -r tools/requirements.txt` to install prerequisites." @@ -44,6 +32,20 @@ except ImportError as e: print(MISSING_PREREQUISITES, file=sys.stderr) sys.exit(1) +try: + import click + import libdol + import libarc + import requests + + from rich.logging import RichHandler + from rich.console import Console + from rich.progress import Progress + from rich.text import Text + from rich.table import Table +except ImportError as ex: + _handle_import_error(ex) + class PathPath(click.Path): def convert(self, value, param, ctx): @@ -297,6 +299,14 @@ def setup(debug: bool, game_path: Path, tools_path: Path): if os.name == 'posix': subprocess.run(['chmod', '+x'] + list(compilers.glob("*/*.exe"))) + # + text = Text("--- Building tools") + text.stylize("bold magenta") + CONSOLE.print(text) + if subprocess.run(["make", "tools"]).returncode != 0: + LOG.error("An error occurred while running 'make tools'") + exit(1) + # text = Text("--- Extracting game assets") text.stylize("bold magenta") @@ -313,10 +323,13 @@ def setup(debug: bool, game_path: Path, tools_path: Path): sys.exit(1) try: + import extract_game_assets previous_dir = os.getcwd() os.chdir(str(game_path.absolute())) extract_game_assets.extract("../" + str(iso)) os.chdir(previous_dir) + except ImportError as ex: + _handle_import_error(ex) except Exception as e: LOG.error(f"failure:") LOG.error(e) @@ -1132,6 +1145,11 @@ class CheckException(Exception): def check_sha1(game_path: Path, build_path: Path, include_rels: bool): + try: + import librel + except ImportError as ex: + _handle_import_error(ex) + EXPECTED = {} EXPECTED[0] = ( "",