mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 15:18:38 +00:00
- Without --stages, runtime (Windows only for now) is left out off Windows. Before, the default build ran shaders and assets (hours) and then failed in runtime, so pipelines never ran. - Asked for explicitly off Windows, preflight() refuses it before any work. - pipelines finds vk_pipeline_check where CMake builds it off Windows (runtime/build/linux as in the README, or runtime/build as in CONTRIBUTING.md) instead of only vk_pipeline_check.exe, and says how to build it when it is missing. Windows is unchanged. - tests/test_make_game_platform.py (9 tests, 6 fail before this change); test_make_game_preflight.py's all-tools test asks for runtime only on Windows, since it is now refused elsewhere. AI-assisted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
132 lines
5.4 KiB
Python
132 lines
5.4 KiB
Python
"""make_game.py off Windows: the Windows-only runtime stage is left out of the default stages and refused before
|
|
any work when asked for, and the pipelines stage finds the vk_pipeline_check that CMake builds there.
|
|
|
|
python -I tests/test_make_game_platform.py
|
|
|
|
No game data: main() runs with every stage mocked; the vk_pipeline_check binaries are empty files.
|
|
"""
|
|
import io
|
|
import os
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
if ROOT not in sys.path:
|
|
sys.path.insert(0, ROOT)
|
|
|
|
import make_game # noqa: E402
|
|
|
|
STAGE_FUNCS = ("shaders", "assets", "runtime", "pipelines")
|
|
|
|
|
|
class DefaultStagesTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.game = os.path.join(self.tmp.name, "game")
|
|
os.makedirs(self.game)
|
|
|
|
def tearDown(self):
|
|
self.tmp.cleanup()
|
|
|
|
def run_main(self, os_name, *args):
|
|
argv = ["make_game.py", "--game", self.game, "--out", os.path.join(self.tmp.name, "out"), *args]
|
|
mocks = {n: mock.MagicMock() for n in STAGE_FUNCS}
|
|
with mock.patch.object(sys, "argv", argv), \
|
|
mock.patch.object(make_game.os, "name", os_name), \
|
|
mock.patch.object(make_game, "below_normal"), \
|
|
mock.patch.object(make_game, "check", return_value={"expected_exe": "game.exe"}), \
|
|
mock.patch.object(make_game, "preflight") as preflight, \
|
|
mock.patch.object(make_game, "log"), \
|
|
mock.patch.multiple(make_game, **mocks):
|
|
self.assertEqual(make_game.main(), 0)
|
|
return preflight.call_args.args[0], {n: m.called for n, m in mocks.items()}
|
|
|
|
def test_default_stages_leave_runtime_out_off_windows(self):
|
|
stages, ran = self.run_main("posix")
|
|
self.assertEqual(stages, ["check", "shaders", "assets", "pipelines"])
|
|
self.assertEqual(ran, {"shaders": True, "assets": True, "runtime": False, "pipelines": True})
|
|
|
|
def test_default_stages_keep_runtime_on_windows(self):
|
|
stages, ran = self.run_main("nt")
|
|
self.assertEqual(stages, make_game.STAGES)
|
|
self.assertTrue(ran["runtime"])
|
|
|
|
def test_explicit_stages_are_kept_as_given(self):
|
|
stages, _ = self.run_main("posix", "--stages", "shaders,runtime")
|
|
self.assertEqual(stages, ["shaders", "runtime"])
|
|
|
|
|
|
class PreflightTest(unittest.TestCase):
|
|
def test_runtime_asked_for_off_windows_fails_before_any_work(self):
|
|
err = io.StringIO()
|
|
with tempfile.TemporaryDirectory() as work, \
|
|
mock.patch.object(make_game.os, "name", "posix"), \
|
|
mock.patch("sys.stderr", err), \
|
|
mock.patch.object(make_game.shutil, "disk_usage") as usage:
|
|
with self.assertRaises(SystemExit) as ctx:
|
|
make_game.preflight(["shaders", "runtime"], os.path.join(work, "w"))
|
|
self.assertEqual(ctx.exception.code, 1)
|
|
self.assertIn("runtime stage builds on Windows only", err.getvalue())
|
|
usage.assert_not_called()
|
|
self.assertFalse(os.path.exists(os.path.join(work, "w")))
|
|
|
|
|
|
class PipelineCheckExeTest(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.build = os.path.join(self.tmp.name, "runtime", "build")
|
|
os.makedirs(os.path.join(self.build, "linux"))
|
|
self.root = mock.patch.object(make_game, "ROOT", self.tmp.name)
|
|
self.root.start()
|
|
|
|
def tearDown(self):
|
|
self.root.stop()
|
|
self.tmp.cleanup()
|
|
|
|
def touch(self, *parts):
|
|
p = os.path.join(self.build, *parts)
|
|
open(p, "w").close()
|
|
return p
|
|
|
|
def exe(self, os_name):
|
|
with mock.patch.object(make_game.os, "name", os_name):
|
|
return make_game.pipeline_check_exe()
|
|
|
|
def test_linux_prefers_the_readme_build_folder(self):
|
|
self.assertIsNone(self.exe("posix"))
|
|
plain = self.touch("vk_pipeline_check")
|
|
self.assertEqual(self.exe("posix"), plain)
|
|
readme = self.touch("linux", "vk_pipeline_check")
|
|
self.assertEqual(self.exe("posix"), readme)
|
|
|
|
def test_windows_finds_only_the_exe(self):
|
|
self.touch("linux", "vk_pipeline_check")
|
|
self.assertIsNone(self.exe("nt"))
|
|
exe = self.touch("vk_pipeline_check.exe")
|
|
self.assertEqual(self.exe("nt"), exe)
|
|
|
|
def test_pipelines_off_windows_runs_the_linux_build(self):
|
|
exe = self.touch("linux", "vk_pipeline_check")
|
|
work = os.path.join(self.tmp.name, "work")
|
|
os.makedirs(os.path.join(work, "shaders", "spirv"))
|
|
open(os.path.join(work, "shaders", "spirv", "index.json"), "w").close()
|
|
out = os.path.join(self.tmp.name, "out")
|
|
with mock.patch.object(make_game.os, "name", "posix"), \
|
|
mock.patch.object(make_game, "log"), \
|
|
mock.patch.object(make_game, "run") as run:
|
|
make_game.pipelines(work, out)
|
|
self.assertEqual(run.call_args.args[0][0], exe)
|
|
|
|
def test_pipelines_off_windows_without_the_build_says_how_to_build_it(self):
|
|
err = io.StringIO()
|
|
with mock.patch.object(make_game.os, "name", "posix"), mock.patch("sys.stderr", err):
|
|
with self.assertRaises(SystemExit):
|
|
make_game.pipelines(os.path.join(self.tmp.name, "work"), os.path.join(self.tmp.name, "out"))
|
|
self.assertIn("cmake -S runtime -B runtime/build/linux", err.getvalue())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|