Files
Thomas MartinandClaude Opus 5.5 438dc0a90d Code overlays recompiled: 1368 CodeWarrior modules as overlay modules; all 13 IOP modules native
- tools/find_overlays.py: the 1383 'MWo3' overlays in CDDATA.000 (load slots 0x940000, 0x963000, ...).
- scripts/overlays.sh: per module VP2S_Recomp's wrap_elf.py (ELF at the load address), tools/overlay_functions.py
  (function map without Ghidra) and ps2_recomp in module mode (64-byte guard: the module header with its name),
  JOBS at a time, into generated/overlays/ (headers also in one include folder); CMake object library jc2_overlays.
  1368 build; 15 SC_* modules with a constructor table are left for later.
- tools/overlay_main_targets.py: 99 main-ELF functions reached only through pointers or from the overlays (Ghidra
  missed them; boot 46 stopped at 0x194FB0), added to entry_points.
- scripts/iop_recomp.sh: all 13 IRX (none leaves code to the interpreter).
- tools/sync_tree.py --keep iop,overlays: scripts/recomp.sh no longer deletes them (boot 47 lost both).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-29 06:36:07 +01:00

100 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""Mirror a directory tree, writing only the files whose content changed.
python3 -I tools/sync_tree.py <source> <destination> [<manifest>]
Unchanged files keep their mtime, so ninja rebuilds only the sources that really changed; files missing from the
source are deleted. Replaces `rsync -rc --delete`, which takes minutes for the ~49,000 generated files on Windows
(MSYS2 rsync costs several ms per file). With a manifest (the content hashes written by the previous sync), the
destination is not read back at all: only the freshly written source is hashed. Prints the number of files written or
deleted.
"""
import hashlib
import os
import shutil
import sys
def walk_files(root):
"""Relative paths (with forward slashes) of all files under root."""
files = set()
stack = [""]
while stack:
relative = stack.pop()
with os.scandir(os.path.join(root, relative)) as entries:
for entry in entries:
path = f"{relative}/{entry.name}" if relative else entry.name
if entry.is_dir(follow_symlinks=False):
stack.append(path)
else:
files.add(path)
return files
def digest(path):
with open(path, "rb") as file:
return hashlib.blake2b(file.read(), digest_size=16).hexdigest()
def load_manifest(path):
manifest = {}
if path and os.path.exists(path):
with open(path, encoding="utf-8") as file:
for line in file:
name, _, value = line.rstrip("\n").rpartition("\t")
manifest[name] = value
return manifest
def main():
# --keep a,b: subdirectories of the destination that other scripts write (generated/iop, generated/overlays):
# never deleted. Boot 47 ran without its native IOP modules and its overlay module after a recomp removed them.
args = sys.argv[1:]
keep = ()
if '--keep' in args:
i = args.index('--keep')
keep = tuple(k.strip('/') + '/' for k in args[i + 1].split(','))
del args[i:i + 2]
if len(args) not in (2, 3):
sys.exit(__doc__)
source, destination = args[0], args[1]
manifest_path = args[2] if len(args) == 3 else None
previous = load_manifest(manifest_path)
os.makedirs(destination, exist_ok=True)
changed = 0
current = {}
wanted = walk_files(source)
for relative in wanted:
origin = os.path.join(source, relative)
target = os.path.join(destination, relative)
current[relative] = digest(origin)
if relative in previous and os.path.exists(target):
unchanged = previous[relative] == current[relative]
else:
unchanged = os.path.exists(target) and digest(target) == current[relative]
if not unchanged:
os.makedirs(os.path.dirname(target), exist_ok=True)
shutil.copyfile(origin, target)
changed += 1
for relative in walk_files(destination) - wanted:
if relative.startswith(keep):
continue
os.remove(os.path.join(destination, relative))
changed += 1
for directory, _, _ in sorted(os.walk(destination), key=lambda item: -len(item[0])):
if directory != destination and not os.listdir(directory):
os.rmdir(directory)
if manifest_path:
with open(manifest_path + ".tmp", "w", encoding="utf-8") as file:
file.writelines(f"{name}\t{current[name]}\n" for name in sorted(current))
os.replace(manifest_path + ".tmp", manifest_path)
print(changed)
if __name__ == "__main__":
main()