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. (cherry picked from commitsc7dc5142b5
anddf7ecfc4a7
)
This commit is contained in:
parent
c34b351b24
commit
75164169c4
|
@ -350,12 +350,13 @@ if selected_platform in platform_list:
|
||||||
# Force to use Unicode encoding
|
# Force to use Unicode encoding
|
||||||
env.Append(MSVC_FLAGS=['/utf8'])
|
env.Append(MSVC_FLAGS=['/utf8'])
|
||||||
else: # Rest of the world
|
else: # Rest of the world
|
||||||
|
version = methods.get_compiler_version(env) or [-1, -1]
|
||||||
|
|
||||||
shadow_local_warning = []
|
shadow_local_warning = []
|
||||||
all_plus_warnings = ['-Wwrite-strings']
|
all_plus_warnings = ['-Wwrite-strings']
|
||||||
|
|
||||||
if methods.using_gcc(env):
|
if methods.using_gcc(env):
|
||||||
version = methods.get_compiler_version(env)
|
if version[0] >= 7:
|
||||||
if version != None and version[0] >= '7':
|
|
||||||
shadow_local_warning = ['-Wshadow-local']
|
shadow_local_warning = ['-Wshadow-local']
|
||||||
|
|
||||||
if (env["warnings"] == 'extra'):
|
if (env["warnings"] == 'extra'):
|
||||||
|
@ -369,8 +370,7 @@ if selected_platform in platform_list:
|
||||||
'-Wduplicated-branches', '-Wduplicated-cond',
|
'-Wduplicated-branches', '-Wduplicated-cond',
|
||||||
'-Wstringop-overflow=4', '-Wlogical-op'])
|
'-Wstringop-overflow=4', '-Wlogical-op'])
|
||||||
env.Append(CXXFLAGS=['-Wnoexcept', '-Wplacement-new=1'])
|
env.Append(CXXFLAGS=['-Wnoexcept', '-Wplacement-new=1'])
|
||||||
version = methods.get_compiler_version(env)
|
if version[0] >= 9:
|
||||||
if version != None and version[0] >= '9':
|
|
||||||
env.Append(CCFLAGS=['-Wattribute-alias=2'])
|
env.Append(CCFLAGS=['-Wattribute-alias=2'])
|
||||||
elif (env["warnings"] == 'all'):
|
elif (env["warnings"] == 'all'):
|
||||||
env.Append(CCFLAGS=['-Wall'] + shadow_local_warning)
|
env.Append(CCFLAGS=['-Wall'] + shadow_local_warning)
|
||||||
|
|
24
methods.py
24
methods.py
|
@ -1,5 +1,4 @@
|
||||||
import os
|
import os
|
||||||
import os.path
|
|
||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -626,14 +625,23 @@ def detect_darwin_sdk_path(platform, env):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def get_compiler_version(env):
|
def get_compiler_version(env):
|
||||||
# Not using this method on clang because it returns 4.2.1 # https://reviews.llvm.org/D56803
|
"""
|
||||||
if using_gcc(env):
|
Returns an array of version numbers as ints: [major, minor, patch].
|
||||||
version = decode_utf8(subprocess.check_output([env['CXX'], '-dumpversion']).strip())
|
The return array should have at least two values (major, minor).
|
||||||
else:
|
"""
|
||||||
version = decode_utf8(subprocess.check_output([env['CXX'], '--version']).strip())
|
if not env.msvc:
|
||||||
match = re.search('[0-9][0-9.]*', version)
|
# Not using -dumpversion as some GCC distros only return major, and
|
||||||
|
# Clang used to return hardcoded 4.2.1: # https://reviews.llvm.org/D56803
|
||||||
|
try:
|
||||||
|
version = decode_utf8(subprocess.check_output([env.subst(env['CXX']), '--version']).strip())
|
||||||
|
except (subprocess.CalledProcessError, OSError):
|
||||||
|
print("Couldn't parse CXX environment variable to infer compiler version.")
|
||||||
|
return None
|
||||||
|
else: # TODO: Implement for MSVC
|
||||||
|
return None
|
||||||
|
match = re.search('[0-9]+\.[0-9.]+', version)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
return match.group().split('.')
|
return list(map(int, match.group().split('.')))
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -180,15 +180,14 @@ def configure(env):
|
||||||
env.Append(LINKFLAGS=['-pipe'])
|
env.Append(LINKFLAGS=['-pipe'])
|
||||||
|
|
||||||
# Check for gcc version >= 6 before adding -no-pie
|
# Check for gcc version >= 6 before adding -no-pie
|
||||||
|
version = get_compiler_version(env) or [-1, -1]
|
||||||
if using_gcc(env):
|
if using_gcc(env):
|
||||||
version = get_compiler_version(env)
|
if version[0] >= 6:
|
||||||
if version != None and version[0] >= '6':
|
|
||||||
env.Append(CCFLAGS=['-fpie'])
|
env.Append(CCFLAGS=['-fpie'])
|
||||||
env.Append(LINKFLAGS=['-no-pie'])
|
env.Append(LINKFLAGS=['-no-pie'])
|
||||||
# Do the same for clang should be fine with Clang 4 and higher
|
# Do the same for clang should be fine with Clang 4 and higher
|
||||||
if using_clang(env):
|
if using_clang(env):
|
||||||
version = get_compiler_version(env)
|
if version[0] >= 4:
|
||||||
if version != None and version[0] >= '4':
|
|
||||||
env.Append(CCFLAGS=['-fpie'])
|
env.Append(CCFLAGS=['-fpie'])
|
||||||
env.Append(LINKFLAGS=['-no-pie'])
|
env.Append(LINKFLAGS=['-no-pie'])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue