diff options
| author | Yash Dubey <yash.dubey803at@gmail.com> | 2026-11-24 07:35:50 +0530 |
|---|---|---|
| committer | Yash Dubey <yash.dubey803at@gmail.com> | 2026-11-24 07:35:50 +0530 |
| commit | dfd239266fd62e1fbbfcf264e9bb4e5c8e8dc801 (patch) | |
| tree | 0fb3fbb22dda6a8b3af3b30b0fc3bcc1a23480f6 /tools | |
| parent | 9ec34cdff41b19d7671bc260e5f40dc69790d905 (diff) | |
make_game, first_light: a vk_pipeline_check or vk_harness older than its sources is rebuilt or reported, not reused silently
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/first_light.py | 24 | ||||
| -rw-r--r-- | tools/stale_build.py | 50 |
2 files changed, 72 insertions, 2 deletions
diff --git a/tools/first_light.py b/tools/first_light.py index 7ce4c8a7d..75d14d7af 100644 --- a/tools/first_light.py +++ b/tools/first_light.py | |||
| @@ -50,6 +50,8 @@ TOOLS = os.path.dirname(os.path.abspath(__file__)) | |||
| 50 | ROOT = os.path.dirname(TOOLS) | 50 | ROOT = os.path.dirname(TOOLS) |
| 51 | sys.path.insert(0, os.path.join(ROOT, "runtime", "test", "shaders")) | 51 | sys.path.insert(0, os.path.join(ROOT, "runtime", "test", "shaders")) |
| 52 | from compute_fixture import find_test_program # noqa: E402 | 52 | from compute_fixture import find_test_program # noqa: E402 |
| 53 | sys.path.insert(0, TOOLS) # python -I leaves the script's own folder off sys.path | ||
| 54 | from stale_build import newer_sources # noqa: E402 | ||
| 53 | 55 | ||
| 54 | DEFAULT_VS = "VS_main_170e32e6_Wrapped" | 56 | DEFAULT_VS = "VS_main_170e32e6_Wrapped" |
| 55 | DEFAULT_PS = "$PS_Rage_Untextured_14f8529b_Wrapped" | 57 | DEFAULT_PS = "$PS_Rage_Untextured_14f8529b_Wrapped" |
| @@ -584,6 +586,24 @@ def uv_probes(vertices, indices, width: int, height: int, limit: int = 4) -> lis | |||
| 584 | return found | 586 | return found |
| 585 | 587 | ||
| 586 | 588 | ||
| 589 | def warn_if_stale(harness: str) -> str: | ||
| 590 | """`harness`, after a warning when it is a build in this checkout's runtime/build older than vk_harness's sources | ||
| 591 | (a pull since it was built): it would draw with the old harness and say nothing. A harness outside runtime/build | ||
| 592 | (--harness or LEONIDA_VK_HARNESS naming another folder) isn't compared.""" | ||
| 593 | build = os.path.abspath(os.path.join(ROOT, "runtime", "build")) | ||
| 594 | try: | ||
| 595 | ours = os.path.commonpath([build, os.path.abspath(harness)]) == build | ||
| 596 | except ValueError: # another drive | ||
| 597 | ours = False | ||
| 598 | newer = newer_sources(harness, ROOT, "vk_harness") if ours else [] | ||
| 599 | if newer: | ||
| 600 | more = f" and {len(newer) - 3} more" if len(newer) > 3 else "" | ||
| 601 | print(f"WARNING: {harness} is older than {', '.join(newer[:3])}{more}; rebuild it " | ||
| 602 | f"(cmake --build <build folder> --target vk_harness) to draw with this checkout's harness", | ||
| 603 | file=sys.stderr) | ||
| 604 | return harness | ||
| 605 | |||
| 606 | |||
| 587 | def find_harness(explicit: str | None) -> str: | 607 | def find_harness(explicit: str | None) -> str: |
| 588 | executable = "vk_harness.exe" if os.name == "nt" else "vk_harness" | 608 | executable = "vk_harness.exe" if os.name == "nt" else "vk_harness" |
| 589 | build = os.path.join(ROOT, "runtime", "build") | 609 | build = os.path.join(ROOT, "runtime", "build") |
| @@ -594,11 +614,11 @@ def find_harness(explicit: str | None) -> str: | |||
| 594 | *(os.path.join(folder, executable) for folder in build_dirs), | 614 | *(os.path.join(folder, executable) for folder in build_dirs), |
| 595 | ): | 615 | ): |
| 596 | if candidate and os.path.isfile(candidate): | 616 | if candidate and os.path.isfile(candidate): |
| 597 | return candidate | 617 | return warn_if_stale(candidate) |
| 598 | for folder in build_dirs: | 618 | for folder in build_dirs: |
| 599 | configured = find_test_program(folder, "vk_harness") | 619 | configured = find_test_program(folder, "vk_harness") |
| 600 | if configured: | 620 | if configured: |
| 601 | return os.path.join(configured, executable) | 621 | return warn_if_stale(os.path.join(configured, executable)) |
| 602 | raise SystemExit( | 622 | raise SystemExit( |
| 603 | "vk_harness not found: build runtime/build/linux or runtime/build/windows (target vk_harness), " | 623 | "vk_harness not found: build runtime/build/linux or runtime/build/windows (target vk_harness), " |
| 604 | "or set --harness/LEONIDA_VK_HARNESS" | 624 | "or set --harness/LEONIDA_VK_HARNESS" |
diff --git a/tools/stale_build.py b/tools/stale_build.py new file mode 100644 index 000000000..0945e5fed --- /dev/null +++ b/tools/stale_build.py | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | """Which sources of a runtime/test program are newer than a built copy of it. | ||
| 2 | |||
| 3 | make_game.py (vk_pipeline_check) and first_light.py (vk_harness) take a program already in runtime/build when there | ||
| 4 | is one. After a pull that changed the program, that copy is from the old sources and would run silently. The | ||
| 5 | sources are runtime/test/<name>.cpp and the headers it pulls in with #include "..." (followed through other | ||
| 6 | headers): a change to any of them recompiles and relinks the program, so a current build is never older than them. | ||
| 7 | runtime/CMakeLists.txt isn't one: a change there that doesn't concern the program leaves it as it was. | ||
| 8 | """ | ||
| 9 | import os | ||
| 10 | import re | ||
| 11 | |||
| 12 | _INCLUDE = re.compile(r'^\s*#\s*include\s*"([^"]+)"', re.MULTILINE) | ||
| 13 | |||
| 14 | |||
| 15 | def program_sources(root, name): | ||
| 16 | """The files program `name` of runtime/test is built from, as far as they exist in this checkout.""" | ||
| 17 | runtime = os.path.join(root, "runtime") | ||
| 18 | pending = [os.path.join(runtime, "test", name + ".cpp")] | ||
| 19 | found = [] | ||
| 20 | seen = set() | ||
| 21 | while pending: | ||
| 22 | path = os.path.normpath(pending.pop()) | ||
| 23 | if path in seen or not os.path.isfile(path): | ||
| 24 | continue | ||
| 25 | seen.add(path) | ||
| 26 | found.append(path) | ||
| 27 | try: | ||
| 28 | with open(path, encoding="utf-8", errors="replace") as f: | ||
| 29 | text = f.read() | ||
| 30 | except OSError: | ||
| 31 | continue | ||
| 32 | pending.extend(os.path.join(os.path.dirname(path), inc) for inc in _INCLUDE.findall(text)) | ||
| 33 | return found | ||
| 34 | |||
| 35 | |||
| 36 | def newer_sources(exe, root, name): | ||
| 37 | """The sources of program `name` changed after `exe` was built, relative to `root`; empty when `exe` is current | ||
| 38 | or isn't there to compare.""" | ||
| 39 | try: | ||
| 40 | built = os.path.getmtime(exe) | ||
| 41 | except OSError: | ||
| 42 | return [] | ||
| 43 | newer = [] | ||
| 44 | for path in program_sources(root, name): | ||
| 45 | try: | ||
| 46 | if os.path.getmtime(path) > built: | ||
| 47 | newer.append(os.path.relpath(path, root).replace(os.sep, "/")) | ||
| 48 | except OSError: | ||
| 49 | pass | ||
| 50 | return newer | ||