diff options
| author | Felix Croasdale <205819305+etcetera-yt@users.noreply.github.com> | 2026-11-22 03:02:20 -0600 |
|---|---|---|
| committer | Felix Croasdale <205819305+etcetera-yt@users.noreply.github.com> | 2026-11-22 03:02:20 -0600 |
| commit | e63bf6bdefa9c41340a3c1f7fde428ee676b1d8e (patch) | |
| tree | 51f9b8092b65373590a7e0b8fb9ab231fb3e2726 /tools/mc_command.py | |
| parent | 426023a585b47ba04509d5f3e5e52d6ae40e1109 (diff) | |
mc_command.run: a missing llvm-mc is one line, not a FileNotFoundError traceback
Without llvm-mc, run_gpu_tests.py, valu_fuzz.py, lds_fuzz.py,
image_fuzz.py, crosslane_fuzz.py and runtime/test/shaders/build.py
ended in 'FileNotFoundError: [WinError 2]' from subprocess.run: the first
step of TEST-71 on a Windows machine without one. Only shader_disasm.py
said what was missing. mc_command.run() starts an llvm-mc command and
turns a command that can't be started into shader_disasm.py's message
(set LLVM_MC or --llvm-mc, build_llvm_mc.ps1, the WSL form); the six
llvm-mc call sites use it. tests/test_mc_command.py covers run() and
each tool with a nonexistent LLVM_MC.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'tools/mc_command.py')
| -rw-r--r-- | tools/mc_command.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/mc_command.py b/tools/mc_command.py index 9c1f14946..b21f5a4ce 100644 --- a/tools/mc_command.py +++ b/tools/mc_command.py | |||
| @@ -5,12 +5,15 @@ needs the command-line form when llvm-mc runs inside WSL, because the official W | |||
| 5 | target: | 5 | target: |
| 6 | 6 | ||
| 7 | set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc | 7 | set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc |
| 8 | |||
| 9 | run() starts such a command and turns a missing llvm-mc into one line instead of a FileNotFoundError traceback. | ||
| 8 | """ | 10 | """ |
| 9 | from __future__ import annotations | 11 | from __future__ import annotations |
| 10 | 12 | ||
| 11 | import os | 13 | import os |
| 12 | import shlex | 14 | import shlex |
| 13 | import shutil | 15 | import shutil |
| 16 | import subprocess | ||
| 14 | 17 | ||
| 15 | 18 | ||
| 16 | def split_command(raw: str) -> list: | 19 | def split_command(raw: str) -> list: |
| @@ -41,3 +44,18 @@ def mc_command(raw: str | None = None) -> list: | |||
| 41 | if raw is None: | 44 | if raw is None: |
| 42 | raw = os.environ.get("LLVM_MC", "llvm-mc") | 45 | raw = os.environ.get("LLVM_MC", "llvm-mc") |
| 43 | return split_command(raw) or ["llvm-mc"] | 46 | return split_command(raw) or ["llvm-mc"] |
| 47 | |||
| 48 | |||
| 49 | def not_found(exe: str, error: OSError) -> str: | ||
| 50 | """The message for an llvm-mc that can't be started (shader_disasm.py's wording).""" | ||
| 51 | return (f"'{exe}' could not be started: {error}. Put llvm-mc on PATH or set LLVM_MC (or --llvm-mc) to it\n" | ||
| 52 | f"(on Windows, scripts\\build_llvm_mc.ps1 builds one and sets it), e.g.\n" | ||
| 53 | f" LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc") | ||
| 54 | |||
| 55 | |||
| 56 | def run(cmd: list, **kwargs) -> subprocess.CompletedProcess: | ||
| 57 | """subprocess.run for an llvm-mc command line; one that can't be started ends the tool with not_found().""" | ||
| 58 | try: | ||
| 59 | return subprocess.run(cmd, **kwargs) | ||
| 60 | except OSError as e: | ||
| 61 | raise SystemExit(not_found(cmd[0], e)) from None | ||