diff options
| author | Yanis002 <35189056+Yanis002@users.noreply.github.com> | 2025-02-05 18:01:04 +0100 |
|---|---|---|
| committer | Yanis002 <35189056+Yanis002@users.noreply.github.com> | 2025-02-05 18:01:04 +0100 |
| commit | 705596daff8989db4d7bfd7a980609951c7a6c20 (patch) | |
| tree | a714f7d9ac0873c60447a8b3da73a686d35a5896 /tools | |
| parent | 8fa0cb0095e397212679eb8ddaa347a658619b0c (diff) | |
| parent | 3f7197110627adbbe7ff1f69db1f5a15f9b6c598 (diff) | |
Merge remote-tracking branch 'upstream/main' into transform_dep
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/configure.py | 18 | ||||
| -rwxr-xr-x | tools/m2ctx.py | 7 | ||||
| -rw-r--r-- | tools/mangle.py | 30 | ||||
| -rw-r--r-- | tools/setup.py | 2 | ||||
| -rw-r--r-- | tools/sha1.py | 29 |
5 files changed, 71 insertions, 15 deletions
diff --git a/tools/configure.py b/tools/configure.py index 77e3ba53..26f7e86e 100644 --- a/tools/configure.py +++ b/tools/configure.py @@ -27,7 +27,7 @@ CC_FLAGS = " ".join([ "-proc arm946e", # Target processor "-gccext,on", # Enable GCC extensions "-fp soft", # Compute float operations in software - "-inline on,noauto", # Inline only functions marked with 'inline' + "-inline noauto", # Inline only functions marked with 'inline' "-lang=c++", # Set language to C++ "-Cpp_exceptions off", # Disable C++ exceptions "-RTTI off", # Disable runtime type information @@ -179,6 +179,12 @@ def main(): ) n.newline() + n.rule( + name="sha1", + command=f"{PYTHON} tools/sha1.py $in -c $sha1_file" + ) + n.newline() + game_build = build_path / game_version game_extract = extract_path / game_version @@ -249,6 +255,16 @@ def add_mwld_and_rom_builds(n: ninja_syntax.Writer, game_build: Path, game_confi ) n.newline() + n.build( + inputs=rom_file, + rule="sha1", + variables={ + "sha1_file": str(Path(rom_file).with_suffix(".sha1")) + }, + outputs="sha1", + ) + n.newline() + def add_mwcc_builds(n: ninja_syntax.Writer, game_version: str, game_build: Path, mwcc_implicit: list[Path]): for source_file in get_c_cpp_files([src_path, libs_path]): diff --git a/tools/m2ctx.py b/tools/m2ctx.py index dc43f326..f2275e33 100755 --- a/tools/m2ctx.py +++ b/tools/m2ctx.py @@ -21,7 +21,8 @@ CXX_FLAGS = [ '-nostdinc', '-Iinclude', '-Ilibs/c/include', - '-Ilibs/cpp/include' + '-Ilibs/cpp/include', + '-Ilibs/nds/include' ] script_dir = Path(os.path.dirname(os.path.realpath(__file__))) @@ -37,8 +38,8 @@ COMMENT_REGEX = r'\/\/.*$|\/\*(?:.|\r|\n)+?\*\/' with open(args.file, 'r') as f: contents = f.read() -contents = re.sub(COMMENT_REGEX, '', contents, 0, re.MULTILINE) -includes = re.findall(INCLUDE_REGEX, contents, re.MULTILINE) +contents = re.sub(COMMENT_REGEX, '', contents, count=0, flags=re.MULTILINE) +includes = re.findall(INCLUDE_REGEX, contents, flags=re.MULTILINE) _, suffix = os.path.splitext(args.file) diff --git a/tools/mangle.py b/tools/mangle.py index 68d2aeb3..0d173788 100644 --- a/tools/mangle.py +++ b/tools/mangle.py @@ -15,6 +15,7 @@ include_dir = root_dir / 'include' libs_dir = root_dir / 'libs' libc_include_dir = libs_dir / 'c' / 'include' libcpp_include_dir = libs_dir / 'cpp' / 'include' +libnds_include_dir = libs_dir / 'nds' / 'include' if platform.system() == 'Windows': cc = [str(cc_path)] else: cc = ['wine', str(cc_path)] @@ -27,7 +28,7 @@ cc.extend([ '-proc', 'arm946e', '-gccext,on', '-fp', 'soft', - '-inline', 'on,noauto', + '-inline', 'noauto', '-Cpp_exceptions', 'off', '-RTTI', 'off', '-interworking', @@ -38,6 +39,7 @@ cc.extend([ '-i', include_dir, '-i', libc_include_dir, '-i', libcpp_include_dir, + '-i', libnds_include_dir, args.file ]) @@ -52,19 +54,27 @@ output = output.decode() # print(output) mangled_funcs: list[str] = re.findall(r'.text +([^\$ ]\S+)', output) -mangled_data: list[str] = re.findall(r'(?:.data|.bss) +([^\. ]\S+)', output) +init_funcs: list[str] = re.findall(r'.init +([^\$ ]\S+)', output) +mangled_data: list[str] = re.findall(r'.data +([^\. ]\S+)', output) +mangled_bss: list[str] = re.findall(r'.bss +([^\. ]\S+)', output) if len(mangled_funcs) > 0: - print('Functions:') - print() + print('.text:\n') for func in mangled_funcs: print(func) - print() - print() + print('\n') +if len(init_funcs) > 0: + print('.init:\n') + for func in init_funcs: + print(func) + print('\n') if len(mangled_data) > 0: - print('Data:') - print() + print('.data:\n') for data in mangled_data: print(data) - print() - print() + print('\n') +if len(mangled_bss) > 0: + print('.bss:\n') + for bss in mangled_bss: + print(bss) + print('\n') diff --git a/tools/setup.py b/tools/setup.py index 87f64099..bc322e1d 100644 --- a/tools/setup.py +++ b/tools/setup.py @@ -4,7 +4,7 @@ import io from pathlib import Path import platform -DSD_VERSION = 'v0.2.3' +DSD_VERSION = 'v0.4.0' tools_path = Path(__file__).parent diff --git a/tools/sha1.py b/tools/sha1.py new file mode 100644 index 00000000..8cd6edd8 --- /dev/null +++ b/tools/sha1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from pathlib import Path +import argparse +import hashlib +import sys + +def eprint(*args, **kwargs): + print(*args, file=sys.stderr, **kwargs) + +parser = argparse.ArgumentParser(description="Computes and verifies a SHA1 checksum") +parser.add_argument('file', help="Input file to verify") +parser.add_argument('-c', type=str, dest='checksum_file', required=False, help='Checksum file') +args = parser.parse_args() + +file_path = Path(args.file) +checksum_path = Path(args.checksum_file) + +with checksum_path.open('r') as file: + target_sha1, _ = file.readline().split(' ', 1) + +with file_path.open('rb') as file: + file_sha1 = hashlib.sha1(file.read()).hexdigest() + +if target_sha1 != file_sha1: + eprint(f"{file_path}: FAILED") + exit(1) +else: + eprint(f"{file_path}: OK") |
