Add special casing for VS which ignores unknown arguments.
This commit is contained in:
parent
beef7cb291
commit
d4adf0983b
|
@ -1435,6 +1435,27 @@ class VisualStudioCCompiler(CCompiler):
|
|||
# msvc does not have a concept of system header dirs.
|
||||
return ['-I' + path]
|
||||
|
||||
# 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):
|
||||
warning_text = b'9002'
|
||||
code = 'int i;\n'
|
||||
(fd, srcname) = tempfile.mkstemp(suffix='.'+self.default_suffix)
|
||||
os.close(fd)
|
||||
ofile = open(srcname, 'w')
|
||||
ofile.write(code)
|
||||
ofile.close()
|
||||
commands = self.exelist + [arg] + self.get_compile_only_args() + [srcname]
|
||||
mlog.debug('Running VS compile:')
|
||||
mlog.debug('Command line: ', ' '.join(commands))
|
||||
mlog.debug('Code:\n', code)
|
||||
p = subprocess.Popen(commands, cwd=os.path.split(srcname)[0], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stde, stdo) = p.communicate()
|
||||
if p.returncode != 0:
|
||||
raise MesonException('Compiling test app failed.')
|
||||
return not(warning_text in stde or warning_text in stdo)
|
||||
|
||||
class VisualStudioCPPCompiler(VisualStudioCCompiler):
|
||||
def __init__(self, exelist, version, is_cross, exe_wrap):
|
||||
VisualStudioCCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
project('has arg', 'c')
|
||||
project('has arg', 'c', 'cpp')
|
||||
|
||||
cc = meson.get_compiler('c')
|
||||
cpp = meson.get_compiler('cpp')
|
||||
|
||||
if cc.get_id() == 'msvc'
|
||||
is_arg = '/O2'
|
||||
|
@ -15,6 +16,9 @@ isnt_arg = '-fiambroken'
|
|||
assert(cc.has_argument(is_arg), 'Arg that should have worked does not work.')
|
||||
assert(not cc.has_argument(isnt_arg), 'Arg that should be broken is not.')
|
||||
|
||||
assert(cpp.has_argument(is_arg), 'Arg that should have worked does not work.')
|
||||
assert(not cpp.has_argument(isnt_arg), 'Arg that should be broken is not.')
|
||||
|
||||
# Have useless at the end to ensure that the search goes from front to back.
|
||||
l1 = cc.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless])
|
||||
l2 = cc.first_supported_argument(isnt_arg, isnt_arg, isnt_arg)
|
||||
|
@ -22,3 +26,10 @@ l2 = cc.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.')
|
||||
|
||||
l1 = cpp.first_supported_argument([isnt_arg, is_arg, isnt_arg, useless])
|
||||
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.')
|
||||
|
|
Loading…
Reference in New Issue