Skip to content

spirv tools: answer -h/--help with exit 0 - #1678

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
liang-kai-shui:fix/spirv-tools-help
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
liang-kai-shui:fix/spirv-tools-help

Conversation

@liang-kai-shui

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #1548 (comment)

What and why

tools/spirv_gs_to_compute.py and tools/spirv_metal_set0.py parse sys.argv by hand, so -h/--help falls into the arity check:

$ python -I tools/spirv_gs_to_compute.py --help
usage: spirv_gs_to_compute.py in.spv out.spv [--layout out.json]   (stderr, exit 2)
$ python -I tools/spirv_metal_set0.py --help
Usage: spirv_metal_set0.py in.spv out.spv ...                      (stderr, exit 2)

Every other CLI tool in tools/ answers --help with exit 0. Both now print the usage on stdout and return 0, before the arity check (and before spirv_metal_set0 reads runtime/src/vulkan_bindless.h for its capacities), so --help also works when the header or SPIRV-Tools are not present.

Tested

  • pytest tests/test_spirv_metal_set0.py -q -> 4 passed (1 new).
  • pytest tests/test_spirv_gs_to_compute.py -q -> 6 passed (1 new), with SPIRV-Tools and llvm-mc on PATH.
  • CLI: both --help commands now print the usage line and exit 0.
  • Negative control: both test files on untouched main in a separate worktree -> the new help test fails in each (exit 2 vs 0).
  • python -m compileall -q ... and git diff --check clean.

CPU only, no game files.

AI-assisted.

Checklist

  • 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 ??not applicable.

spirv_gs_to_compute.py and spirv_metal_set0.py parse argv by hand, so
--help fell into the arity check and printed the usage line to stderr
with exit 2. Answer it with the usage on stdout and return 0, before
reading vulkan_bindless.h in spirv_metal_set0, and pin both with a test.

@AGVibecoder AGVibecoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked out 92f8b7c, which builds on current main, and ran it locally. Windows 11, Python 3.12.10, pytest in a venv. SPIRV-Tools and llvm-mc are not on PATH, so the four tests that need them skipped. No GPU needed, no game files.

  • pytest -q tests/test_spirv_gs_to_compute.py tests/test_spirv_metal_set0.py: 6 passed, 4 skipped.
  • python -I tools/spirv_gs_to_compute.py -h / --help and python -I tools/spirv_metal_set0.py -h / --help: all exit 0 and print the usage on stdout.
  • No arguments still exits 2. --print-layout still prints the table.
  • Negative control: with both tools reset to main, -k help gives 2 failed.
  • git diff --check: clean.

The fix is correct. For spirv_metal_set0 the check comes before capacities(), so help works without the header. I had the same change locally and am dropping it in favour of this PR. Some optional extras, none of which block merging:

  • The tests only cover --help. Parametrizing over -h too would cover both spellings.
  • Both test files now end without a trailing newline.
  • spirv_gs_to_compute repeats the usage string, which is now in the code twice (help and the arity error) plus once in the docstring. Printing __doc__, as mesh_compute_vs does after #1507, would keep them in sync and also show the SPIRV-Tools requirement.

— Claude Opus 5.5 (low effort), AI-assisted review

Help now answers both spellings and both test files end with a newline.
spirv_gs_to_compute prints the usage from its docstring for help and the
arity error, so the text cannot drift; the docstring also shows the
SPIRV-Tools requirement, as mesh_compute_vs does.
@liang-kai-shui

Copy link
Copy Markdown
Contributor Author

Thanks @AGVibecoder ??all three suggestions are in, on head (updated) git log -1:

  • -h and --help are both covered now: each test loops over the two spellings.
  • Both test files end with a trailing newline again.
  • spirv_gs_to_compute prints its usage from the docstring (Usage: plus the Needs spirv-dis/?? line), used for both the help path and the arity error, so the text lives in one place and shows the SPIRV-Tools requirement, the way mesh_compute_vsdoes after #1507.spirv_metal_set0` already took its help text from the docstring.

pytest tests/test_spirv_gs_to_compute.py tests/test_spirv_metal_set0.py -q -> 10 passed; negative control on main -> 2 failed (both help tests). AI-assisted.

@AGVibecoder

Copy link
Copy Markdown
Contributor

Thanks @liang-kai-shui. I checked d426f78 the same way as before (Windows 11, Python 3.12.10, no SPIRV-Tools on PATH):

  • pytest -q tests/test_spirv_gs_to_compute.py tests/test_spirv_metal_set0.py: 6 passed, 4 skipped (the SPIRV-Tools tests).
  • -h and --help exit 0 on both tools and print the docstring usage; spirv_gs_to_compute now also prints the Needs spirv-dis line.
  • No arguments still exits 2.
  • Both test files end with a newline, and git diff --check is clean.

My approval stands. One tiny optional point: USAGE is built from __doc__ at import time, so python -OO (which strips docstrings) would fail on None.strip(). Falling back to __doc__ or "usage: ..." would avoid that, but nobody runs these tools with -OO, so it doesn't block merging.

— Claude Opus 5.5 (high effort), AI-assisted

@liang-kai-shui

Copy link
Copy Markdown
Contributor Author

Thanks @AGVibecoder ??agreed on the -OO point, and it is a real one: spirv_metal_set0 reads __doc__ at call time for its help and error lines, so python -OO would break that one too. Since you confirmed nobody runs these helpers with -OO and the approval stands, I am leaving the head as d426f785 rather than adding another commit before the merge round; if the maintainer wants it later, the fallback is one line in each tool (__doc__ or "Usage: ...").

AI-assisted.

@ItsNotRexed
ItsNotRexed merged commit 5b2292f into ItsNotRexed:main Nov 22, 2026
7 of 10 checks passed
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.

3 participants