Merge pull request #4279 from radv-tinker/pr/make-game-preflight-resume

make_game: count assets already exported when a stopped build resumes
This commit is contained in:
shayder
2026-11-22 18:33:23 -06:00
committed by GitHub
2 changed files with 42 additions and 0 deletions

View File

@ -460,6 +460,25 @@ def icloud_default_notes() -> list:
MIN_FREE_GB = {"shaders": 30, "assets": 300}
def tree_bytes(path: str) -> int:
"""Bytes in the files under path (0 when it is missing); links are not followed."""
total, stack = 0, [path]
while stack:
try:
with os.scandir(stack.pop()) as it:
for e in it:
try:
if e.is_dir(follow_symlinks=False):
stack.append(e.path)
elif e.is_file(follow_symlinks=False):
total += e.stat(follow_symlinks=False).st_size
except OSError:
pass
except OSError:
pass
return total
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
@ -619,6 +638,12 @@ def preflight(stages: list, work: str, wav: bool = False, runtime_build: str | N
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
elif need.get("assets") and not wav:
# A stopped export resumes: what it already wrote is on the disk, so it isn't needed free a second time.
done_gb = int(tree_bytes(os.path.join(work, "assets")) / 2**30)
if done_gb:
log(f"preflight: {done_gb} GB of assets are already exported in {work}; not counting them")
need["assets"] = max(0, need["assets"] - done_gb)
os.makedirs(work, exist_ok=True)
free_gb = shutil.disk_usage(work).free / 2**30
need_gb = sum(need.values())

View File

@ -868,6 +868,23 @@ class PreflightExportedAssetsSpaceTest(PreflightTestBase):
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_counts_what_it_already_wrote(self):
# Before: a stopped export that had written 277 GB still asked for all 300 GB free, so it couldn't resume.
with tempfile.TemporaryDirectory() as work:
with mock.patch("make_game.tree_bytes", return_value=277 * 2**30):
self.run_preflight(work, free_gb=60) # 30 for the shaders + 300 - 277
self.assert_fails(self.run_preflight, work, free_gb=40, match="about 53 GB is needed")
def test_tree_bytes_sums_files_under_the_folder(self):
with tempfile.TemporaryDirectory() as work:
sub = os.path.join(work, "a", "b")
os.makedirs(sub)
for p, n in ((os.path.join(work, "x"), 3), (os.path.join(sub, "y"), 5)):
with open(p, "wb") as f:
f.write(b"\0" * n)
self.assertEqual(make_game.tree_bytes(work), 8)
self.assertEqual(make_game.tree_bytes(os.path.join(work, "missing")), 0)
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: