diff --git a/installer/steps.py b/installer/steps.py index 09b36f12..dadcefc4 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -1141,6 +1141,17 @@ def plugins_status(ctx): return ctx.dest / 'build-cache' / 'plugins.status' +def plugins_stale(ctx): + """True when the game listed a plugin whose start differed from the build (build-cache/plugins.stale, runtime/mods.c + mods_plugin_off): the plugin's record comes from the lift's service run and the exe's patch sets from the compile, + so both are out of date, while their keys, made of the files the steps read, are unchanged. Only Lift.run clears + the file.""" + try: + return bool((ctx.dest / 'build-cache' / 'plugins.stale').read_text(encoding='utf-8', errors='replace').strip()) + except OSError: + return False + + def built_plugins(status, files, mods): """The files of the plugins the status file lists as built (kind `plugin`), in the order of files. The key is FNV-1a 32 of "/", as tools/exefs_plugins.py and runtime/mods.c compute it.""" @@ -1194,7 +1205,8 @@ class Lift(Step): def current(self, ctx, record): gen = ctx.temp / 'gen' stamp = gen / STAMP - return (gen / 'layout.json').is_file() and stamp.is_file() and stamp.read_text().strip() == ctx.keys['lift'] + return ((gen / 'layout.json').is_file() and stamp.is_file() and stamp.read_text().strip() == ctx.keys['lift'] + and not plugins_stale(ctx)) def run(self, ctx): # gen/ of the last run stays: gen.py lifts again only the chunks whose inputs changed @@ -1369,6 +1381,8 @@ class Compile(Step): exe = ctx.dest / ('totk' + EXE) if not exe.is_file() or not (ctx.dest / 'romfs-index.bin').is_file(): return False + if plugins_stale(ctx): # the lift runs (Lift.current), and a transient step runs only with the step after it + return False if not all((ctx.dest / d.name).is_file() for d in ctx.layout.dlls): return False return file_sha256(exe) == record.get('exe_sha256') diff --git a/tests/installer_test.py b/tests/installer_test.py index 44201d08..9175100b 100644 --- a/tests/installer_test.py +++ b/tests/installer_test.py @@ -370,6 +370,45 @@ class LiftKeyTest(unittest.TestCase): self.assertEqual(self.key(), before) +class PluginsStaleTest(unittest.TestCase): + """A plugin the game found stale (build-cache/plugins.stale, runtime/mods.c mods_plugin_off) plans the lift and the + compile of the game's rebuild: the plugin's service run is in the lift, and only Lift.run clears the file.""" + + def setUp(self): + tmp = tempfile.TemporaryDirectory() + self.addCleanup(tmp.cleanup) + base = Path(tmp.name) + dest, temp = base / 'install', base / 'temp' + (temp / 'gen').mkdir(parents=True) + (temp / 'gen' / 'layout.json').write_text('[]') + (temp / 'gen' / steps.STAMP).write_text('L\n') + (dest / 'build-cache').mkdir(parents=True) + (dest / ('totk' + steps.EXE)).write_bytes(b'MZ') + (dest / 'romfs-index.bin').write_bytes(b'') + layout = SimpleNamespace(release='1.0', dlls=[]) + records = {'lift': {'key': 'L'}, 'compile': {'key': 'C', 'exe_sha256': steps.file_sha256(dest / ('totk' + steps.EXE))}} + self.ctx = runner.Context(layout, dest, temp, Reporter(out=io.StringIO()), SimpleNamespace(), + state={'release': '1.0', 'steps': records}) + self.addCleanup(self.ctx.reporter.close) + self.ctx.steps = [steps.Lift(), steps.Compile()] + self.ctx.keys = {'lift': 'L', 'compile': 'C'} + self.stale = dest / 'build-cache' / 'plugins.stale' + + def planned(self): + self.ctx.plan() + return [s.id for s in self.ctx.steps if self.ctx.will_run(s.id)] + + def test_stale_plugin_runs_the_lift_and_the_compile(self): + self.assertEqual(self.planned(), []) + self.stale.write_text('A89F6A7C\t74492AD5\tits init wrote 1 words the build did not record ' + '(first main+0x3ad6eb8 87a00000 -> 823c0000)\n') + self.assertEqual(self.planned(), ['lift', 'compile']) + + def test_empty_stale_file_keeps_the_build(self): + self.stale.write_text('') + self.assertEqual(self.planned(), []) + + class LiftRunTest(unittest.TestCase): """Lift.run with fake tools: the ExeFS patch stage writes the status and data files, the lift lists the bytes it read, and the data writes are checked against that list after it; a failed lift or check drops both files."""