From: Gabe Black Date: Thu, 30 Apr 2020 09:00:02 +0000 (-0700) Subject: python: Fix compareVersions for python 3. X-Git-Tag: v20.0.0.0~78 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b4686c8d8451ff5c6ced93f31cc84b3195d051d5;p=gem5.git python: Fix compareVersions for python 3. When the internal utility function make_version_list sees a string, it tries to convert it into a list using the map() function. In python 3, that returns an iterator. The following call to zip() will consume those iterators, and then the following calls to len() will die because they don't work on map iterators. This is only a problem if all the common components of the version lists are equal, and the comparison needs to then check if one of the lists was equal to the other but with more components. When versions are equal, for instance when compiling with the oldest supported version of gcc (4.8.0) this error surfaces and breaks our scons build. A simple fix is to just wrap the call to map() with list() to convert the iterator to a flat list, making the other logic work as before. Change-Id: If9dc5cd7fff70c21229ac3dd9a017edeccd26148 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/28309 Reviewed-by: Giacomo Travaglini Maintainer: Giacomo Travaglini Tested-by: kokoro --- diff --git a/src/python/m5/util/__init__.py b/src/python/m5/util/__init__.py index fd1ea9125..98a7a08dd 100644 --- a/src/python/m5/util/__init__.py +++ b/src/python/m5/util/__init__.py @@ -125,7 +125,8 @@ def compareVersions(v1, v2): if isinstance(v, (list,tuple)): return v elif isinstance(v, string_types): - return map(lambda x: int(re.match('\d+', x).group()), v.split('.')) + return list(map(lambda x: int(re.match('\d+', x).group()), + v.split('.'))) else: raise TypeError()