Skip to content

Commit

Permalink
cleanup clang version minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
scivision committed Jul 8, 2019
1 parent 9c6d135 commit 0f77ef0
Showing 1 changed file with 51 additions and 31 deletions.
82 changes: 51 additions & 31 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ class PatchModule:
Fancy monkey-patching! Whee! Can't use mock.patch because it only
patches in the local namespace.
'''

def __init__(self, func, name, impl):
self.func = func
assert(isinstance(name, str))
Expand Down Expand Up @@ -1455,6 +1456,7 @@ class AllPlatformTests(BasePlatformTests):
'''
Tests that should run on all platforms
'''

def test_default_options_prefix(self):
'''
Tests that setting a prefix in default_options in project() works.
Expand Down Expand Up @@ -4005,6 +4007,7 @@ class WindowsTests(BasePlatformTests):
'''
Tests that should run on Cygwin, MinGW, and MSVC
'''

def setUp(self):
super().setUp()
self.platform_test_dir = os.path.join(self.src_root, 'test cases/windows')
Expand Down Expand Up @@ -4119,6 +4122,7 @@ class DarwinTests(BasePlatformTests):
'''
Tests that should run on macOS
'''

def setUp(self):
super().setUp()
self.platform_test_dir = os.path.join(self.src_root, 'test cases/osx')
Expand Down Expand Up @@ -4219,6 +4223,7 @@ class LinuxlikeTests(BasePlatformTests):
'''
Tests that should run on Linux, macOS, and *BSD
'''

def test_basic_soname(self):
'''
Test that the soname is set correctly for shared libraries. This can't
Expand Down Expand Up @@ -4506,45 +4511,33 @@ def test_compiler_check_flags_order(self):
Oargs = [arg for arg in cmd if arg.startswith('-O')]
self.assertEqual(Oargs, [Oflag, '-O0'])

def _test_stds_impl(self, testdir, compiler, p):
def _test_stds_impl(self, testdir, compiler, p: str):
lang_std = p + '_std'
clangLT5 = (compiler.get_id() == 'clang' and
(version_compare(compiler.version, '<5.0.0') or
(compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<9.1'))))
clangLT6 = (compiler.get_id() == 'clang' and
(version_compare(compiler.version, '<6.0.0') or
(compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<10.0'))))
clangLT8 = (compiler.get_id() == 'clang' and
(version_compare(compiler.version, '<8.0.0') or
(compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<11.0'))))

has_cpp17 = (compiler.get_Id() not in {'clang', 'gcc'} or
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=5.0.0', '>=9.1') or
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=5.0.0'))
has_cpp2a_c17 = (compiler.get_Id() not in {'clang', 'gcc'} or
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=6.0.0', '>=10.0') or
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=8.0.0'))
has_c18 = (compiler.get_Id() not in {'clang', 'gcc'} or
compiler.get_id() == 'clang' and _clang_at_least(compiler, '>=8.0.0', '>=11.0') or
compiler.get_id() == 'gcc' and version_compare(compiler.version, '>=8.0.0'))
# Check that all the listed -std=xxx options for this compiler work just fine when used
# https://en.wikipedia.org/wiki/Xcode#Latest_versions
# https://www.gnu.org/software/gcc/projects/cxx-status.html
for v in compiler.get_options()[lang_std].choices:
# we do it like this to handle gnu++17,c++17 and gnu17,c17 cleanly
# thus, C++ first
if '++17' in v:
if clangLT5:
continue
if compiler.get_id() == 'gcc' and version_compare(compiler.version, '<5.0.0'):
continue
elif '++2a' in v:
# https://en.cppreference.com/w/cpp/compiler_support
if clangLT6:
continue
if compiler.get_id() == 'gcc' and version_compare(compiler.version, '<8.0.0'):
continue
if '++17' in v and not has_cpp17:
continue
elif '++2a' in v and not has_cpp2a_c17: # https://en.cppreference.com/w/cpp/compiler_support
continue
# now C
elif '17' in v:
if clangLT6:
continue
if compiler.get_id() == 'gcc' and version_compare(compiler.version, '<8.0.0'):
continue
elif '18' in v:
if clangLT8:
continue
if compiler.get_id() == 'gcc' and version_compare(compiler.version, '<8.0.0'):
continue
elif '17' in v and not has_cpp2a_c17:
continue
elif '18' in v and not has_c18:
continue
std_opt = '{}={}'.format(lang_std, v)
self.init(testdir, ['-D' + std_opt])
cmd = self.get_compdb()[0]['command']
Expand Down Expand Up @@ -5290,6 +5283,7 @@ class LinuxCrossArmTests(BasePlatformTests):
'''
Tests that cross-compilation to Linux/ARM works
'''

def setUp(self):
super().setUp()
src_root = os.path.dirname(__file__)
Expand Down Expand Up @@ -5350,6 +5344,7 @@ class LinuxCrossMingwTests(BasePlatformTests):
'''
Tests that cross-compilation to Windows/MinGW works
'''

def setUp(self):
super().setUp()
src_root = os.path.dirname(__file__)
Expand Down Expand Up @@ -5398,6 +5393,7 @@ class PythonTests(BasePlatformTests):
'''
Tests that verify compilation of python extension modules
'''

def test_versions(self):
if self.backend is not Backend.ninja:
raise unittest.SkipTest('Skipping python tests with {} backend'.format(self.backend.name))
Expand Down Expand Up @@ -6442,6 +6438,30 @@ def test_yaml(self):
self.assert_test(events, number=2, name='', result=TestResult.FAIL)
self.assert_last(events)


def _clang_at_least(compiler, minver: str, apple_minver: str) -> bool:
"""
check that Clang compiler is at least a specified version, whether AppleClang or regular Clang
Parameters
----------
compiler:
Meson compiler object
minver: str
Clang minimum version
apple_minver: str
AppleCLang minimum version
Returns
-------
at_least: bool
Clang is at least the specified version
"""
if compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX:
return version_compare(compiler.version, apple_minver)
return version_compare(compiler.version, minver)


def unset_envs():
# For unit tests we must fully control all command lines
# so that there are no unexpected changes coming from the
Expand Down

0 comments on commit 0f77ef0

Please sign in to comment.