Factor out lookup of sconf overrides
This commit is contained in:
parent
b5bf4cf9cc
commit
3bf0c93067
43
SConstruct
43
SConstruct
|
@ -74,8 +74,9 @@ class ConfigureTests:
|
||||||
class Collector:
|
class Collector:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.tests = []
|
self.tests = []
|
||||||
|
self.record = self.tests.append
|
||||||
def __call__(self,f):
|
def __call__(self,f):
|
||||||
self.tests.append(f.__name__)
|
self.record(f.__name__)
|
||||||
return f
|
return f
|
||||||
class Cxx11RequiredFeature:
|
class Cxx11RequiredFeature:
|
||||||
def __init__(self,name,text,main=''):
|
def __init__(self,name,text,main=''):
|
||||||
|
@ -269,7 +270,20 @@ struct %(N)s_derived : %(N)s_base {
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _quote_macro_value(v):
|
def _quote_macro_value(v):
|
||||||
return v.strip().replace('\n', ' \\\n')
|
return v.strip().replace('\n', ' \\\n')
|
||||||
def _check_forced(self,context,name):
|
def _check_sconf_forced(self,calling_function):
|
||||||
|
if calling_function is not None:
|
||||||
|
return self._check_forced(calling_function)
|
||||||
|
try:
|
||||||
|
1//0
|
||||||
|
except ZeroDivisionError:
|
||||||
|
frame = sys.exc_info()[2].tb_frame.f_back.f_back
|
||||||
|
while frame is not None:
|
||||||
|
co_name = frame.f_code.co_name
|
||||||
|
if co_name[:6] == 'check_':
|
||||||
|
return self._check_forced(co_name[6:])
|
||||||
|
frame = frame.f_back
|
||||||
|
assert False
|
||||||
|
def _check_forced(self,name):
|
||||||
return getattr(self.user_settings, 'sconf_%s' % name)
|
return getattr(self.user_settings, 'sconf_%s' % name)
|
||||||
def _check_macro(self,context,macro_name,macro_value,test,**kwargs):
|
def _check_macro(self,context,macro_name,macro_value,test,**kwargs):
|
||||||
macro_value = self._quote_macro_value(macro_value)
|
macro_value = self._quote_macro_value(macro_value)
|
||||||
|
@ -294,7 +308,7 @@ struct %(N)s_derived : %(N)s_base {
|
||||||
return self._Test(context,action=context.TryCompile, **kwargs)
|
return self._Test(context,action=context.TryCompile, **kwargs)
|
||||||
def Link(self,context,**kwargs):
|
def Link(self,context,**kwargs):
|
||||||
return self._Test(context,action=context.TryLink, **kwargs)
|
return self._Test(context,action=context.TryLink, **kwargs)
|
||||||
def _Test(self,context,text,msg,action,main='',ext='.cpp',testflags={},successflags={},skipped=None,successmsg=None,failuremsg=None,expect_failure=False):
|
def _Test(self,context,text,msg,action,main='',ext='.cpp',testflags={},successflags={},skipped=None,successmsg=None,failuremsg=None,expect_failure=False,calling_function=None):
|
||||||
self._check_compiler_works(context,ext)
|
self._check_compiler_works(context,ext)
|
||||||
context.Message('%s: checking %s...' % (self.msgprefix, msg))
|
context.Message('%s: checking %s...' % (self.msgprefix, msg))
|
||||||
if skipped is not None:
|
if skipped is not None:
|
||||||
|
@ -302,18 +316,7 @@ struct %(N)s_derived : %(N)s_base {
|
||||||
return
|
return
|
||||||
env_flags = self.PreservedEnvironment(context.env, successflags.keys() + testflags.keys() + self.__flags_Werror.keys() + ['CPPDEFINES'])
|
env_flags = self.PreservedEnvironment(context.env, successflags.keys() + testflags.keys() + self.__flags_Werror.keys() + ['CPPDEFINES'])
|
||||||
context.env.MergeFlags(successflags)
|
context.env.MergeFlags(successflags)
|
||||||
frame = None
|
forced = self._check_sconf_forced(calling_function)
|
||||||
forced = None
|
|
||||||
try:
|
|
||||||
1//0
|
|
||||||
except ZeroDivisionError:
|
|
||||||
frame = sys.exc_info()[2].tb_frame.f_back
|
|
||||||
while frame is not None:
|
|
||||||
co_name = frame.f_code.co_name
|
|
||||||
if co_name[0:6] == 'check_':
|
|
||||||
forced = self._check_forced(context, co_name[6:])
|
|
||||||
break
|
|
||||||
frame = frame.f_back
|
|
||||||
caller_modified_env_flags = self.PreservedEnvironment(context.env, self.__flags_Werror.keys() + testflags.keys())
|
caller_modified_env_flags = self.PreservedEnvironment(context.env, self.__flags_Werror.keys() + testflags.keys())
|
||||||
# Always pass -Werror
|
# Always pass -Werror
|
||||||
context.env.Append(**self.__flags_Werror)
|
context.env.Append(**self.__flags_Werror)
|
||||||
|
@ -1215,12 +1218,14 @@ help:always wipe certain freed memory
|
||||||
|
|
||||||
def add_compiler_option_tests():
|
def add_compiler_option_tests():
|
||||||
def define_compiler_option_test(opt, doc=None):
|
def define_compiler_option_test(opt, doc=None):
|
||||||
|
n = 'compiler_option' + opt.replace('-', '_').replace('=', '_')
|
||||||
def f(self, context):
|
def f(self, context):
|
||||||
self.Compile(context, text='', main='', msg='whether compiler accepts ' + opt, successflags={'CXXFLAGS' : [opt]})
|
self.Compile(context, text='', main='', msg='whether compiler accepts ' + opt, successflags={'CXXFLAGS' : [opt]}, calling_function=n)
|
||||||
f.__name__ = n = 'check_compiler_option' + opt.replace('-', '_').replace('=', '')
|
cn = 'check_' + n
|
||||||
|
custom_tests(cn)
|
||||||
f.__doc__ = doc or ('\nhelp:assume compiler accepts ' + opt + '\n')
|
f.__doc__ = doc or ('\nhelp:assume compiler accepts ' + opt + '\n')
|
||||||
setattr(ConfigureTests, n, custom_tests(f))
|
setattr(ConfigureTests, cn, f)
|
||||||
custom_tests = ConfigureTests._custom_test
|
custom_tests = ConfigureTests._custom_test.record
|
||||||
for opt in (
|
for opt in (
|
||||||
('-fvisibility=hidden',),
|
('-fvisibility=hidden',),
|
||||||
('-Wsuggest-attribute=noreturn',),
|
('-Wsuggest-attribute=noreturn',),
|
||||||
|
|
Loading…
Reference in a new issue