Skip to content

tools/rdna2spirv: reject a --out that is a file (new BUILD item) - #2475

Merged
ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
NethminaYasas:tools/rdna2spirv-out-path-validation
Nov 22, 2026
Merged

ItsNotRexed merged 1 commit into
ItsNotRexed:mainfrom
NethminaYasas:tools/rdna2spirv-out-path-validation

Conversation

@NethminaYasas

Copy link
Copy Markdown
Contributor

Claim: new BUILD item in the coordination issue #2300 — claim comment. The coordinator did not assign a numeric item ID (it was claimed as an unlisted one-line item).

Depends on: none.

What

tools/rdna2spirv.py validated src but never --out. A regular file at --out, a path under a file, a dangling symlink or an unmapped Windows drive root used to abort with an uncaught FileExistsError / NotADirectoryError traceback (and the --merge path failed later in write_index).

The guard now runs right after parse_args(), before --merge and before any os.makedirs(): one argparse error line, exit 2, no traceback, and nothing created, modified or overwritten. Wording follows the same guards in shader_disasm.py (#1607) and tex_export.py (#1632). Ancestor lookup uses realpath so symlinked .. components resolve the way os.makedirs uses them, and stops at a non-existent root instead of looping forever.

No docs/design.md change: this is input validation, not a translator rule.

Verification

  • AI-assisted. No GPU used; no game files; stdlib-only Python.
  • python -m compileall -q make_game.py tools tests — pass.
  • python -I tests/test_rdna2spirv_cli.py -v — 25 tests, OK, 1 skipped (creating symlinks needs a Windows privilege not held here; the skip reason is explicit). New cases cover a file at --out, a path under a file, --out with --merge, a trailing path separator, an unmapped drive root, and a control that a new folder with missing parents still translates.
  • python -m unittest discover -s tests/semantic -v — 2567 tests, OK (3 skipped).
  • python -I make_game.py --help — pass.
  • CodeRabbit: two findings — (1) abspath collapsed .. across symlink components, fixed by using realpath; (2) an unmapped drive root made the ancestor walk loop forever, fixed by stopping at a root whose parent is itself, with a regression test. Final review: no new findings. The third finding was about a pre-existing stale submodule checkout in my working tree, not this diff; I aligned the submodule to the branch's gitlink and it is absent from the PR.
  • git status / git diff: only tools/rdna2spirv.py and tests/test_rdna2spirv_cli.py. No game data, shaders, logs or reports quoting them.

Validate --out right after parsing arguments: a file, a path under a file,
a dangling symlink or an unmapped drive root is now one argparse error line
with exit 2, instead of a FileExistsError/NotADirectoryError traceback, and
before --merge or os.makedirs can write anything. Matches the guards in
shader_disasm.py (ItsNotRexed#1607) and tex_export.py (ItsNotRexed#1632).

Add subprocess tests for those paths and a control that a new output folder
with missing parents still translates. CPU-only; no game data.
@Marukooh

Copy link
Copy Markdown
Contributor

Tested 4a03e78 on CachyOS Linux, Python 3.14.10. The CLI suite passed 24 tests and skipped the Windows-only drive case. I also compared a synthetic source directory with --out pointed at an existing file. The parent exited 1 with a traceback during normal translation and gave a shard-index error with --merge. The patch returned a clear usage error (exit 2) in both modes, and the file contents remained unchanged. CPU-only, AI-assisted.

@zneel

zneel commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 4a03e786 on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 170/185, 15 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 170/185, 15 skipped, 0 failed
pytest tests/test_rdna2spirv_cli.py tests/test_translate.py 550 passed, 3 skipped, 22 subtests passed in 64.34s (0:01:04)

By hand on Windows, rdna2spirv.py <src> --out X:

--out main 49475796 this head
an existing file FileExistsError: [WinError 183] traceback error: ... is a file, not a folder, exit 2
a path under that file error: cannot create ...: ... is a file, not a folder, exit 2
an unmapped drive root (Q:\) error: cannot create Q:\: Q:\ is not a folder, exit 2

In each case the file was left as it was. A small cosmetic point: in the second case the message names the parent by its long path, while the --out I gave was an 8.3 short path, presumably from resolve().

The suite's 193 modules are byte-identical to main's, as expected for a CLI-only change.

AI-assisted (Claude Code); I checked the results.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 4a03e78 on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 139/185 passed, 46 skipped, 0 failed. main 4947579 gives 139/185, 46 skipped, 0 failed. All 190 test shaders translate and pass spirv-val.
  • tests/test_rdna2spirv_cli.py: ran 25 tests in 3.980s; OK (skipped=1).

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit 78af799 into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
@NethminaYasas
NethminaYasas deleted the tools/rdna2spirv-out-path-validation branch November 23, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants