From 35c590bacdd3ce52adc5e2e2d5a422241fdb2fa2 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Sat, 14 Nov 2026 15:12:35 +0300 Subject: [PATCH] Start the Linux rebuild through the AppImage file, not its vanished mount The setup wrote the path of its Python inside the AppImage mount into build-cache/rebuild.txt. The mount is gone once the setup exits, so the game could not start the rebuild for code cheats and ExeFS patches, kept its old code, and rebuild.skip then stopped every later attempt. The command now starts $APPIMAGE --rebuild , and a rebuild that does not start leaves no rebuild.skip (#560, #403) Co-Authored-By: Claude Opus 5.5 --- docs/installer.md | 8 ++++++-- installer/steps.py | 9 ++++++++- runtime/cheats.c | 5 ++++- tests/installer_test.py | 15 +++++++++++++++ 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/docs/installer.md b/docs/installer.md index 09fadff4..347e9434 100644 --- a/docs/installer.md +++ b/docs/installer.md @@ -120,8 +120,12 @@ whatever the working folder), one argument per line. When an enabled mod has cod lacks, `totk.exe` runs it at start and exits (`runtime/cheats.c` `rebuild_if_needed`); the window runs the setup on the folder at once and starts the game again when it succeeds. A failed or cancelled rebuild offers to start the game with the code it has; `build-cache/rebuild.skip` then keeps the same files from starting it -again, until "Rebuild the game now" on the Cheats or Mods tab. `[mods] mods_rebuild = off` turns it off. The rebuild -needs the release folder the setup ran from: a moved or deleted release folder means running a setup again. +again, until "Rebuild the game now" on the Cheats or Mods tab. A command that does not start at all leaves no +`rebuild.skip`, so the next start tries it again. `[mods] mods_rebuild = off` turns it off. The rebuild needs the +release folder the setup ran from: a moved or deleted release folder means running a setup again. On Linux the command +starts the AppImage file itself (`$APPIMAGE --rebuild `), because the AppImage's mounted folder is gone +once the setup exits; a moved or deleted AppImage means running a setup again. Installs set up by an AppImage before +this change hold a command into that mount: running the new setup once on the install folder writes the new one. ## Command line diff --git a/installer/steps.py b/installer/steps.py index 3888dfee..3c3c1e25 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -1374,8 +1374,15 @@ REBUILD_BOOT = ('import runpy, sys; sys.path.insert(0, sys.argv.pop(1)); ' def rebuild_command(ctx): """The command that starts the setup window in its rebuild mode on this install folder (installer/gui.py --rebuild): pythonw beside the setup's Python on Windows, so no console opens. In a repository that is the Python - running this setup: the tools' embeddable Python there has no tkinter.""" + running this setup: the tools' embeddable Python there has no tkinter. + In the Linux AppImage the release folder is the AppImage's mount (/tmp/.mount_*), which goes away when the setup + exits, so a path into it would fail to start later and the game would keep its old code. The command starts the + AppImage file itself instead ($APPIMAGE, set by the AppImage runtime); its AppRun passes the arguments to + installer.gui.""" layout = ctx.layout + appimage = os.environ.get('APPIMAGE', '') + if not layout.dev and appimage and Path(appimage).is_file(): + return [str(Path(appimage).resolve()), '--rebuild', str(ctx.dest)] python = Path(sys.executable) if layout.dev else layout.python if os.name == 'nt' and python.with_name('pythonw.exe').is_file(): python = python.with_name('pythonw.exe') diff --git a/runtime/cheats.c b/runtime/cheats.c index 07862a18..11991dc3 100644 --- a/runtime/cheats.c +++ b/runtime/cheats.c @@ -575,7 +575,10 @@ static void rebuild_if_needed(const char *dir) { int ok = plat_spawn(argv, dir); free(cmd); if (!ok) { - rt_log("cheats: the rebuild did not start; the game starts with the code it has"); + // The skip key is for a rebuild that ran and failed or was cancelled. One that never started (a command whose + // program is gone) leaves no key, so the next start and "Rebuild the game now" try it again. + plat_fs_unlink(skip_path); + rt_log("cheats: the rebuild did not start (%s); the game starts with the code it has", cmd_path); return; } prof_write(); // plat_exit runs no atexit handlers diff --git a/tests/installer_test.py b/tests/installer_test.py index d8d7d378..d1615661 100644 --- a/tests/installer_test.py +++ b/tests/installer_test.py @@ -526,6 +526,21 @@ class CleanupTest(unittest.TestCase): self.assertEqual(lines[1:], ['-c', steps.REBUILD_BOOT, str(self.ctx.layout.root), '--root', str(self.ctx.layout.root), '--rebuild', str(self.dest)]) + def test_appimage_rebuild_command_starts_the_appimage(self): + # The AppImage's mount, where its Python lives, is gone once the setup exits (#560, #403) + appimage = Path(self.tmp.name) / 'TotK-Setup-x86_64.AppImage' + appimage.write_bytes(b'') + with mock.patch.dict('os.environ', {'APPIMAGE': str(appimage)}): + self.assertEqual(self.run_cleanup(), 'ok') + lines = (self.dest / 'build-cache' / 'rebuild.txt').read_text(encoding='utf-8').splitlines() + self.assertEqual(lines, [str(appimage.resolve()), '--rebuild', str(self.dest)]) + + def test_appimage_variable_without_the_file_keeps_the_python_command(self): + with mock.patch.dict('os.environ', {'APPIMAGE': str(Path(self.tmp.name) / 'gone.AppImage')}): + self.assertEqual(self.run_cleanup(), 'ok') + lines = (self.dest / 'build-cache' / 'rebuild.txt').read_text(encoding='utf-8').splitlines() + self.assertEqual(lines[1:3], ['-c', steps.REBUILD_BOOT]) + def test_emptied_romfs_fails(self): for p in (self.dest / 'romfs').iterdir(): p.unlink()