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] value = self.__container[index]
del 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 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: def __len__(self) -> int:
return len(self.__container) return len(self.__container)
@ -688,7 +688,7 @@ class CompilerArgs(collections.abc.MutableSequence):
should_prepend = self._should_prepend(arg) should_prepend = self._should_prepend(arg)
if dedup == 2: if dedup == 2:
# Remove all previous occurrences of the arg and add it anew # 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) self.remove(arg)
if should_prepend: if should_prepend:
if arg in pre: if arg in pre:
@ -954,7 +954,7 @@ class Compiler:
return args return args
@contextlib.contextmanager @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: if extra_args is None:
extra_args = [] extra_args = []
try: try:

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

Loading…
Cancel
Save