Skip to content

Commit

Permalink
add clang c_std=c18 alias
Browse files Browse the repository at this point in the history
fix unit test skips for clang c18

correct unittests clang minimum version

cleanup unittest clang skip c_std

finesse unittest vs. clang version
  • Loading branch information
scivision committed Jun 26, 2019
1 parent 41a0292 commit a9b0523
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 19 deletions.
11 changes: 7 additions & 4 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,16 @@ def get_options(self):
opts = CCompiler.get_options(self)
c_stds = ['c89', 'c99', 'c11']
g_stds = ['gnu89', 'gnu99', 'gnu11']
if self.compiler_type is CompilerType.CLANG_OSX:
v = '>=10.0.0'
else:
v = '>=7.0.0'
# https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html
# https://en.wikipedia.org/wiki/Xcode#Latest_versions
v = '>=10.0.0' if self.compiler_type is CompilerType.CLANG_OSX else '>=6.0.0'
if version_compare(self.version, v):
c_stds += ['c17']
g_stds += ['gnu17']
v = '>=11.0.0' if self.compiler_type is CompilerType.CLANG_OSX else '>=8.0.0'
if version_compare(self.version, v):
c_stds += ['c18']
g_stds += ['gnu18']
opts.update({'c_std': coredata.UserComboOption('C language standard to use',
['none'] + c_stds + g_stds,
'none')})
Expand Down
6 changes: 3 additions & 3 deletions mesonbuild/mesonlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def __cmp(self, other, comparator):
# otherwise, the version with a suffix remaining is greater
return comparator(len(self._v), len(other._v))

def _version_extract_cmpop(vstr2):
def _version_extract_cmpop(vstr2: str) -> tuple:
if vstr2.startswith('>='):
cmpop = operator.ge
vstr2 = vstr2[2:]
Expand All @@ -601,7 +601,7 @@ def _version_extract_cmpop(vstr2):

return (cmpop, vstr2)

def version_compare(vstr1, vstr2):
def version_compare(vstr1: str, vstr2: str) -> bool:
(cmpop, vstr2) = _version_extract_cmpop(vstr2)
return cmpop(Version(vstr1), Version(vstr2))

Expand All @@ -619,7 +619,7 @@ def version_compare_many(vstr1, conditions):

# determine if the minimum version satisfying the condition |condition| exceeds
# the minimum version for a feature |minimum|
def version_compare_condition_with_min(condition, minimum):
def version_compare_condition_with_min(condition, minimum) -> bool:
if condition.startswith('>='):
cmpop = operator.le
condition = condition[2:]
Expand Down
48 changes: 36 additions & 12 deletions run_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4472,19 +4472,43 @@ def test_compiler_check_flags_order(self):

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
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'))))
# 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:
if (compiler.get_id() == 'clang' and '17' in v and
(version_compare(compiler.version, '<5.0.0') or
(compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
continue
if (compiler.get_id() == 'clang' and '2a' in v and
(version_compare(compiler.version, '<6.0.0') or
(compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
continue
if (compiler.get_id() == 'gcc' and '2a' in v and version_compare(compiler.version, '<8.0.0')):
continue
# 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
# 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
std_opt = '{}={}'.format(lang_std, v)
self.init(testdir, ['-D' + std_opt])
cmd = self.get_compdb()[0]['command']
Expand Down

0 comments on commit a9b0523

Please sign in to comment.