Hoa Nguyen has submitted this change. ( https://gem5-review.googlesource.com/c/public/gem5/+/32014 )

Change subject: util,scons: improve compareVersions function
......................................................................

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 <hoangu...@ucdavis.edu>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/32014
Reviewed-by: Gabe Black <gabebl...@google.com>
Maintainer: Gabe Black <gabebl...@google.com>
Tested-by: kokoro <noreply+kok...@google.com>
---
M src/python/m5/util/__init__.py
1 file changed, 5 insertions(+), 4 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py
index c59f40a..d26bf4e 100644
--- a/src/python/m5/util/__init__.py
+++ b/src/python/m5/util/__init__.py
@@ -44,6 +44,7 @@
 import sys

 from six import string_types
+from six.moves import zip_longest

 from . import convert
 from . import jobfile
@@ -132,13 +133,13 @@

     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):

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/32014
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I859679185ac67e1b4d327d8803699cc5e399fa8c
Gerrit-Change-Number: 32014
Gerrit-PatchSet: 5
Gerrit-Owner: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-Reviewer: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-Reviewer: Gabe Black <gabebl...@google.com>
Gerrit-Reviewer: Hoa Nguyen <hoangu...@ucdavis.edu>
Gerrit-Reviewer: Jason Lowe-Power <power...@gmail.com>
Gerrit-Reviewer: kokoro <noreply+kok...@google.com>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to