From: Hoa Nguyen Date: Thu, 30 Jul 2020 22:30:57 +0000 (-0700) Subject: util,scons: improve compareVersions function X-Git-Tag: v20.1.0.0~356 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5bf345f77a31c16a0f500cdaaef2749565068fe5;p=gem5.git util,scons: improve compareVersions function Current compareVersions() fails in this case: compareVersions("10", "10.0") return -1 while it should be 0. This at least is causing a systemc compiling issue. This problem causes by the comparison algorithm. The algorithm turns the versions in two lists, and compares the corresponding elements of the two lists up to the last element of the shorter list. If all elements are equal, the longer list will be determined to be the more recent version. Hence, this algorithm determines "10.0" to be more recent to "10". This commit addresses this issue by making the version lists have the same length by adding 0 to the shorter list. JIRA: https://gem5.atlassian.net/browse/GEM5-715 Change-Id: I859679185ac67e1b4d327d8803699cc5e399fa8c Signed-off-by: Hoa Nguyen Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32014 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py index c59f40a81..d26bf4e60 100644 --- a/src/python/m5/util/__init__.py +++ b/src/python/m5/util/__init__.py @@ -44,6 +44,7 @@ import re import sys from six import string_types +from six.moves import zip_longest from . import convert from . import jobfile @@ -132,13 +133,13 @@ def compareVersions(v1, v2): v1 = make_version_list(v1) v2 = make_version_list(v2) + # Compare corresponding elements of lists - for n1,n2 in zip(v1, v2): + # The shorter list is filled with 0 till the lists have the same length + for n1,n2 in zip_longest(v1, v2, fillvalue=0): if n1 < n2: return -1 if n1 > n2: return 1 - # all corresponding values are equal... see if one has extra values - if len(v1) < len(v2): return -1 - if len(v1) > len(v2): return 1 + return 0 def crossproduct(items):