diff options
Diffstat (limited to 'tools/mc_command.py')
| -rw-r--r-- | tools/mc_command.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/mc_command.py b/tools/mc_command.py new file mode 100644 index 000000000..9f76e03b4 --- /dev/null +++ b/tools/mc_command.py | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | """Resolve LLVM_MC to an argv list. | ||
| 2 | |||
| 3 | LLVM_MC may be one executable (a path, spaces and all) or a whole command line. Windows needs the command-line | ||
| 4 | form when llvm-mc runs inside WSL, because the official Windows LLVM build has no AMDGPU target: | ||
| 5 | |||
| 6 | set LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc | ||
| 7 | """ | ||
| 8 | import os | ||
| 9 | import shlex | ||
| 10 | |||
| 11 | |||
| 12 | def split_command(raw: str) -> list: | ||
| 13 | """Split a command line without eating the backslashes of a Windows path (POSIX shlex would).""" | ||
| 14 | raw = raw.strip() | ||
| 15 | if not raw: | ||
| 16 | return [] | ||
| 17 | if os.path.isfile(raw): | ||
| 18 | return [raw] # a plain path, spaces and all | ||
| 19 | if os.name != "nt": | ||
| 20 | return shlex.split(raw) | ||
| 21 | parts = shlex.split(raw, posix=False) | ||
| 22 | return [p[1:-1] if len(p) > 1 and p[0] == p[-1] == '"' else p for p in parts] | ||
| 23 | |||
| 24 | |||
| 25 | def mc_command(raw: str | None = None) -> list: | ||
| 26 | """LLVM_MC is a path, or a command line: 'wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc'.""" | ||
| 27 | if raw is None: | ||
| 28 | raw = os.environ.get("LLVM_MC", "llvm-mc") | ||
| 29 | return split_command(raw) or ["llvm-mc"] | ||