Skip to content

Commit

Permalink
[lldb] Migrate distutils.version.LooseVersion to packaging (llvm#82066)
Browse files Browse the repository at this point in the history
The distutils package has been deprecated and was removed from Python
3.12. The migration page [1] advises to use the packaging module
instead. Since Python 3.6 that's vendored into pkg_resources.

[1] https://peps.python.org/pep-0632/#migration-advice

(cherry picked from commit 0c02329)
  • Loading branch information
JDevlieghere committed Apr 18, 2024
1 parent ffc041d commit e804c8b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions lldb/packages/Python/lldbsuite/test/lldbplatformutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import subprocess
import sys
import os
from distutils.version import LooseVersion
from urllib.parse import urlparse
from pkg_resources import packaging

# LLDB modules
import lldb
Expand Down Expand Up @@ -297,27 +297,30 @@ def expectedCompilerVersion(compiler_version):
if compiler_version is None:
return True
operator = str(compiler_version[0])
version = compiler_version[1]
version_str = str(compiler_version[1])

if version is None:
if not version_str:
return True

test_compiler_version = getCompilerVersion()
if test_compiler_version == "unknown":
test_compiler_version_str = getCompilerVersion()
if test_compiler_version_str == "unknown":
# Assume the compiler version is at or near the top of trunk.
return operator in [">", ">=", "!", "!=", "not"]

version = packaging.version.parse(version_str)
test_compiler_version = packaging.version.parse(test_compiler_version_str)

if operator == ">":
return LooseVersion(test_compiler_version) > LooseVersion(version)
return test_compiler_version > version
if operator == ">=" or operator == "=>":
return LooseVersion(test_compiler_version) >= LooseVersion(version)
return test_compiler_version >= version
if operator == "<":
return LooseVersion(test_compiler_version) < LooseVersion(version)
return test_compiler_version < version
if operator == "<=" or operator == "=<":
return LooseVersion(test_compiler_version) <= LooseVersion(version)
return test_compiler_version <= version
if operator == "!=" or operator == "!" or operator == "not":
return str(version) not in str(test_compiler_version)
return str(version) in str(test_compiler_version)
return version_str not in test_compiler_version_str
return version_str in test_compiler_version_str


def expectedCompiler(compilers):
Expand Down

0 comments on commit e804c8b

Please sign in to comment.