Can set extra args to all compilation checks.
This commit is contained in:
parent
2056426b47
commit
f16986e31b
54
compilers.py
54
compilers.py
|
@ -150,25 +150,25 @@ class Compiler():
|
|||
def get_option_link_args(self, options):
|
||||
return []
|
||||
|
||||
def has_header(self, hname):
|
||||
def has_header(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support header checks.' % self.language)
|
||||
|
||||
def compiles(self, code):
|
||||
def compiles(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support compile checks.' % self.language)
|
||||
|
||||
def links(self, code):
|
||||
def links(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support link checks.' % self.language)
|
||||
|
||||
def run(self, code):
|
||||
def run(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support run checks.' % self.language)
|
||||
|
||||
def sizeof(self, element, prefix, env):
|
||||
def sizeof(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support sizeof checks.' % self.language)
|
||||
|
||||
def alignment(self, typename, env):
|
||||
def alignment(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support alignment checks.' % self.language)
|
||||
|
||||
def has_function(self, funcname, prefix, env):
|
||||
def has_function(self, *args, **kwargs):
|
||||
raise EnvironmentException('Language %s does not support function checks.' % self.language)
|
||||
|
||||
class CCompiler(Compiler):
|
||||
|
@ -310,11 +310,11 @@ class CCompiler(Compiler):
|
|||
if pe.returncode != 0:
|
||||
raise EnvironmentException('Executables created by C compiler %s are not runnable.' % self.name_string())
|
||||
|
||||
def has_header(self, hname):
|
||||
def has_header(self, hname, extra_args=[]):
|
||||
templ = '''#include<%s>
|
||||
int someSymbolHereJustForFun;
|
||||
'''
|
||||
return self.compiles(templ % hname)
|
||||
return self.compiles(templ % hname, extra_args)
|
||||
|
||||
def compile(self, code, srcname, extra_args=[]):
|
||||
commands = self.get_exelist()
|
||||
|
@ -369,7 +369,7 @@ int someSymbolHereJustForFun;
|
|||
pass
|
||||
return p.returncode == 0
|
||||
|
||||
def run(self, code):
|
||||
def run(self, code, extra_args=[]):
|
||||
mlog.debug('Running code:\n\n', code)
|
||||
if self.is_cross and self.exe_wrapper is None:
|
||||
raise CrossNoRunException('Can not run test applications in this cross environment.')
|
||||
|
@ -380,6 +380,7 @@ int someSymbolHereJustForFun;
|
|||
ofile.close()
|
||||
exename = srcname + '.exe' # Is guaranteed to be executable on every platform.
|
||||
commands = self.get_exelist()
|
||||
commands += extra_args
|
||||
commands.append(srcname)
|
||||
commands += self.get_output_args(exename)
|
||||
p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
@ -404,13 +405,12 @@ int someSymbolHereJustForFun;
|
|||
os.remove(exename)
|
||||
return RunResult(True, pe.returncode, so, se)
|
||||
|
||||
def cross_sizeof(self, element, prefix, env):
|
||||
def cross_sizeof(self, element, prefix, env, extra_args=[]):
|
||||
templ = '''%s
|
||||
int temparray[%d-sizeof(%s)];
|
||||
'''
|
||||
extra_args = []
|
||||
try:
|
||||
extra_args = env.cross_info.config['properties'][self.language + '_args']
|
||||
extra_args += env.cross_info.config['properties'][self.language + '_args']
|
||||
except KeyError:
|
||||
pass
|
||||
for i in range(1, 1024):
|
||||
|
@ -419,9 +419,9 @@ int temparray[%d-sizeof(%s)];
|
|||
return i
|
||||
raise EnvironmentException('Cross checking sizeof overflowed.')
|
||||
|
||||
def sizeof(self, element, prefix, env):
|
||||
def sizeof(self, element, prefix, env, extra_args=[]):
|
||||
if self.is_cross:
|
||||
return self.cross_sizeof(element, prefix, env)
|
||||
return self.cross_sizeof(element, prefix, env, extra_args)
|
||||
templ = '''#include<stdio.h>
|
||||
%s
|
||||
|
||||
|
@ -430,14 +430,14 @@ int main(int argc, char **argv) {
|
|||
return 0;
|
||||
};
|
||||
'''
|
||||
res = self.run(templ % (prefix, element))
|
||||
res = self.run(templ % (prefix, element), extra_args)
|
||||
if not res.compiled:
|
||||
raise EnvironmentException('Could not compile sizeof test.')
|
||||
if res.returncode != 0:
|
||||
raise EnvironmentException('Could not run sizeof test binary.')
|
||||
return int(res.stdout)
|
||||
|
||||
def cross_alignment(self, typename, env):
|
||||
def cross_alignment(self, typename, env, extra_args=[]):
|
||||
templ = '''#include<stddef.h>
|
||||
struct tmp {
|
||||
char c;
|
||||
|
@ -447,7 +447,7 @@ struct tmp {
|
|||
int testarray[%d-offsetof(struct tmp, target)];
|
||||
'''
|
||||
try:
|
||||
extra_args = env.cross_info.config['properties'][self.language + '_args']
|
||||
extra_args += env.cross_info.config['properties'][self.language + '_args']
|
||||
except KeyError:
|
||||
pass
|
||||
for i in range(1, 1024):
|
||||
|
@ -456,9 +456,9 @@ int testarray[%d-offsetof(struct tmp, target)];
|
|||
return i
|
||||
raise EnvironmentException('Cross checking offsetof overflowed.')
|
||||
|
||||
def alignment(self, typename, env):
|
||||
def alignment(self, typename, env, extra_args=[]):
|
||||
if self.is_cross:
|
||||
return self.cross_alignment(typename, env)
|
||||
return self.cross_alignment(typename, env, extra_args)
|
||||
templ = '''#include<stdio.h>
|
||||
#include<stddef.h>
|
||||
|
||||
|
@ -472,7 +472,7 @@ int main(int argc, char **argv) {
|
|||
return 0;
|
||||
}
|
||||
'''
|
||||
res = self.run(templ % typename)
|
||||
res = self.run(templ % typename, extra_args)
|
||||
if not res.compiled:
|
||||
raise EnvironmentException('Could not compile alignment test.')
|
||||
if res.returncode != 0:
|
||||
|
@ -482,7 +482,7 @@ int main(int argc, char **argv) {
|
|||
raise EnvironmentException('Could not determine alignment of %s. Sorry. You might want to file a bug.' % typename)
|
||||
return align
|
||||
|
||||
def has_function(self, funcname, prefix, env):
|
||||
def has_function(self, funcname, prefix, env, extra_args=[]):
|
||||
# This fails (returns true) if funcname is a ptr or a variable.
|
||||
# The correct check is a lot more difficult.
|
||||
# Fix this to do that eventually.
|
||||
|
@ -500,24 +500,24 @@ int main(int argc, char **argv) {
|
|||
if isinstance(val, bool):
|
||||
return val
|
||||
raise EnvironmentException('Cross variable {0} is not a boolean.'.format(varname))
|
||||
return self.compiles(templ % (prefix, funcname))
|
||||
return self.compiles(templ % (prefix, funcname), extra_args)
|
||||
|
||||
def has_member(self, typename, membername, prefix):
|
||||
def has_member(self, typename, membername, prefix, extra_args=[]):
|
||||
templ = '''%s
|
||||
void bar() {
|
||||
%s foo;
|
||||
foo.%s;
|
||||
};
|
||||
'''
|
||||
return self.compiles(templ % (prefix, typename, membername))
|
||||
return self.compiles(templ % (prefix, typename, membername), extra_args)
|
||||
|
||||
def has_type(self, typename, prefix):
|
||||
def has_type(self, typename, prefix, extra_args):
|
||||
templ = '''%s
|
||||
void bar() {
|
||||
sizeof(%s);
|
||||
};
|
||||
'''
|
||||
return self.compiles(templ % (prefix, typename))
|
||||
return self.compiles(templ % (prefix, typename), extra_args)
|
||||
|
||||
def thread_flags(self):
|
||||
return ['-pthread']
|
||||
|
|
|
@ -588,7 +588,8 @@ class CompilerHolder(InterpreterObject):
|
|||
raise InterpreterException('Alignment method takes exactly one positional argument.')
|
||||
check_stringlist(args)
|
||||
typename = args[0]
|
||||
result = self.compiler.alignment(typename, self.environment)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.alignment(typename, self.environment, extra_args)
|
||||
mlog.log('Checking for alignment of "', mlog.bold(typename), '": ', result, sep='')
|
||||
return result
|
||||
|
||||
|
@ -600,7 +601,8 @@ class CompilerHolder(InterpreterObject):
|
|||
testname = kwargs.get('name', '')
|
||||
if not isinstance(testname, str):
|
||||
raise InterpreterException('Testname argument must be a string.')
|
||||
result = self.compiler.run(code)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.run(code, extra_args)
|
||||
if len(testname) > 0:
|
||||
if not result.compiled:
|
||||
h = mlog.red('DID NOT COMPILE')
|
||||
|
@ -623,7 +625,8 @@ class CompilerHolder(InterpreterObject):
|
|||
prefix = kwargs.get('prefix', '')
|
||||
if not isinstance(prefix, str):
|
||||
raise InterpreterException('Prefix argument of has_function must be a string.')
|
||||
had = self.compiler.has_member(typename, membername, prefix)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
had = self.compiler.has_member(typename, membername, prefix, extra_args)
|
||||
if had:
|
||||
hadtxt = mlog.green('YES')
|
||||
else:
|
||||
|
@ -640,7 +643,8 @@ class CompilerHolder(InterpreterObject):
|
|||
prefix = kwargs.get('prefix', '')
|
||||
if not isinstance(prefix, str):
|
||||
raise InterpreterException('Prefix argument of has_function must be a string.')
|
||||
had = self.compiler.has_function(funcname, prefix, self.environment)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
had = self.compiler.has_function(funcname, prefix, self.environment, extra_args)
|
||||
if had:
|
||||
hadtxt = mlog.green('YES')
|
||||
else:
|
||||
|
@ -656,7 +660,8 @@ class CompilerHolder(InterpreterObject):
|
|||
prefix = kwargs.get('prefix', '')
|
||||
if not isinstance(prefix, str):
|
||||
raise InterpreterException('Prefix argument of has_type must be a string.')
|
||||
had = self.compiler.has_type(typename, prefix)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
had = self.compiler.has_type(typename, prefix, extra_args)
|
||||
if had:
|
||||
hadtxt = mlog.green('YES')
|
||||
else:
|
||||
|
@ -672,7 +677,8 @@ class CompilerHolder(InterpreterObject):
|
|||
prefix = kwargs.get('prefix', '')
|
||||
if not isinstance(prefix, str):
|
||||
raise InterpreterException('Prefix argument of sizeof must be a string.')
|
||||
esize = self.compiler.sizeof(element, prefix, self.environment)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
esize = self.compiler.sizeof(element, prefix, self.environment, extra_args)
|
||||
mlog.log('Checking for size of "%s": %d' % (element, esize))
|
||||
return esize
|
||||
|
||||
|
@ -684,8 +690,8 @@ class CompilerHolder(InterpreterObject):
|
|||
testname = kwargs.get('name', '')
|
||||
if not isinstance(testname, str):
|
||||
raise InterpreterException('Testname argument must be a string.')
|
||||
args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.compiles(code, args)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.compiles(code, extra_args)
|
||||
if len(testname) > 0:
|
||||
if result:
|
||||
h = mlog.green('YES')
|
||||
|
@ -702,8 +708,8 @@ class CompilerHolder(InterpreterObject):
|
|||
testname = kwargs.get('name', '')
|
||||
if not isinstance(testname, str):
|
||||
raise InterpreterException('Testname argument must be a string.')
|
||||
args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.links(code, args)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
result = self.compiler.links(code, extra_args)
|
||||
if len(testname) > 0:
|
||||
if result:
|
||||
h = mlog.green('YES')
|
||||
|
@ -717,7 +723,8 @@ class CompilerHolder(InterpreterObject):
|
|||
raise InterpreterException('has_header method takes exactly one argument.')
|
||||
check_stringlist(args)
|
||||
string = args[0]
|
||||
haz = self.compiler.has_header(string)
|
||||
extra_args = mesonlib.stringlistify(kwargs.get('args', []))
|
||||
haz = self.compiler.has_header(string, extra_args)
|
||||
if haz:
|
||||
h = mlog.green('YES')
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue