aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-17 12:35:15 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-09-24 12:14:13 -0700
commit4911e8eef42b11612adfab517c2d31b453ed14c4 (patch)
tree54c3f0ceb1c0c303f3c47b8050379dc72aa1af32
parentb6c8b8a5bedd3b01fee776e8f92cce83bbfed86b (diff)
downloadmeson-4911e8eef42b11612adfab517c2d31b453ed14c4.zip
meson-4911e8eef42b11612adfab517c2d31b453ed14c4.tar.gz
meson-4911e8eef42b11612adfab517c2d31b453ed14c4.tar.bz2
compilers/mixins: make visual studio type safe
-rw-r--r--mesonbuild/compilers/mixins/visualstudio.py23
-rwxr-xr-xrun_mypy.py1
2 files changed, 22 insertions, 2 deletions
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
index 74229e3..0686678 100644
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -24,7 +24,14 @@ from ... import mesonlib
from ... import mlog
if T.TYPE_CHECKING:
+ from contextlib import contextmanager
+
+ from ...arglist import CompilerArgs
+ from ...compilers.compilers import CompileResult
+ from ...dependencies import Dependency
+ from ...envconfig import MachineChoice
from ...environment import Environment
+ from ...linkers import MSVCDynamicLinker
vs32_instruction_set_args = {
'mmx': ['/arch:SSE'], # There does not seem to be a flag just for MMX
@@ -95,6 +102,18 @@ class VisualStudioLikeCompiler(metaclass=abc.ABCMeta):
This class implements as much common logic as possible.
"""
+ if T.TYPE_CHECKING:
+ linker = MSVCDynamicLinker(MachineChoice.HOST, [])
+ version = ''
+
+ @contextmanager # yes, yes, it's a half truth.
+ def _build_wrapper(self, code: str, env: 'Environment',
+ extra_args: T.Union[None, 'CompilerArgs', T.List[str]] = None,
+ dependencies: T.Optional[T.List['Dependency']] = None,
+ mode: str = 'compile', want_output: bool = False,
+ disable_cache: bool = False,
+ temp_dir: str = None) -> T.Iterator[T.Optional[CompileResult]]: ...
+
std_warn_args = ['/W3']
std_opt_args = ['/O2']
# XXX: this is copied in this patch only to avoid circular dependencies
@@ -291,7 +310,7 @@ class VisualStudioLikeCompiler(metaclass=abc.ABCMeta):
# Visual Studio is special. It ignores some arguments it does not
# understand and you can't tell it to error out on those.
# http://stackoverflow.com/questions/15259720/how-can-i-make-the-microsoft-c-compiler-treat-unknown-flags-as-errors-rather-t
- def has_arguments(self, args: T.List[str], env: 'Environment', code, mode: str) -> T.Tuple[bool, bool]:
+ def has_arguments(self, args: T.List[str], env: 'Environment', code: str, mode: str) -> T.Tuple[bool, bool]:
warning_text = '4044' if mode == 'link' else '9002'
with self._build_wrapper(code, env, extra_args=args, mode=mode) as p:
if p.returncode != 0:
@@ -420,7 +439,7 @@ class ClangClCompiler(VisualStudioLikeCompiler):
super().__init__(target)
self.id = 'clang-cl'
- def has_arguments(self, args: T.List[str], env: 'Environment', code, mode: str) -> T.Tuple[bool, bool]:
+ def has_arguments(self, args: T.List[str], env: 'Environment', code: str, mode: str) -> T.Tuple[bool, bool]:
if mode != 'link':
args = args + ['-Werror=unknown-argument']
return super().has_arguments(args, env, code, mode)
diff --git a/run_mypy.py b/run_mypy.py
index 8aaae87..0e9d957 100755
--- a/run_mypy.py
+++ b/run_mypy.py
@@ -27,6 +27,7 @@ modules = [
'mesonbuild/compilers/mixins/intel.py',
'mesonbuild/compilers/mixins/islinker.py',
'mesonbuild/compilers/mixins/pgi.py',
+ 'mesonbuild/compilers/mixins/visualstudio.py',
# 'mesonbuild/coredata.py',
'mesonbuild/dependencies/boost.py',
'mesonbuild/dependencies/hdf5.py',