icc: Fix C/C++ std options and add a unit test for them

Compiler versions 15.0 and later actually ignore invalid values for the
-std= option unless `-diag-error 10159` is passed, so we need to put
that in the unit test.

I have tested this with versions 14.0.3, 15.0.6, 16.0.4, and 17.0.1.
Would be great if someone could test with 13.x.y
pull/1253/head
Nirbheek Chauhan 8 years ago
parent e36183aab4
commit 731aca216e
  1. 37
      mesonbuild/compilers.py
  2. 67
      run_unittests.py
  3. 5
      test cases/common/1 trivial/meson.build
  4. 6
      test cases/common/2 cpp/meson.build

@ -2448,9 +2448,12 @@ class IntelCCompiler(IntelCompiler, CCompiler):
'3': ['-Wall', '-w3', '-diag-disable:remark', '-Wpedantic', '-Wextra', '-Wpch-messages']}
def get_options(self):
c_stds = ['c89', 'c99']
g_stds = ['gnu89', 'gnu99']
if mesonlib.version_compare(self.version, '>=16.0.0'):
c_stds += ['c11']
opts = {'c_std': coredata.UserComboOption('c_std', 'C language standard to use',
['none', 'c89', 'c99',
'gnu89', 'gnu99'],
['none'] + c_stds + g_stds,
'none')}
return opts
@ -2469,6 +2472,7 @@ class IntelCCompiler(IntelCompiler, CCompiler):
class IntelCPPCompiler(IntelCompiler, CPPCompiler):
def __init__(self, exelist, version, icc_type, is_cross, exe_wrap):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap)
IntelCompiler.__init__(self, icc_type)
@ -2477,22 +2481,21 @@ class IntelCPPCompiler(IntelCompiler, CPPCompiler):
'3': ['-Wall', '-w3', '-diag-disable:remark', '-Wpedantic', '-Wextra', '-Wpch-messages', '-Wnon-virtual-dtor']}
def get_options(self):
c_stds = []
g_stds = ['gnu++98']
if mesonlib.version_compare(self.version, '>=15.0.0'):
c_stds += ['c++11', 'c++14']
g_stds += ['gnu++11']
if mesonlib.version_compare(self.version, '>=16.0.0'):
c_stds += ['c++17']
if mesonlib.version_compare(self.version, '>=17.0.0'):
opts = {'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
['none', 'c++11', 'c++0x', 'c++14',
'gnu++98', 'gnu++11', 'gnu++0x', 'gnu++14'],
'none'),
'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl',
'STL debug mode',
False)}
else:
opts = {'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
['none', 'c++03', 'c++11', 'c++0x',
'gnu++98', 'gnu++03', 'gnu++11', 'gnu++0x'],
'none'),
'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl',
'STL debug mode',
False)}
g_stds += ['gnu++14']
opts = {'cpp_std': coredata.UserComboOption('cpp_std', 'C++ language standard to use',
['none'] + c_stds + g_stds,
'none'),
'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl',
'STL debug mode',
False)}
return opts
def get_option_compile_args(self, options):

@ -19,7 +19,7 @@ import re, json
import tempfile
from glob import glob
import mesonbuild.environment
from mesonbuild.environment import detect_ninja
from mesonbuild.environment import detect_ninja, Environment
from mesonbuild.dependencies import PkgConfigDependency
def get_soname(fname):
@ -33,6 +33,12 @@ def get_soname(fname):
return m.group(1)
raise RuntimeError('Could not determine soname:\n\n' + raw_out)
def get_fake_options():
import argparse
opts = argparse.Namespace()
opts.cross_file = None
return opts
class FakeEnvironment(object):
def __init__(self):
self.cross_info = None
@ -81,11 +87,13 @@ class LinuxlikeTests(unittest.TestCase):
def _run(self, command):
self.output += subprocess.check_output(command, env=os.environ.copy())
def init(self, srcdir):
def init(self, srcdir, extra_args=None):
if extra_args is None:
extra_args = []
args = [srcdir, self.builddir,
'--prefix', self.prefix,
'--libdir', self.libdir]
self._run(self.meson_command + args)
self._run(self.meson_command + args + extra_args)
self.privatedir = os.path.join(self.builddir, 'meson-private')
def build(self):
@ -410,6 +418,59 @@ class LinuxlikeTests(unittest.TestCase):
self.assertTrue('TEST_ENV is set' in vg_log)
self.assertTrue('Memcheck' in vg_log)
def _test_stds_impl(self, testdir, compiler, p):
lang_std = p + '_std'
# Check that all the listed -std=xxx options for this compiler work
# just fine when used
for v in compiler.get_options()[lang_std].choices:
std_opt = '{}={}'.format(lang_std, v)
self.init(testdir, ['-D' + std_opt])
cmd = self.get_compdb()[0]['command']
if v != 'none':
cmd_std = "'-std={}'".format(v)
self.assertIn(cmd_std, cmd)
try:
self.build()
except:
print('{} was {!r}'.format(lang_std, v))
raise
self.wipe()
# Check that an invalid std option in CFLAGS/CPPFLAGS fails
# Needed because by default ICC ignores invalid options
cmd_std = '-std=FAIL'
env_flags = p.upper() + 'FLAGS'
os.environ[env_flags] = cmd_std
self.init(testdir)
cmd = self.get_compdb()[0]['command']
qcmd_std = "'{}'".format(cmd_std)
self.assertIn(qcmd_std, cmd)
with self.assertRaises(subprocess.CalledProcessError,
msg='{} should have failed'.format(qcmd_std)):
self.build()
def test_compiler_c_stds(self):
'''
Test that C stds specified for this compiler can all be used. Can't be
an ordinary test because it requires passing options to meson.
'''
testdir = os.path.join(self.common_test_dir, '1 trivial')
env = Environment(testdir, self.builddir, self.meson_command,
get_fake_options(), [])
cc = env.detect_c_compiler(False)
self._test_stds_impl(testdir, cc, 'c')
def test_compiler_cpp_stds(self):
'''
Test that C++ stds specified for this compiler can all be used. Can't
be an ordinary test because it requires passing options to meson.
'''
testdir = os.path.join(self.common_test_dir, '2 cpp')
env = Environment(testdir, self.builddir, self.meson_command,
get_fake_options(), [])
cpp = env.detect_cpp_compiler(False)
self._test_stds_impl(testdir, cpp, 'cpp')
class RewriterTests(unittest.TestCase):
def setUp(self):

@ -6,6 +6,11 @@ project('trivial test',
#this is a comment
sources = 'trivial.c'
if meson.get_compiler('c').get_id() == 'intel'
# Error out if the -std=xxx option is incorrect
add_project_arguments('-diag-error', '10159', language : 'c')
endif
exe = executable('trivialprog', sources : sources)
test('runtest', exe) # This is a comment

@ -1,3 +1,9 @@
project('c++ test', 'cpp')
if meson.get_compiler('cpp').get_id() == 'intel'
# Error out if the -std=xxx option is incorrect
add_project_arguments('-diag-error', '10159', language : 'cpp')
endif
exe = executable('trivialprog', 'trivial.cc', extra_files : 'something.txt')
test('runtest', exe)

Loading…
Cancel
Save