Merge task/cheatsrebuild: on the Linux AppImage "Rebuild the game now" starts the setup AppImage itself, so code cheats get built in, and a rebuild that does not start is tried again (#560, #403)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-14 15:13:04 +03:00
commit 97d12240f4
4 files changed
+33 -4

No files matched your search

+6 -2
View File
@@ -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 <install folder>`), 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
+8 -1
View File
@@ -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')
+4 -1
View File
@@ -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
+15
View File
@@ -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()