[Lldb-commits] [lldb] [lldb] Rally around triple rather than arch in the API tests (PR #191416)

David Spickett via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 10 06:59:47 PDT 2026


================
@@ -6,69 +6,23 @@
 from lldbsuite.test import configuration
 import lldbsuite.test.lldbutil as lldbutil
 
-REMOTE_PLATFORM_NAME_RE = re.compile(r"^remote-(.+)$")
-SIMULATOR_PLATFORM_RE = re.compile(r"^(.+)-simulator$")
+TRIPLE_RE = re.compile(
+    r"^(?P<arch>[a-zA-Z0-9_]+)"  # arch (required)
+    r"(?:-(?P<vendor>[a-zA-Z0-9_]+))?"  # vendor (optional)
+    r"(?:-(?P<os>[a-zA-Z_]+)(?P<os_version>[\d.]+)?)?"  # os + version (optional)
+    r"(?:-(?P<env>[a-zA-Z0-9_]+))?"  # env/abi (optional)
+    r"$"
+)
 
 
-def get_os_env_from_platform(platform):
-    match = REMOTE_PLATFORM_NAME_RE.match(platform)
-    if match:
-        return match.group(1), ""
-    match = SIMULATOR_PLATFORM_RE.match(platform)
-    if match:
-        return match.group(1), "simulator"
-    return None, None
-
-
-def get_os_from_sdk(sdk):
-    return sdk[: sdk.find(".")], ""
-
-
-def get_os_and_env():
-    if configuration.lldb_platform_name:
-        return get_os_env_from_platform(configuration.lldb_platform_name)
-    if configuration.apple_sdk:
-        return get_os_from_sdk(configuration.apple_sdk)
-    return None, None
-
-
-def get_triple():
-    # Construct the vendor component.
-    vendor = "apple"
-
-    # Construct the os component.
-    os, env = get_os_and_env()
-    if os is None or env is None:
-        return None, None, None, None
-
-    # Get the SDK from the os and env.
-    sdk = lldbutil.get_xcode_sdk(os, env)
-    if sdk is None:
-        return None, None, None, None
-
-    # Get the version from the SDK.
-    version = lldbutil.get_xcode_sdk_version(sdk)
-    if version is None:
-        return None, None, None, None
-
-    return vendor, os, version, env
-
-
-def get_triple_str(arch, vendor, os, version, env):
-    if None in [arch, vendor, os, version, env]:
-        return None
-
-    component = [arch, vendor, os + version]
-    if env:
-        component.append(env)
-    return "-".join(component)
+def split_triple(triple):
+    m = TRIPLE_RE.match(triple)
+    if m:
+        return m["arch"], m["vendor"], m["os"], m["os_version"], m["env"]
----------------
DavidSpickett wrote:

https://docs.python.org/3/library/re.html#re.Match.groups ?

Then it is clear that you expect to get them in the order stated in the regex rather than typing them out again and maybe shuffling them around.

https://github.com/llvm/llvm-project/pull/191416


More information about the lldb-commits mailing list