From 1c20f187e87e7bfec0c242cef88f1d06ab324b39 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 28 Sep 2020 12:57:11 -0700 Subject: [PATCH] compilers/intel: use get_compiler_check_args Instead of trying to override the compiles() method, which gets skipped in a bunch of cases. --- mesonbuild/compilers/mixins/clike.py | 12 ++++++------ mesonbuild/compilers/mixins/intel.py | 27 +++++++++------------------ 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index 9de715c97..c21fbd01c 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -385,10 +385,10 @@ class CLikeCompiler(Compiler): return self.compiles(t.format(**fargs), env, extra_args=extra_args, dependencies=dependencies) - def _get_basic_compiler_args(self, env: 'Environment', mode: str) -> T.Tuple[T.List[str], T.List[str]]: + def _get_basic_compiler_args(self, env: 'Environment', mode: CompileCheckMode) -> T.Tuple[T.List[str], T.List[str]]: cargs = [] # type: T.List[str] largs = [] # type: T.List[str] - if mode == 'link': + if mode is CompileCheckMode.LINK: # Sometimes we need to manually select the CRT to use with MSVC. # One example is when trying to do a compiler check that involves # linking with static libraries since MSVC won't select a CRT for @@ -409,7 +409,7 @@ class CLikeCompiler(Compiler): cleaned_sys_args = self.remove_linkerlike_args(sys_args) cargs += cleaned_sys_args - if mode == 'link': + if mode is CompileCheckMode.LINK: ld_value = env.lookup_binary_entry(self.for_machine, self.language + '_ld') if ld_value is not None: largs += self.use_linker_args(ld_value[0]) @@ -433,7 +433,7 @@ class CLikeCompiler(Compiler): else: # TODO: we want to do this in the caller extra_args = mesonlib.listify(extra_args) - extra_args = mesonlib.listify([e(mode) if callable(e) else e for e in extra_args]) + extra_args = mesonlib.listify([e(mode.value) if callable(e) else e for e in extra_args]) if dependencies is None: dependencies = [] @@ -446,7 +446,7 @@ class CLikeCompiler(Compiler): for d in dependencies: # Add compile flags needed by dependencies cargs += d.get_compile_args() - if mode == 'link': + if mode is CompileCheckMode.LINK: # Add link flags needed to find dependencies largs += d.get_link_args() @@ -476,7 +476,7 @@ class CLikeCompiler(Compiler): def _build_wrapper(self, code: str, env: 'Environment', extra_args: T.Union[None, arglist.CompilerArgs, T.List[str]] = None, dependencies: T.Optional[T.List['Dependency']] = None, - mode: str = CompileCheckMode.COMPILE, want_output: bool = False, + mode: str = 'compile', want_output: bool = False, disable_cache: bool = False, temp_dir: str = None) -> T.Iterator[T.Optional[compilers.CompileResult]]: args = self._get_compiler_check_args(env, extra_args, dependencies, CompileCheckMode(mode)) diff --git a/mesonbuild/compilers/mixins/intel.py b/mesonbuild/compilers/mixins/intel.py index 5bb55ffa1..1fc55fcaf 100644 --- a/mesonbuild/compilers/mixins/intel.py +++ b/mesonbuild/compilers/mixins/intel.py @@ -24,6 +24,7 @@ import os import typing as T from ... import mesonlib +from ..compilers import CompileCheckMode from .gnu import GnuLikeCompiler from .visualstudio import VisualStudioLikeCompiler @@ -99,13 +100,8 @@ class IntelGnuLikeCompiler(GnuLikeCompiler): else: return ['-openmp'] - 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 += [ + def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: + extra_args = [ '-diag-error', '10006', # ignoring unknown option '-diag-error', '10148', # Option not supported '-diag-error', '10155', # ignoring argument required @@ -113,7 +109,7 @@ 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(code, env, extra_args=extra_args, dependencies=dependencies, mode=mode, disable_cache=disable_cache) + return super().get_compiler_check_args(mode) + extra_args def get_profile_generate_args(self) -> T.List[str]: return ['-prof-gen=threadsafe'] @@ -157,15 +153,10 @@ class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): super().__init__(target) self.id = 'intel-cl' - 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 mode != 'link': - extra_args = extra_args.copy() if extra_args is not None else [] - extra_args.extend([ + def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]: + args = super().get_compiler_check_args(mode) + if mode is not CompileCheckMode.LINK: + args.extend([ '/Qdiag-error:10006', # ignoring unknown option '/Qdiag-error:10148', # Option not supported '/Qdiag-error:10155', # ignoring argument required @@ -173,7 +164,7 @@ 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().compiles(code, env, extra_args=extra_args, dependencies=dependencies, mode=mode, disable_cache=disable_cache) + return args def get_toolset_version(self) -> T.Optional[str]: # Avoid circular dependencies....