[compiler-rt] Reland "[compiler-rt][test] Use packaging.version.Version to compare glibc versions" (#158230)" (PR #158236)

David Spickett via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 12 01:03:26 PDT 2025


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/158236

This reverts commit d7b7b9cd6d12a8cbc35fba4ecfd0a557011e9cdd.

As the name suggests, packaging's Version is more strict than distutil's LooseVersion. `LooseVersion(".3")` is fine but `Version(".3")` raises an exception. I think this was happening on the Google bot, which lead us to enable tests that should not have been running.

Looking at the way we find the glibc version, it should be `<0 or more numbers>.<0 or more numbers>`. So I think the only way we're getting invalid versions is if it comes out as `X.` or `.Y`.

>From df897a71bfce3a6bf4649d09294e04429db3cc37 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 12 Sep 2025 07:51:38 +0000
Subject: [PATCH 1/2] Reland "[compiler-rt][test] Use packaging.version.Version
 to compare glibc versions" (#158230)"

This reverts commit d7b7b9cd6d12a8cbc35fba4ecfd0a557011e9cdd.

TODO: with what added?
---
 compiler-rt/test/lit.common.cfg.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index e2e815444dcf9..7734491310edf 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -713,9 +713,9 @@ def add_glibc_versions(ver_string):
         if config.android:
             return
 
-        from distutils.version import LooseVersion
+        from packaging.version import Version
 
-        ver = LooseVersion(ver_string)
+        ver = Version(ver_string)
         any_glibc = False
         for required in [
             "2.19",
@@ -727,7 +727,7 @@ def add_glibc_versions(ver_string):
             "2.38",
             "2.40",
         ]:
-            if ver >= LooseVersion(required):
+            if ver >= Version(required):
                 config.available_features.add("glibc-" + required)
                 any_glibc = True
             if any_glibc:

>From efa1a8b664db60bf43406509112a213526bb0b73 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Fri, 12 Sep 2025 07:59:43 +0000
Subject: [PATCH 2/2] fix exception handling

---
 compiler-rt/test/lit.common.cfg.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 7734491310edf..2d866a3c1bbe1 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -713,9 +713,13 @@ def add_glibc_versions(ver_string):
         if config.android:
             return
 
-        from packaging.version import Version
+        from packaging.version import Version, InvalidVersion
+
+        try:
+            ver = Version(ver_string)
+        except InvalidVersion:
+            return
 
-        ver = Version(ver_string)
         any_glibc = False
         for required in [
             "2.19",



More information about the llvm-commits mailing list