From 8ee1e6b768aa4ba0f323d0e3bbf8bb7a137601a4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 17 Sep 2020 12:25:16 -0700 Subject: [PATCH] compilers/mixins/intel: make type safe --- mesonbuild/compilers/mixins/intel.py | 33 ++++++++++++++++++---------- run_mypy.py | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/mesonbuild/compilers/mixins/intel.py b/mesonbuild/compilers/mixins/intel.py index 7295e4e6d..cbbfc7a73 100644 --- a/mesonbuild/compilers/mixins/intel.py +++ b/mesonbuild/compilers/mixins/intel.py @@ -30,6 +30,10 @@ from .visualstudio import VisualStudioLikeCompiler if T.TYPE_CHECKING: import subprocess # noqa: F401 + from ...arglist import CompilerArgs + from ...dependencies import Dependency + from ...environment import Environment + # XXX: avoid circular dependencies # TODO: this belongs in a posix compiler class # NOTE: the default Intel optimization is -O2, unlike GNU which defaults to -O0. @@ -97,12 +101,13 @@ class IntelGnuLikeCompiler(GnuLikeCompiler): else: return ['-openmp'] - def compiles(self, *args, **kwargs) -> T.Tuple[bool, bool]: - # This covers a case that .get('foo', []) doesn't, that extra_args is - # defined and is None - extra_args = kwargs.get('extra_args') or [] - kwargs['extra_args'] = [ - extra_args, + def compiles(self, code: str, env: 'Environment', *, + extra_args: T.Union[None, T.List[str], 'CompilerArgs'] = None, + dependencies: T.Optional[T.List['Dependency']] = None, + mode: str = 'compile', + disable_cache: bool = False) -> T.Tuple[bool, bool]: + extra_args = extra_args.copy() if extra_args is not None else [] + extra_args += [ '-diag-error', '10006', # ignoring unknown option '-diag-error', '10148', # Option not supported '-diag-error', '10155', # ignoring argument required @@ -110,7 +115,8 @@ class IntelGnuLikeCompiler(GnuLikeCompiler): '-diag-error', '10157', # Ignoring argument of the wrong type '-diag-error', '10158', # Argument must be separate. Can be hit by trying an option like -foo-bar=foo when -foo=bar is a valid option but -foo-bar isn't ] - return super().compiles(*args, **kwargs) + ret = super().compiles(code, env, extra_args=extra_args, dependencies=dependencies, mode=mode, disable_cache=disable_cache) # type: ignore + return T.cast(T.Tuple[bool, bool], ret) def get_profile_generate_args(self) -> T.List[str]: return ['-prof-gen=threadsafe'] @@ -150,13 +156,17 @@ class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): 's': ['/Os'], } - def __init__(self, target: str): + def __init__(self, target: str) -> None: super().__init__(target) self.id = 'intel-cl' - def compile(self, code: str, *, extra_args: T.Optional[T.List[str]] = None, **kwargs) -> T.Iterator['subprocess.Popen']: + def compiles(self, code: str, env: 'Environment', *, + extra_args: T.Union[None, T.List[str], 'CompilerArgs'] = None, + dependencies: T.Optional[T.List['Dependency']] = None, + mode: str = 'compile', + disable_cache: bool = False) -> T.Tuple[bool, bool]: # This covers a case that .get('foo', []) doesn't, that extra_args is - if kwargs.get('mode', 'compile') != 'link': + if mode != 'link': extra_args = extra_args.copy() if extra_args is not None else [] extra_args.extend([ '/Qdiag-error:10006', # ignoring unknown option @@ -166,7 +176,8 @@ class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): '/Qdiag-error:10157', # Ignoring argument of the wrong type '/Qdiag-error:10158', # Argument must be separate. Can be hit by trying an option like -foo-bar=foo when -foo=bar is a valid option but -foo-bar isn't ]) - return super().compile(code, extra_args, **kwargs) + ret = super().compiles(code, env, extra_args=extra_args, dependencies=dependencies, mode=mode, disable_cache=disable_cache) # type: ignore + return T.cast(T.Tuple[bool, bool], ret) def get_toolset_version(self) -> T.Optional[str]: # Avoid circular dependencies.... diff --git a/run_mypy.py b/run_mypy.py index adffd83ca..ba805cb83 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -24,7 +24,7 @@ modules = [ 'mesonbuild/compilers/mixins/elbrus.py', 'mesonbuild/compilers/mixins/emscripten.py', 'mesonbuild/compilers/mixins/gnu.py', - # 'mesonbuild/compilers/mixins/intel.py', + 'mesonbuild/compilers/mixins/intel.py', # 'mesonbuild/coredata.py', 'mesonbuild/dependencies/boost.py', 'mesonbuild/dependencies/hdf5.py',