[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
Mon Sep 21 08:58:04 PDT 2026
https://github.com/arichardson created https://github.com/llvm/llvm-project/pull/225126
<!-- nspr:warning -->
> [!WARNING]
> ⚠️ **Part of a stacked PR.** Merge via `nspr land` or GitHub's **Merge stack** (if merging a single PR via the web UI, click **Rebase stack** or run `nspr sync` afterwards).
<!-- /nspr:warning -->
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
>From 4cc3cfbd6b9d2d3743abd0d8aa2b5f78f9c8f875 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] [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 ae4647d33672e..e991cd290a3e6 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":
More information about the llvm-commits
mailing list