upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/mc_command.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mc_command.py')
-rw-r--r--tools/mc_command.py29
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
3LLVM_MC may be one executable (a path, spaces and all) or a whole command line. Windows needs the command-line
4form 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"""
8import os
9import shlex
10
11
12def 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
25def 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"]