add type anno: compilers/clike

pull/7215/head
Michael Hirsch, Ph.D 5 years ago committed by Jussi Pakkanen
parent a340b413ef
commit e2c475939e
  1. 6
      mesonbuild/compilers/compilers.py
  2. 30
      mesonbuild/compilers/mixins/clike.py

@ -494,7 +494,7 @@ class CompilerArgs(collections.abc.MutableSequence):
value = self.__container[index]
del self.__container[index]
if value in self.__seen_args and value in self.__container: # this is also honoring that you can have duplicated entries
self.__seen_args.remove(value)
self.__seen_args.remove(value)
def __len__(self) -> int:
return len(self.__container)
@ -688,7 +688,7 @@ class CompilerArgs(collections.abc.MutableSequence):
should_prepend = self._should_prepend(arg)
if dedup == 2:
# Remove all previous occurrences of the arg and add it anew
if arg in self.__seen_args and arg not in this_round_added: #if __seen_args contains arg as well as this_round_added, then its not yet part in self.
if arg in self.__seen_args and arg not in this_round_added: # if __seen_args contains arg as well as this_round_added, then its not yet part in self.
self.remove(arg)
if should_prepend:
if arg in pre:
@ -954,7 +954,7 @@ class Compiler:
return args
@contextlib.contextmanager
def compile(self, code, extra_args=None, *, mode='link', want_output=False, temp_dir=None):
def compile(self, code: str, extra_args: list = None, *, mode: str = 'link', want_output: bool = False, temp_dir: str = None):
if extra_args is None:
extra_args = []
try:

@ -254,14 +254,14 @@ class CLikeCompiler:
code = 'int main(void) { int class=0; return class; }\n'
return self.sanity_check_impl(work_dir, environment, 'sanitycheckc.c', code)
def check_header(self, hname, prefix, env, *, extra_args=None, dependencies=None):
def check_header(self, hname: str, prefix: str, env, *, extra_args=None, dependencies=None):
fargs = {'prefix': prefix, 'header': hname}
code = '''{prefix}
#include <{header}>'''
return self.compiles(code.format(**fargs), env, extra_args=extra_args,
dependencies=dependencies)
def has_header(self, hname, prefix, env, *, extra_args=None, dependencies=None, disable_cache=False):
def has_header(self, hname: str, prefix: str, env, *, extra_args=None, dependencies=None, disable_cache: bool = False):
fargs = {'prefix': prefix, 'header': hname}
code = '''{prefix}
#ifdef __has_include
@ -274,7 +274,7 @@ class CLikeCompiler:
return self.compiles(code.format(**fargs), env, extra_args=extra_args,
dependencies=dependencies, mode='preprocess', disable_cache=disable_cache)
def has_header_symbol(self, hname, symbol, prefix, env, *, extra_args=None, dependencies=None):
def has_header_symbol(self, hname: str, symbol: str, prefix: str, env, *, extra_args=None, dependencies=None):
fargs = {'prefix': prefix, 'header': hname, 'symbol': symbol}
t = '''{prefix}
#include <{header}>
@ -288,7 +288,7 @@ class CLikeCompiler:
return self.compiles(t.format(**fargs), env, extra_args=extra_args,
dependencies=dependencies)
def _get_basic_compiler_args(self, env, mode):
def _get_basic_compiler_args(self, env, mode: str):
cargs, largs = [], []
# Select a CRT if needed since we're linking
if mode == 'link':
@ -354,11 +354,11 @@ class CLikeCompiler:
def compiles(self, code: str, env, *,
extra_args: T.Sequence[T.Union[T.Sequence[str], str]] = None,
dependencies=None, mode: str = 'compile', disable_cache=False) -> T.Tuple[bool, bool]:
dependencies=None, mode: str = 'compile', disable_cache: bool = False) -> T.Tuple[bool, bool]:
with self._build_wrapper(code, env, extra_args, dependencies, mode, disable_cache=disable_cache) as p:
return p.returncode == 0, p.cached
def _build_wrapper(self, code: str, env, extra_args, dependencies=None, mode: str = 'compile', want_output: bool = False, disable_cache: bool = False, temp_dir=None) -> T.Tuple[bool, bool]:
def _build_wrapper(self, code: str, env, extra_args, dependencies=None, mode: str = 'compile', want_output: bool = False, disable_cache: bool = False, temp_dir: str = None) -> T.Tuple[bool, bool]:
args = self._get_compiler_check_args(env, extra_args, dependencies, mode)
if disable_cache or want_output:
return self.compile(code, extra_args=args, mode=mode, want_output=want_output, temp_dir=env.scratch_dir)
@ -916,21 +916,21 @@ class CLikeCompiler:
architecture.
'''
# If not building on macOS for Darwin, do a simple file check
files = [Path(f) for f in files]
paths = [Path(f) for f in files]
if not env.machines.host.is_darwin() or not env.machines.build.is_darwin():
for f in files:
if f.is_file():
return f
for p in paths:
if p.is_file():
return p
# Run `lipo` and check if the library supports the arch we want
for f in files:
if not f.is_file():
for p in paths:
if not p.is_file():
continue
archs = mesonlib.darwin_get_object_archs(str(f))
archs = mesonlib.darwin_get_object_archs(str(p))
if archs and env.machines.host.cpu_family in archs:
return f
return p
else:
mlog.debug('Rejected {}, supports {} but need {}'
.format(f, archs, env.machines.host.cpu_family))
.format(p, archs, env.machines.host.cpu_family))
return None
@functools.lru_cache()

Loading…
Cancel
Save