tools: one cached work_root() per shader instead of nine realpath() calls (OLD-9777) #1265

Closed
leonida/mandy
ambroseautomation wants to merge 0 commits from carry/old-9777-work-root-cache into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

ambroseautomation commented 2026-11-24 21:03:07 +00:00

Claimed in the coordination issue as: OLD-9777 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144385534)

What and why

Carries forward old-pr/9777 (draft #55, original commit author pes7 preserved across all 3 commits; indexed in #17), rebased cleanly onto current main (0b45fdc21).

Replaces repeated os.path.realpath calls per shader in tools/rdna2spirv.py and tools/shader_meta.py with a cached work_root() helper in tools/report_paths.py:

  • Caches os.path.realpath for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output).
  • Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately.
  • Adds WorkRootTests in tests/test_report_paths.py verifying absolute-path caching, relative-path re-resolution after os.chdir, and 8.3 short-path compatibility on Windows.

Tested

  • python -I tests/test_report_paths.py -v: 24 tests, OK (1 skipped: Windows symlink privilege).
  • python -m compileall -q make_game.py tools tests: exit 0.
  • python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py: exit 0 (no game data).

GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — path-resolution caching only, no codegen changes)
Claimed in the coordination issue as: OLD-9777 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144385534) ### What and why Carries forward `old-pr/9777` (draft #55, original commit author `pes7` preserved across all 3 commits; indexed in #17), rebased cleanly onto current `main` (`0b45fdc21`). Replaces repeated `os.path.realpath` calls per shader in `tools/rdna2spirv.py` and `tools/shader_meta.py` with a cached `work_root()` helper in `tools/report_paths.py`: - Caches `os.path.realpath` for absolute paths so translating a shader resolves its work root once instead of nine times (byte-identical output). - Resolves relative paths on every call (never from the cache), so changing working directory between calls still resolves accurately. - Adds `WorkRootTests` in `tests/test_report_paths.py` verifying absolute-path caching, relative-path re-resolution after `os.chdir`, and 8.3 short-path compatibility on Windows. ### Tested - `python -I tests/test_report_paths.py -v`: 24 tests, OK (1 skipped: Windows symlink privilege). - `python -m compileall -q make_game.py tools tests`: exit 0. - `python -I scripts/check_no_game_data.py tools/report_paths.py tools/rdna2spirv.py tools/shader_meta.py tests/test_report_paths.py`: exit 0 (no game data). GPUs tested: n/a (Python path resolution helper + stdlib unit tests on Windows 11 Pro 64-bit, Python 3.12.10) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — path-resolution caching only, no codegen changes)
tiguan26 approved these changes 2026-11-25 06:23:13 +00:00
tiguan26 left a comment

Approving. Merged into current main (42537e7) with no conflicts. tests/test_report_paths.py plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only test_int32_to_f64 failing, as on main here (Linux, Python 3.13).

I checked every replaced call: each was the same dirname(dirname(realpath(path))), so work_root returns the same value. Only absolute spellings are cached, so a chdir can't give a stale answer, and the size cap stops the table growing past one corpus.

AI-assisted (Claude).

Approving. Merged into current main (42537e7) with no conflicts. `tests/test_report_paths.py` plus the shader_meta tests pass (57 passed), and the full translator suite gives 487 files / 6,279 tests with only `test_int32_to_f64` failing, as on main here (Linux, Python 3.13). I checked every replaced call: each was the same `dirname(dirname(realpath(path)))`, so `work_root` returns the same value. Only absolute spellings are cached, so a `chdir` can't give a stale answer, and the size cap stops the table growing past one corpus. AI-assisted (Claude).
PierreEbele commented 2026-11-25 14:42:41 +00:00

Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review.

Recommendation: Merge

Reviewed 74cc3eb: 3 commits (cached work_root() helper, relative-path chdir guard, tests). Ran on arm64 Linux with no game files: tests/test_report_paths.py 24 OK on the branch; the branch's test file fails on main (no work_root) as expected; test_shader_meta, test_shader_meta_operands, test_shader_library, test_pe_shader_containers, test_bvh_shaders_stage and the fspx semantic tests all pass on both trees and on the branch applied to current main (the nine call sites are unchanged there; patch applies cleanly). Probed relative/absolute/symlinked/retargeted spellings across two synthetic work folders: only difference from main is the retargeted-symlink case, which is the documented "cannot change while a build runs" assumption and unreachable in a build where each spelling is translated once; relative-path-after-chdir behaves correctly on both. No findings. AI-assisted review. **Recommendation:** Merge
Sign in to join this conversation.
No description provided.