Add Compiler.has_multi_arguments method.
It allows checking if a compiler supports a multi-argument option.
This commit is contained in:
parent
c42167dc6f
commit
ec47db6c0c
|
@ -425,8 +425,13 @@ class Compiler():
|
|||
def get_library_dirs(self):
|
||||
return []
|
||||
|
||||
def has_argument(self, arg):
|
||||
raise EnvironmentException('Language {} does not support has_arg.'.format(self.language))
|
||||
def has_argument(self, arg, env):
|
||||
return self.has_multi_arguments([arg], env)
|
||||
|
||||
def has_multi_arguments(self, args, env):
|
||||
raise EnvironmentException(
|
||||
'Language {} does not support has_multi_arguments.'.format(
|
||||
self.language))
|
||||
|
||||
def get_cross_extra_flags(self, environment, *, compile, link):
|
||||
extra_flags = []
|
||||
|
@ -1091,8 +1096,8 @@ void bar() {
|
|||
def thread_link_flags(self):
|
||||
return ['-pthread']
|
||||
|
||||
def has_argument(self, arg, env):
|
||||
return self.compiles('int i;\n', env, extra_args=arg)
|
||||
def has_multi_arguments(self, args, env):
|
||||
return self.compiles('int i;\n', env, extra_args=args)
|
||||
|
||||
class CPPCompiler(CCompiler):
|
||||
def __init__(self, exelist, version, is_cross, exe_wrap):
|
||||
|
@ -1926,7 +1931,7 @@ class VisualStudioCCompiler(CCompiler):
|
|||
# Visual Studio is special. It ignores arguments it does not
|
||||
# understand and you can't tell it to error out on those.
|
||||
# http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
|
||||
def has_argument(self, arg, env):
|
||||
def has_multi_arguments(self, args, env):
|
||||
warning_text = '9002'
|
||||
code = 'int i;\n'
|
||||
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
|
||||
|
@ -1936,7 +1941,7 @@ class VisualStudioCCompiler(CCompiler):
|
|||
# Read c_args/cpp_args/etc from the cross-info file (if needed)
|
||||
extra_args = self.get_cross_extra_flags(env, compile=True, link=False)
|
||||
extra_args += self.get_compile_only_args()
|
||||
commands = self.exelist + [arg] + extra_args + [srcname]
|
||||
commands = self.exelist + args + extra_args + [srcname]
|
||||
mlog.debug('Running VS compile:')
|
||||
mlog.debug('Command line: ', ' '.join(commands))
|
||||
mlog.debug('Code:\n', code)
|
||||
|
@ -2229,8 +2234,10 @@ class ClangCompiler():
|
|||
raise MesonException('Unreachable code when converting clang type to gcc type.')
|
||||
return get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, path, soversion, is_shared_module)
|
||||
|
||||
def has_argument(self, arg, env):
|
||||
return super().has_argument(['-Werror=unknown-warning-option', arg], env)
|
||||
def has_multi_arguments(self, args, env):
|
||||
return super().has_multi_arguments(
|
||||
['-Werror=unknown-warning-option'] + args,
|
||||
env)
|
||||
|
||||
def has_function(self, funcname, prefix, env, extra_args=None, dependencies=None):
|
||||
if extra_args is None:
|
||||
|
|
|
@ -621,6 +621,7 @@ class CompilerHolder(InterpreterObject):
|
|||
'cmd_array' : self.cmd_array_method,
|
||||
'find_library': self.find_library_method,
|
||||
'has_argument' : self.has_argument_method,
|
||||
'has_multi_arguments' : self.has_multi_arguments_method,
|
||||
'first_supported_argument' : self.first_supported_argument_method,
|
||||
'unittest_args' : self.unittest_args_method,
|
||||
})
|
||||
|
@ -918,6 +919,19 @@ class CompilerHolder(InterpreterObject):
|
|||
mlog.log('Compiler for {} supports argument {}:'.format(self.compiler.language, args[0]), h)
|
||||
return result
|
||||
|
||||
def has_multi_arguments_method(self, args, kwargs):
|
||||
args = mesonlib.stringlistify(args)
|
||||
result = self.compiler.has_multi_arguments(args, self.environment)
|
||||
if result:
|
||||
h = mlog.green('YES')
|
||||
else:
|
||||
h = mlog.red('NO')
|
||||
mlog.log(
|
||||
'Compiler for {} supports arguments {}:'.format(
|
||||
self.compiler.language, ' '.join(args)),
|
||||
h)
|
||||
return result
|
||||
|
||||
def first_supported_argument_method(self, args, kwargs):
|
||||
for i in mesonlib.stringlistify(args):
|
||||
if self.compiler.has_argument(i, self.environment):
|
||||
|
|
|
@ -33,3 +33,12 @@ l2 = cpp.first_supported_argument(isnt_arg, isnt_arg, isnt_arg)
|
|||
assert(l1.length() == 1, 'First supported returned wrong result.')
|
||||
assert(l1.get(0) == is_arg, 'First supported returned wrong argument.')
|
||||
assert(l2.length() == 0, 'First supported did not return empty array.')
|
||||
|
||||
if cc.get_id() == 'gcc'
|
||||
pre_arg = '-Wformat'
|
||||
anti_pre_arg = '-Wno-format'
|
||||
arg = '-Werror=format-security'
|
||||
assert(not cc.has_multi_arguments([anti_pre_arg, arg]), 'Arg that should be broken is not.')
|
||||
assert(cc.has_multi_arguments(pre_arg), 'Arg that should have worked does not work.')
|
||||
assert(cc.has_multi_arguments([pre_arg, arg]), 'Arg that should have worked does not work.')
|
||||
endif
|
||||
|
|
Loading…
Reference in New Issue