compilers: Fix extra_args parameter

which can also be a callable taking a CompileChekcMode as an argumetn
and returning a list of strings.
pull/9132/head
Dylan Baker 3 years ago
parent e9639be167
commit e3c72ad7c7
  1. 3
      mesonbuild/compilers/c.py
  2. 28
      mesonbuild/compilers/compilers.py
  3. 2
      mesonbuild/compilers/cpp.py
  4. 4
      mesonbuild/compilers/cuda.py
  5. 3
      mesonbuild/compilers/fortran.py
  6. 27
      mesonbuild/compilers/mixins/clike.py

@ -45,6 +45,7 @@ if T.TYPE_CHECKING:
from ..environment import Environment
from ..linkers import DynamicLinker
from ..programs import ExternalProgram
from .compilers import CompileCheckMode
CompilerMixinBase = Compiler
else:
@ -81,7 +82,7 @@ class CCompiler(CLikeCompiler, Compiler):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol}
t = '''{prefix}

@ -550,13 +550,15 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
return self.default_suffix
def get_define(self, dname: str, prefix: str, env: 'Environment',
extra_args: T.List[str], dependencies: T.List['Dependency'],
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.List['Dependency'],
disable_cache: bool = False) -> T.Tuple[str, bool]:
raise EnvironmentException('%s does not support get_define ' % self.get_id())
def compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[int],
guess: T.Optional[int], prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]], dependencies: T.Optional[T.List['Dependency']]) -> int:
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']]) -> int:
raise EnvironmentException('%s does not support compute_int ' % self.get_id())
def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
@ -565,12 +567,12 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def has_members(self, typename: str, membernames: T.List[str],
prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
raise EnvironmentException('%s does not support has_member(s) ' % self.get_id())
def has_type(self, typename: str, prefix: str, env: 'Environment',
extra_args: T.List[str], *,
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], *,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
raise EnvironmentException('%s does not support has_type ' % self.get_id())
@ -631,7 +633,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
return self.linker.get_option_args(options)
def check_header(self, hname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
"""Check that header is usable.
@ -642,7 +644,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
raise EnvironmentException('Language %s does not support header checks.' % self.get_display_language())
def has_header(self, hname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
"""Check that header is exists.
@ -663,17 +665,17 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
raise EnvironmentException('Language %s does not support header symbol checks.' % self.get_display_language())
def run(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]], None] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> RunResult:
raise EnvironmentException('Language %s does not support run checks.' % self.get_display_language())
def sizeof(self, typename: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> int:
raise EnvironmentException('Language %s does not support sizeof checks.' % self.get_display_language())
@ -1163,7 +1165,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
return []
def build_wrapper_args(self, env: 'Environment',
extra_args: T.Union[None, CompilerArgs, T.List[str]],
extra_args: T.Union[None, CompilerArgs, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']],
mode: CompileCheckMode = CompileCheckMode.COMPILE) -> CompilerArgs:
"""Arguments to pass the build_wrapper helper.
@ -1201,7 +1203,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
@contextlib.contextmanager
def _build_wrapper(self, code: 'mesonlib.FileOrString', env: 'Environment',
extra_args: T.Union[None, CompilerArgs, T.List[str]] = None,
extra_args: T.Union[None, CompilerArgs, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
mode: str = 'compile', want_output: bool = False,
disable_cache: bool = False,
@ -1220,7 +1222,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
yield r
def compiles(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
extra_args: T.Union[None, T.List[str], CompilerArgs] = None,
extra_args: T.Union[None, T.List[str], CompilerArgs, T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
mode: str = 'compile',
disable_cache: bool = False) -> T.Tuple[bool, bool]:
@ -1229,7 +1231,7 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
def links(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
extra_args: T.Union[None, T.List[str], CompilerArgs] = None,
extra_args: T.Union[None, T.List[str], CompilerArgs, T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
mode: str = 'compile',
disable_cache: bool = False) -> T.Tuple[bool, bool]:

@ -99,7 +99,7 @@ class CPPCompiler(CLikeCompiler, Compiler):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
# Check if it's a C-like symbol
found, cached = super().has_header_symbol(hname, symbol, prefix, env,

@ -24,7 +24,7 @@ from ..mesonlib import (
is_windows, LibType, OptionKey,
)
from .compilers import (Compiler, cuda_buildtype_args, cuda_optimization_args,
cuda_debug_args)
cuda_debug_args, CompileCheckMode)
if T.TYPE_CHECKING:
from ..build import BuildTarget
@ -584,7 +584,7 @@ class CudaCompiler(Compiler):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
if extra_args is None:
extra_args = []

@ -42,6 +42,7 @@ if T.TYPE_CHECKING:
from ..environment import Environment
from ..linkers import DynamicLinker
from ..programs import ExternalProgram
from .compilers import CompileCheckMode
class FortranCompiler(CLikeCompiler, Compiler):
@ -214,7 +215,7 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
return ['-lgfortran', '-lm']
def has_header(self, hname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
'''

@ -343,7 +343,7 @@ class CLikeCompiler(Compiler):
return self._sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code)
def check_header(self, hname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
code = f'''{prefix}
#include <{hname}>'''
@ -351,7 +351,7 @@ class CLikeCompiler(Compiler):
dependencies=dependencies)
def has_header(self, hname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[['CompileCheckMode'], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None,
disable_cache: bool = False) -> T.Tuple[bool, bool]:
code = f'''{prefix}
@ -367,7 +367,7 @@ class CLikeCompiler(Compiler):
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
t = f'''{prefix}
#include <{hname}>
@ -422,7 +422,7 @@ class CLikeCompiler(Compiler):
return cargs, largs
def build_wrapper_args(self, env: 'Environment',
extra_args: T.Union[None, arglist.CompilerArgs, T.List[str]],
extra_args: T.Union[None, arglist.CompilerArgs, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']],
mode: CompileCheckMode = CompileCheckMode.COMPILE) -> arglist.CompilerArgs:
# TODO: the caller should handle the listfing of these arguments
@ -463,7 +463,7 @@ class CLikeCompiler(Compiler):
return args
def run(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]], None] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> compilers.RunResult:
need_exe_wrapper = env.need_exe_wrapper(self.for_machine)
if need_exe_wrapper and self.exe_wrapper is None:
@ -489,7 +489,7 @@ class CLikeCompiler(Compiler):
return compilers.RunResult(True, pe.returncode, so, se)
def _compile_int(self, expression: str, prefix: str, env: 'Environment',
extra_args: T.Optional[T.List[str]],
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']]) -> bool:
t = f'''#include <stdio.h>
{prefix}
@ -499,7 +499,7 @@ class CLikeCompiler(Compiler):
def cross_compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[int],
guess: T.Optional[int], prefix: str, env: 'Environment',
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> int:
# Try user's guess first
if isinstance(guess, int):
@ -550,7 +550,7 @@ class CLikeCompiler(Compiler):
def compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[int],
guess: T.Optional[int], prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']] = None) -> int:
if extra_args is None:
extra_args = []
@ -571,7 +571,7 @@ class CLikeCompiler(Compiler):
return int(res.stdout)
def cross_sizeof(self, typename: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> int:
if extra_args is None:
extra_args = []
@ -587,7 +587,7 @@ class CLikeCompiler(Compiler):
return self.cross_compute_int(f'sizeof({typename})', None, None, None, prefix, env, extra_args, dependencies)
def sizeof(self, typename: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> int:
if extra_args is None:
extra_args = []
@ -661,7 +661,7 @@ class CLikeCompiler(Compiler):
return align
def get_define(self, dname: str, prefix: str, env: 'Environment',
extra_args: T.Optional[T.List[str]],
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
dependencies: T.Optional[T.List['Dependency']],
disable_cache: bool = False) -> T.Tuple[str, bool]:
delim = '"MESON_GET_DEFINE_DELIMITER"'
@ -874,7 +874,7 @@ class CLikeCompiler(Compiler):
def has_members(self, typename: str, membernames: T.List[str],
prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None,
extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]] = None,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
if extra_args is None:
extra_args = []
@ -890,7 +890,8 @@ class CLikeCompiler(Compiler):
return self.compiles(t, env, extra_args=extra_args,
dependencies=dependencies)
def has_type(self, typename: str, prefix: str, env: 'Environment', extra_args: T.List[str],
def has_type(self, typename: str, prefix: str, env: 'Environment',
extra_args: T.Union[T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], *,
dependencies: T.Optional[T.List['Dependency']] = None) -> T.Tuple[bool, bool]:
t = f'''{prefix}
void bar(void) {{

Loading…
Cancel
Save