make_game.py: preflight doesn't count the assets stage's 300 GB when its exports are already finished

A rerun with the default stages (for example after a translator update) refused to start on a drive that
had already held a full build: preflight asked for 30 + 300 GB free although the asset exports were
complete and their space was already in use. The assets stage then skips every finished step anyway.

preflight now leaves the assets stage out of the sum when both of its audio markers (ogg.done, then
xma.done, the last one assets() writes) hold what mark() wrote. A fresh work folder, a stopped export or a
marker with other contents still needs the full 330 GB. --wav still counts it, because the WAV decode
writes several times the Ogg Opus size and has no marker of its own.

Tested: tests/test_make_game_preflight.py 49/49 (7 new), all test_make_game*.py 165/165, compileall
clean. The new tests fail on main without the change. Checked against a real finished work folder: the
assets markers are read as finished and preflight passes for shaders + assets with 223 GB free. CPU only,
no game files. AI-assisted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thatters
2026-11-21 23:51:09 -05:00
parent d1211d0206
commit 7cf659a7d6
2 changed files with 91 additions and 1 deletions

View File

@ -238,6 +238,21 @@ def default_out() -> str:
MIN_FREE_GB = {"shaders": 30, "assets": 300}
def assets_exported(work: str) -> bool:
"""Whether an earlier run finished the assets stage's exports, so its space is already in use. xma.done is the
last marker assets() writes, after every model, texture and audio export before it succeeded; ogg.done is read
too. A marker counts only when it holds what mark() writes, not because a file of that name exists."""
audio = os.path.join(work, "assets", "audio")
for name, what in (("ogg.done", "awc_opus.py"), ("xma.done", "rpf9dump xma")):
try:
with open(os.path.join(audio, name), encoding="utf-8") as f:
if f.read().strip() != f"{what} finished":
return False
except (OSError, UnicodeError):
return False
return True
def pipeline_check_prerequisite(runtime_selected: bool = False) -> str:
"""Why the pipelines stage can't run yet. Kept here so preflight can fail before a long shader build;
pipelines() prints its own, more detailed message when the stage is reached. On Windows the runtime stage
@ -292,7 +307,13 @@ def preflight(stages: list, work: str, wav: bool = False, runtime_build: str | N
missing.append(pipeline_check_prerequisite(runtime_building))
if missing:
fail("Install these first, then run the build again:\n - " + "\n - ".join(dict.fromkeys(missing)))
need_gb = sum(MIN_FREE_GB.get(s, 0) for s in stages)
need = {s: MIN_FREE_GB.get(s, 0) for s in stages}
# A rerun that only refreshes the shaders shouldn't need room for a second copy of exports already on disk.
# --wav still counts it: the WAV decode writes several times the Ogg Opus size and has no marker.
if need.get("assets") and not wav and assets_exported(work):
log(f"preflight: the assets are already exported in {work}; not counting their {need['assets']} GB")
need["assets"] = 0
need_gb = sum(need.values())
os.makedirs(work, exist_ok=True)
free_gb = shutil.disk_usage(work).free / 2**30
if free_gb < need_gb:

View File

@ -549,5 +549,74 @@ class PathAndGameSelectionTest(PreflightTestBase):
make_game.below_normal()
class PreflightExportedAssetsSpaceTest(PreflightTestBase):
"""A rerun over finished asset exports doesn't need room for a second copy of them."""
OGG = "awc_opus.py finished\n"
XMA = "rpf9dump xma finished\n"
def run_preflight(self, work, free_gb, wav=False):
usage = Usage(1000 * 2**30, (1000 - free_gb) * 2**30, free_gb * 2**30)
with mock.patch("sys.version_info", (3, 12, 0)), \
mock.patch("shutil.which", return_value="/usr/bin/tool"), \
mock.patch("make_game.tool_available", return_value=True), \
mock.patch("make_game.ensure_submodule", return_value=None), \
mock.patch("sys.stdout", io.StringIO()), \
mock.patch("shutil.disk_usage", return_value=usage):
make_game.preflight(["shaders", "assets"], work, wav=wav)
def write_markers(self, work, ogg=OGG, xma=XMA):
audio = os.path.join(work, "assets", "audio")
os.makedirs(audio, exist_ok=True)
for name, text in (("ogg.done", ogg), ("xma.done", xma)):
if text is not None:
with open(os.path.join(audio, name), "w", encoding="utf-8") as f:
f.write(text)
def test_markers_written_by_assets_are_read_back(self):
with tempfile.TemporaryDirectory() as work:
audio = os.path.join(work, "assets", "audio")
os.makedirs(audio)
make_game.mark(os.path.join(audio, "ogg.done"), "awc_opus.py")
make_game.mark(os.path.join(audio, "xma.done"), "rpf9dump xma")
self.assertTrue(make_game.assets_exported(work))
def test_exported_assets_need_only_the_shader_space(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work)
self.run_preflight(work, free_gb=220) # 30 GB for the shaders, not 330
err = self.assert_fails(self.run_preflight, work, free_gb=20, match="about 30 GB is needed")
self.assertIn("20 GB free", err)
def test_fresh_work_folder_still_needs_the_asset_space(self):
with tempfile.TemporaryDirectory() as work:
self.assertFalse(make_game.assets_exported(work))
self.assert_fails(self.run_preflight, work, free_gb=220, match="about 330 GB is needed")
def test_stopped_export_still_needs_the_asset_space(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None) # stopped before the XMA2 step
self.assertFalse(make_game.assets_exported(work))
self.assert_fails(self.run_preflight, work, free_gb=220, match="about 330 GB is needed")
def test_marker_with_other_contents_does_not_count(self):
for ogg, xma in (("", self.XMA), (self.OGG, "something else\n"), (self.XMA, self.OGG)):
with self.subTest(ogg=ogg, xma=xma), tempfile.TemporaryDirectory() as work:
self.write_markers(work, ogg=ogg, xma=xma)
self.assertFalse(make_game.assets_exported(work))
def test_marker_that_is_a_folder_does_not_count(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None)
os.makedirs(os.path.join(work, "assets", "audio", "xma.done"))
self.assertFalse(make_game.assets_exported(work))
def test_wav_still_counts_the_asset_space(self):
# The WAV decode writes several times the Ogg Opus size and has no marker of its own.
with tempfile.TemporaryDirectory() as work:
self.write_markers(work)
self.assert_fails(self.run_preflight, work, free_gb=220, wav=True, match="about 330 GB is needed")
if __name__ == "__main__":
unittest.main()