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 <hoanguyen@ucdavis.edu>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32014
Reviewed-by: Gabe Black <gabeblack@google.com>
Maintainer: Gabe Black <gabeblack@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
import sys
from six import string_types
+from six.moves import zip_longest
from . import convert
from . import jobfile
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):