diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2019-07-02 15:30:12 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2019-07-15 10:59:22 -0700 |
commit | f574beffb4d7e26ba21d1bbc5ad6f36a23df0bfc (patch) | |
tree | 587ab9ceffd7a7c68054a370f8b5cdc60f0c8b52 /mesonbuild | |
parent | 5d685e7a5c5d2705591d908ec985b6cc8994c4d9 (diff) | |
download | meson-f574beffb4d7e26ba21d1bbc5ad6f36a23df0bfc.zip meson-f574beffb4d7e26ba21d1bbc5ad6f36a23df0bfc.tar.gz meson-f574beffb4d7e26ba21d1bbc5ad6f36a23df0bfc.tar.bz2 |
compilers/mixins/elbrus: add type annotations and fix types
There is a pretty big error in here, trying to return a tuple
comperhension: (a for a in []) is not a tuple, it's a generator. This
has profound type annotations: generators don't support most tuple or
list methods, and they can only be iterated once. Beyond that tuples are
meant for heterogenous types, ie, position matters for types. I've
converted the output to a list in all cases.
Diffstat (limited to 'mesonbuild')
-rw-r--r-- | mesonbuild/compilers/compilers.py | 2 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/clike.py | 8 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/elbrus.py | 23 | ||||
-rw-r--r-- | mesonbuild/compilers/mixins/gnu.py | 8 |
4 files changed, 23 insertions, 18 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index 6e914a6..eebb6e6 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -937,7 +937,7 @@ class Compiler: return () def get_program_dirs(self, *args, **kwargs): - return () + return [] def has_multi_arguments(self, args, env) -> Tuple[bool, bool]: raise EnvironmentException( diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py index b378252..e032402 100644 --- a/mesonbuild/compilers/mixins/clike.py +++ b/mesonbuild/compilers/mixins/clike.py @@ -35,6 +35,10 @@ from ... import mlog from .. import compilers from .visualstudio import VisualStudioLikeCompiler +if typing.TYPE_CHECKING: + from ...environment import Environment + + class CLikeCompiler: """Shared bits for the C and CPP Compilers.""" @@ -161,11 +165,11 @@ class CLikeCompiler: def get_std_shared_lib_link_args(self): return ['-shared'] - def get_compiler_dirs(self, env, name): + def get_compiler_dirs(self, env: 'Environment', name: str) -> typing.List[str]: ''' Get dirs from the compiler, either `libraries:` or `programs:` ''' - return () + return [] @functools.lru_cache() def get_library_dirs(self, env, elf_class = None): diff --git a/mesonbuild/compilers/mixins/elbrus.py b/mesonbuild/compilers/mixins/elbrus.py index a254a8b..eb7414c 100644 --- a/mesonbuild/compilers/mixins/elbrus.py +++ b/mesonbuild/compilers/mixins/elbrus.py @@ -15,15 +15,20 @@ """Abstractions for the Elbrus family of compilers.""" import os +import typing from .gnu import GnuCompiler from ...mesonlib import Popen_safe +if typing.TYPE_CHECKING: + from ..compilers import CompilerType + from ...environment import Environment + class ElbrusCompiler(GnuCompiler): # Elbrus compiler is nearly like GCC, but does not support # PCH, LTO, sanitizers and color output as of version 1.21.x. - def __init__(self, compiler_type, defines): + def __init__(self, compiler_type: 'CompilerType', defines: typing.Dict[str, str]): GnuCompiler.__init__(self, compiler_type, defines) self.id = 'lcc' self.base_options = ['b_pgo', 'b_coverage', @@ -32,28 +37,24 @@ class ElbrusCompiler(GnuCompiler): # FIXME: use _build_wrapper to call this so that linker flags from the env # get applied - def get_library_dirs(self, env, elf_class = None): + def get_library_dirs(self, env: 'Environment', elf_class: typing.Optional[int] = None) -> typing.List[str]: os_env = os.environ.copy() os_env['LC_ALL'] = 'C' stdo = Popen_safe(self.exelist + ['--print-search-dirs'], env=os_env)[1] - paths = () for line in stdo.split('\n'): if line.startswith('libraries:'): # lcc does not include '=' in --print-search-dirs output. libstr = line.split(' ', 1)[1] - paths = (os.path.realpath(p) for p in libstr.split(':')) - break - return paths + return [os.path.realpath(p) for p in libstr.split(':')] + return [] - def get_program_dirs(self, env): + def get_program_dirs(self, env: 'Environment') -> typing.List[str]: os_env = os.environ.copy() os_env['LC_ALL'] = 'C' stdo = Popen_safe(self.exelist + ['--print-search-dirs'], env=os_env)[1] - paths = () for line in stdo.split('\n'): if line.startswith('programs:'): # lcc does not include '=' in --print-search-dirs output. libstr = line.split(' ', 1)[1] - paths = (os.path.realpath(p) for p in libstr.split(':')) - break - return paths
\ No newline at end of file + return [os.path.realpath(p) for p in libstr.split(':')] + return [] diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 92fa579..46f04c4 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -319,7 +319,7 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): stdo = p.stdo return stdo - def _split_fetch_real_dirs(self, pathstr: str) -> typing.Tuple[str, ...]: + def _split_fetch_real_dirs(self, pathstr: str) -> typing.List[str]: # We need to use the path separator used by the compiler for printing # lists of paths ("gcc --print-search-dirs"). By default # we assume it uses the platform native separator. @@ -354,9 +354,9 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): result.append(resolved) except FileNotFoundError: pass - return tuple(result) + return result - def get_compiler_dirs(self, env: 'Environment', name: str) -> typing.Tuple[str, ...]: + def get_compiler_dirs(self, env: 'Environment', name: str) -> typing.List[str]: ''' Get dirs from the compiler, either `libraries:` or `programs:` ''' @@ -364,7 +364,7 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): for line in stdo.split('\n'): if line.startswith(name + ':'): return self._split_fetch_real_dirs(line.split('=', 1)[1]) - return () + return [] class GnuCompiler(GnuLikeCompiler): |