SCons: Fix get_compiler_version() to return ints

Otherwise comparisons would fail for compiler versions above 10.
Also simplified code somewhat to avoid using subprocess too much
needlessly.
This commit is contained in:
Rémi Verschelde 2020-02-26 13:23:37 +01:00
parent 1e57b558f2
commit c7dc5142b5
3 changed files with 23 additions and 34 deletions

View file

@ -558,19 +558,18 @@ def is_vanilla_clang(env):
def get_compiler_version(env):
"""
Returns an array of version numbers as strings: [major, minor, patch].
Returns an array of version numbers as ints: [major, minor, patch].
The return array should have at least two values (major, minor).
"""
if using_gcc(env):
version = decode_utf8(subprocess.check_output([env['CXX'], '-dumpversion']).strip())
elif using_clang(env):
# Not using -dumpversion as it used to return 4.2.1: https://reviews.llvm.org/D56803
if not env.msvc:
# Not using -dumpversion as some GCC distros only return major, and
# Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
version = decode_utf8(subprocess.check_output([env['CXX'], '--version']).strip())
else: # TODO: Implement for MSVC
return None
match = re.search('[0-9]+\.[0-9.]*', version)
match = re.search('[0-9]+\.[0-9.]+', version)
if match is not None:
return match.group().split('.')
return list(map(int, match.group().split('.')))
else:
return None