[llvm] [cross-project-tests] Avoid requiring packaging for GDB/LLDB version checks (PR #225126)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 22 22:53:03 PDT 2026


https://github.com/arichardson updated https://github.com/llvm/llvm-project/pull/225126

>From 3383a267582c1a550c4de959f77d8cd84166d47b Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Mon, 21 Sep 2026 08:57:28 -0700
Subject: [PATCH 1/2] [cross-project-tests] Avoid requiring packaging for
 GDB/LLDB version checks

Previously, `cross-project-tests/lit.cfg.py` imported `packaging.version` to
compare GDB and LLDB version numbers and unconditionally called
`lit_config.fatal()` when the third-party `packaging` Python package was not
installed in the test environment. Try `packaging.version.parse` first, fall
back to splitting dot-separated integer components when `packaging` is not
available, and raise `ValueError` on unparseable versions so each caller can
emit a context-specific warning instead of aborting the test suite.

This commit was created with the help of AI tools
---
 cross-project-tests/lit.cfg.py | 47 +++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index ae4647d33672e4..e991cd290a3e69 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/cross-project-tests/lit.cfg.py
@@ -295,6 +295,18 @@ def can_target_host():
 lit.util.usePlatformSdkOnDarwin(config, lit_config)
 
 
+def parse_version(v: str):
+    try:
+        from packaging import version
+
+        return version.parse(v)
+    except ImportError:
+        try:
+            return tuple(int(x) for x in v.split("."))
+        except ValueError:
+            raise ValueError(f"could not parse version number '{v}'")
+
+
 def get_gdb_version_string():
     """Return gdb's version string, or None if gdb cannot be found or the
     --version output is formatted unexpectedly.
@@ -384,13 +396,7 @@ def set_lldb_formatters_compatibility_feature():
         # which some LLVM data formatters depend on.
         min_required_lldb_version = "19.0.0"
 
-    try:
-        from packaging import version
-    except:
-        lit_config.fatal("Running lldb tests requires the packaging package")
-        return
-
-    if version.parse(current_lldb_version) < version.parse(min_required_lldb_version):
+    if parse_version(current_lldb_version) < parse_version(min_required_lldb_version):
         raise ValueError(
             f"using version {current_lldb_version} whereas a version >= {min_required_lldb_version} is required"
         )
@@ -404,12 +410,10 @@ def set_apple_lldb_pre_1000_feature():
         return
 
     try:
-        from packaging import version
-    except:
-        lit_config.fatal("Running lldb tests requires the packaging package")
-        return
-
-    if version.parse(apple_lldb_vers) < version.parse("1000"):
+        if parse_version(apple_lldb_vers) < parse_version("1000"):
+            config.available_features.add("apple-lldb-pre-1000")
+    except ValueError as e:
+        lit_config.warning(f"Failed to check Apple LLDB version: {e}")
         config.available_features.add("apple-lldb-pre-1000")
 
 
@@ -419,7 +423,6 @@ def set_apple_lldb_pre_1000_feature():
 # platform and the installed gdb version.
 dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple)
 gdb_version_string = get_gdb_version_string()
-
 if gdb_version_string:
     config.available_features.add("has-gdb")
     print(
@@ -435,10 +438,13 @@ def set_apple_lldb_pre_1000_feature():
 if dwarf_version_string and gdb_version_string:
     if int(dwarf_version_string) >= 5:
         try:
-            from packaging import version
-        except:
-            lit_config.fatal("Running gdb tests requires the packaging package")
-        if version.parse(gdb_version_string) < version.parse("10.1"):
+            gdb_too_old = parse_version(gdb_version_string) < parse_version("10.1")
+        except ValueError as e:
+            lit_config.warning(
+                f"Assuming GDB {gdb_version_string} is incompatible with DWARF v5: {e}"
+            )
+            gdb_too_old = True
+        if gdb_too_old:
             # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
             # XFAIL: !system-darwin && gdb-clang-incompatibility
             config.available_features.add("gdb-clang-incompatibility")
@@ -450,9 +456,8 @@ def set_apple_lldb_pre_1000_feature():
 try:
     set_lldb_formatters_compatibility_feature()
 except ValueError as e:
-    print(
-        f"Marking some LLDB LLVM data-formatter tests as unsupported: {e}",
-        file=sys.stderr,
+    lit_config.warning(
+        f"Marking some LLDB LLVM data-formatter tests as unsupported: {e}"
     )
 
 if platform.system() == "Darwin":

>From 9d6ed92d64b34ffd9d81121fe80fd4cf6aa7ca04 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Tue, 22 Sep 2026 22:52:19 -0700
Subject: [PATCH 2/2] address feedback

---
 cross-project-tests/lit.cfg.py | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

diff --git a/cross-project-tests/lit.cfg.py b/cross-project-tests/lit.cfg.py
index e991cd290a3e69..bf95fd2dcd6fa3 100644
--- a/cross-project-tests/lit.cfg.py
+++ b/cross-project-tests/lit.cfg.py
@@ -438,20 +438,19 @@ def set_apple_lldb_pre_1000_feature():
 if dwarf_version_string and gdb_version_string:
     if int(dwarf_version_string) >= 5:
         try:
-            gdb_too_old = parse_version(gdb_version_string) < parse_version("10.1")
+            if parse_version(gdb_version_string) < parse_version("10.1"):
+                # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
+                # XFAIL: !system-darwin && gdb-clang-incompatibility
+                config.available_features.add("gdb-clang-incompatibility")
+                print(
+                    "XFAIL some tests: use gdb version >= 10.1 to restore test coverage",
+                    file=sys.stderr,
+                )
         except ValueError as e:
             lit_config.warning(
-                f"Assuming GDB {gdb_version_string} is incompatible with DWARF v5: {e}"
+                f"Assuming GDB {gdb_version_string} is incompatible with DWARF version {dwarf_version_string}: {e}"
             )
-            gdb_too_old = True
-        if gdb_too_old:
-            # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
-            # XFAIL: !system-darwin && gdb-clang-incompatibility
             config.available_features.add("gdb-clang-incompatibility")
-            print(
-                "XFAIL some tests: use gdb version >= 10.1 to restore test coverage",
-                file=sys.stderr,
-            )
 
 try:
     set_lldb_formatters_compatibility_feature()



More information about the llvm-commits mailing list