From c05b083130e27b6ac5644f2f76b4e81fcbafa745 Mon Sep 17 00:00:00 2001 From: Wellington Dias Date: Sat, 31 Oct 2026 16:23:28 -0300 Subject: [PATCH] Read the extracted game from the work folder in build_game.py and stop when the RomFS is missing --- docs/building.md | 3 ++- tools/build_game.py | 34 +++++++++++++++++++++++++++------- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/docs/building.md b/docs/building.md index f457b81a..67d3086e 100644 --- a/docs/building.md +++ b/docs/building.md @@ -69,7 +69,8 @@ of them. keys file. `config.local.toml` is ignored by git. The tools read the keys file themselves. 3. Extract and verify. This writes `build\extracted\v0` (1.0.0) and `build\extracted\` for each update in - `updates`, identified by its hash; a hash mismatch stops the run: + `updates`, identified by its hash; a hash mismatch stops the run. With another `[work] dir` in `config.local.toml`, + `extracted` goes there instead, and `build_game.py` reads the ExeFS and RomFS from there: ```powershell .venv-py314\Scripts\python tools\extract.py diff --git a/tools/build_game.py b/tools/build_game.py index 65a2062f..99df700a 100644 --- a/tools/build_game.py +++ b/tools/build_game.py @@ -17,9 +17,11 @@ first (rpath $ORIGIN). docs/building.md lists the packages. Every runtime/*.c is compiled. build//modules.c carries the layout, the linked function tables, the expected SHA-256 of each ExeFS file (tools/data/expected-.json) and the default game paths -(--exefs, --romfs, --profile), which totk.exe uses unless its own command line names others. tools/romfs_index.py -writes build//romfs-index.bin and romfs_config.h from the RomFS directory's index.json (runtime/romfs.c reads -the index next to totk.exe). +(--exefs, --romfs, --profile), which totk.exe uses unless its own command line names others. --exefs and --romfs +default to extracted/ in the work folder: the [work] dir of config.local.toml, where tools/extract.py writes +them, else build/. tools/romfs_index.py writes build//romfs-index.bin and romfs_config.h from the RomFS +directory's index.json (runtime/romfs.c reads the index next to totk.exe). Without that index.json the build stops: +the exe would stop at start. --no-romfs builds it anyway. Private builds reuse the main build's objects. When --out differs from build/, the main build's generated objects are up to date (checked with a dry run of its build.ninja) and every header they include from runtime/ is @@ -241,6 +243,16 @@ def copy_romfs_patches(version, out): print(f'romfs patches: copied {name} from {src}') +def work_dir(): + """The work folder: the [work] dir of config.local.toml (relative to the checkout), where tools/extract.py writes + extracted/; build/ without the file or the key.""" + cfg = ROOT / 'config.local.toml' + if not cfg.is_file(): + return ROOT / 'build' + import tomllib + return ROOT / tomllib.loads(cfg.read_text(encoding='utf-8')).get('work', {}).get('dir', 'build') + + def c_string(s): return '"' + s.replace('\\', '\\\\').replace('"', '\\"') + '"' @@ -710,9 +722,12 @@ def main(): help='comma-separated runtime/*.c names to leave out (the link needs another definition of what they ' 'define)') ap.add_argument('--exefs', type=Path, - help="totk.exe's default ExeFS directory (default build/extracted//exefs)") + help="totk.exe's default ExeFS directory (default /extracted//exefs, the work " + "dir being the [work] dir of config.local.toml, else build)") ap.add_argument('--romfs', type=Path, help="totk.exe's default RomFS directory with romfs.bin and index.json " - '(default build/extracted//romfs)') + '(default /extracted//romfs)') + ap.add_argument('--no-romfs', action='store_true', + help='build even when the RomFS directory has no index.json (the exe then stops at start)') ap.add_argument('--profile', type=Path, help="totk.exe's default profile directory (default build/profile for v121, " "build/profile- otherwise, so trying another version leaves " "the main profile alone; saves load on 1.2.1 and 1.4.3 alike)") @@ -735,11 +750,16 @@ def main(): gen = (args.gen or ROOT / 'generated' / args.version).resolve() out = (args.out or ROOT / 'build' / args.version).resolve() - extracted = ROOT / 'build' / 'extracted' / args.version + extracted = None if args.exefs and args.romfs else work_dir() / 'extracted' / args.version paths = {'exefs': (args.exefs or extracted / 'exefs').resolve(), 'romfs': (args.romfs or extracted / 'romfs').resolve(), 'profile': (args.profile or ROOT / 'build' / ('profile' if args.version == 'v121' else f'profile-{args.version}')).resolve()} + has_romfs = (paths['romfs'] / 'index.json').is_file() + if not (has_romfs or args.no_romfs or args.make_runtime_lib or args.compile_only): + sys.exit(f'{paths["romfs"] / "index.json"} not found: without the RomFS the game stops at start. Run ' + 'tools/extract.py (it writes extracted/ into the [work] dir of config.local.toml), pass ' + '--romfs DIR, or --no-romfs to build without it') expected = args.expected if not expected: if args.version not in DISPLAY_VERSIONS: @@ -795,7 +815,7 @@ def main(): if missing: sys.exit(f'{expected}: no exefs_sha256 for {missing}') write_if_changed(out / 'modules.c', module_glue(layout, linked, hashes, paths, args.version)) - if (paths['romfs'] / 'index.json').is_file(): + if has_romfs: count, size, dt = romfs_index.write(paths['romfs'], out) print(f'romfs index: {count} files, {mib(size)}, {dt:.1f} s') else: