aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-17 12:02:07 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-09-24 12:14:13 -0700
commit48a181866f9cb574d13f59f8d94983a1bc2f88ed (patch)
treeb4a9ffcc6e168201b9db7ac40ebf811546d71bfd
parent4b52184dc688706e529cf038c1724be7e8951b1c (diff)
downloadmeson-48a181866f9cb574d13f59f8d94983a1bc2f88ed.zip
meson-48a181866f9cb574d13f59f8d94983a1bc2f88ed.tar.gz
meson-48a181866f9cb574d13f59f8d94983a1bc2f88ed.tar.bz2
compilers/mixins/clang: Make type safe
-rw-r--r--mesonbuild/compilers/compilers.py8
-rw-r--r--mesonbuild/compilers/mixins/clang.py21
-rwxr-xr-xrun_mypy.py1
3 files changed, 25 insertions, 5 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index edd1c5d..2f26002 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -1032,6 +1032,14 @@ class Compiler(metaclass=abc.ABCMeta):
def attribute_check_func(self, name: str) -> str:
raise EnvironmentException('{} does not support attribute checks'.format(self.id))
+ def get_pch_suffix(self) -> str:
+ raise EnvironmentException('{} does not support pre compiled headers'.format(self.id))
+
+ def get_pch_name(self, name: str) -> str:
+ raise EnvironmentException('{} does not support pre compiled headers'.format(self.id))
+
+ def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:
+ raise EnvironmentException('{} does not support pre compiled headers'.format(self.id))
def get_args_from_envvars(lang: str,
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 7525c12..8d80751 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -23,8 +23,10 @@ from ...linkers import AppleDynamicLinker
from .gnu import GnuLikeCompiler
if T.TYPE_CHECKING:
+ from ...envconfig import MachineChoice
from ...environment import Environment
from ...dependencies import Dependency # noqa: F401
+ from ...linkers import AppleDynamicLinker
clang_color_args = {
'auto': ['-Xclang', '-fcolor-diagnostics'],
@@ -42,6 +44,12 @@ clang_optimization_args = {
} # type: T.Dict[str, T.List[str]]
class ClangCompiler(GnuLikeCompiler):
+
+ if T.TYPE_CHECKING:
+ linker = AppleDynamicLinker([], MachineChoice.HOST, '', [])
+
+ def get_pch_name(self, name: str) -> str: ...
+
def __init__(self, defines: T.Optional[T.Dict[str, str]]):
super().__init__()
self.id = 'clang'
@@ -79,13 +87,14 @@ class ClangCompiler(GnuLikeCompiler):
myargs = ['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument']
if mesonlib.version_compare(self.version, '>=3.6.0'):
myargs.append('-Werror=ignored-optimization-argument')
- return super().has_multi_arguments(
+ # Mypy doesn't understand co-coperative inheritance
+ return super().has_multi_arguments( # type: ignore
myargs + args,
env)
def has_function(self, funcname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
- dependencies: T.Optional[T.List['Dependency']] = None) -> bool:
+ dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
if extra_args is None:
extra_args = []
# Starting with XCode 8, we need to pass this to force linker
@@ -95,8 +104,10 @@ class ClangCompiler(GnuLikeCompiler):
# TODO: this really should be communicated by the linker
if isinstance(self.linker, AppleDynamicLinker) and mesonlib.version_compare(self.version, '>=8.0'):
extra_args.append('-Wl,-no_weak_imports')
- return super().has_function(funcname, prefix, env, extra_args=extra_args,
- dependencies=dependencies)
+ # Mypy doesn't understand co-coperative inheritance
+ ret = super().has_function(funcname, prefix, env, extra_args=extra_args, # type: ignore
+ dependencies=dependencies)
+ return T.cast(T.Tuple[bool, bool], ret)
def openmp_flags(self) -> T.List[str]:
if mesonlib.version_compare(self.version, '>=3.8.0'):
@@ -125,7 +136,7 @@ class ClangCompiler(GnuLikeCompiler):
return ['-fuse-ld={}'.format(linker)]
return super().use_linker_args(linker)
- def get_has_func_attribute_extra_args(self, name):
+ def get_has_func_attribute_extra_args(self, name: str) -> T.List[str]:
# Clang only warns about unknown or ignored attributes, so force an
# error.
return ['-Werror=attributes']
diff --git a/run_mypy.py b/run_mypy.py
index a502a1e..92570bc 100755
--- a/run_mypy.py
+++ b/run_mypy.py
@@ -18,6 +18,7 @@ modules = [
'mesonbuild/compilers/mixins/arm.py',
'mesonbuild/compilers/mixins/c2000.py',
'mesonbuild/compilers/mixins/ccrx.py',
+ 'mesonbuild/compilers/mixins/clang.py',
'mesonbuild/compilers/mixins/clike.py',
'mesonbuild/compilers/mixins/gnu.py',
# 'mesonbuild/compilers/mixins/intel.py',