[Lldb-commits] [PATCH] D58219: [dotest] Fix compiler version number comparison

Zachary Turner via lldb-commits lldb-commits at lists.llvm.org
Wed Feb 13 17:04:30 PST 2019


Try `import distutils.LooseVersion` and use that to do the comparison.
On Wed, Feb 13, 2019 at 4:49 PM Frederic Riss via Phabricator <
reviews at reviews.llvm.org> wrote:

> friss created this revision.
> friss added reviewers: zturner, labath.
> Herald added a reviewer: serge-sans-paille.
> Herald added a subscriber: jdoerfert.
>
> dotest's version comparision function is just a lexicographical compare
> of the version strings. This is obviously wrong. This patch implements
> a numerical comparision of the individual version components instead.
>
> Python is not my language of choice, please suggest a better
> implementation!
>
>
> https://reviews.llvm.org/D58219
>
> Files:
>   packages/Python/lldbsuite/test/lldbtest.py
>
>
> Index: packages/Python/lldbsuite/test/lldbtest.py
> ===================================================================
> --- packages/Python/lldbsuite/test/lldbtest.py
> +++ packages/Python/lldbsuite/test/lldbtest.py
> @@ -1351,14 +1351,31 @@
>
>          if (version is None):
>              return True
> +
> +        def compare_version_strings(v1, v2):
> +            split1 = v1.split('.')
> +            split2 = v2.split('.')
> +            while len(split1) > len(split2):
> +                split2.append("0")
> +            while len(split2) > len(split1):
> +                split1.append("0")
> +
> +            versions = zip(split1, split2)
> +            for (subv1, subv2) in versions:
> +                diff = int(subv1) - int(subv2)
> +                if diff != 0:
> +                    return diff
> +
> +            return 0
> +
>          if (operator == '>'):
> -            return self.getCompilerVersion() > version
> +            return compare_version_strings(self.getCompilerVersion(),
> version) > 0
>          if (operator == '>=' or operator == '=>'):
> -            return self.getCompilerVersion() >= version
> +            return compare_version_strings(self.getCompilerVersion(),
> version) >= 0
>          if (operator == '<'):
> -            return self.getCompilerVersion() < version
> +            return compare_version_strings(self.getCompilerVersion(),
> version) < 0
>          if (operator == '<=' or operator == '=<'):
> -            return self.getCompilerVersion() <= version
> +            return compare_version_strings(self.getCompilerVersion(),
> version) <= 0
>          if (operator == '!=' or operator == '!' or operator == 'not'):
>              return str(version) not in str(self.getCompilerVersion())
>          return str(version) in str(self.getCompilerVersion())
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20190213/5ab8ada6/attachment.html>


More information about the lldb-commits mailing list