aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/mixins/clike.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2023-07-17 00:29:37 +0300
committerGitHub <noreply@github.com>2023-07-17 00:29:37 +0300
commit0dba7340ecfbe84231a14559ef7f9e7dfb7d1299 (patch)
treeade6d93a8c93bfbfe9df8de6796c93588e3fe080 /mesonbuild/compilers/mixins/clike.py
parentb60ea0851b1dfe4400dc2d12b127300b1da41105 (diff)
parent9b86c67e19b91eee065c1e3706ad5521801022da (diff)
downloadmeson-0dba7340ecfbe84231a14559ef7f9e7dfb7d1299.zip
meson-0dba7340ecfbe84231a14559ef7f9e7dfb7d1299.tar.gz
meson-0dba7340ecfbe84231a14559ef7f9e7dfb7d1299.tar.bz2
Merge pull request #11976 from tristan957/cleanups
Some various type related cleanups
Diffstat (limited to 'mesonbuild/compilers/mixins/clike.py')
-rw-r--r--mesonbuild/compilers/mixins/clike.py52
1 files changed, 26 insertions, 26 deletions
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
index cec6b75..da36185 100644
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -103,7 +103,7 @@ class CLikeCompilerArgs(arglist.CompilerArgs):
default_dirs = self.compiler.get_default_include_dirs()
if default_dirs:
real_default_dirs = [self._cached_realpath(i) for i in default_dirs]
- bad_idx_list = [] # type: T.List[int]
+ bad_idx_list: T.List[int] = []
for i, each in enumerate(new):
if not each.startswith('-isystem'):
continue
@@ -136,11 +136,11 @@ class CLikeCompiler(Compiler):
"""Shared bits for the C and CPP Compilers."""
if T.TYPE_CHECKING:
- warn_args = {} # type: T.Dict[str, T.List[str]]
+ warn_args: T.Dict[str, T.List[str]] = {}
# TODO: Replace this manual cache with functools.lru_cache
- find_library_cache = {} # type: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], str, LibType], T.Optional[T.List[str]]]
- find_framework_cache = {} # type: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], bool], T.Optional[T.List[str]]]
+ find_library_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], str, LibType], T.Optional[T.List[str]]] = {}
+ find_framework_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], bool], T.Optional[T.List[str]]] = {}
internal_libs = arglist.UNIXY_COMPILER_INTERNAL_LIBS
def __init__(self, exe_wrapper: T.Optional['ExternalProgram'] = None):
@@ -226,7 +226,7 @@ class CLikeCompiler(Compiler):
# system directories aren't mixed, we only need to check one file for each
# directory and go by that. If we can't check the file for some reason, assume
# the compiler knows what it's doing, and accept the directory anyway.
- retval = []
+ retval: T.List[str] = []
for d in dirs:
files = [f for f in os.listdir(d) if f.endswith('.so') and os.path.isfile(os.path.join(d, f))]
# if no files, accept directory and move on
@@ -370,7 +370,7 @@ class CLikeCompiler(Compiler):
#include <{hname}>
#endif'''
return self.compiles(code, env, extra_args=extra_args,
- dependencies=dependencies, mode='preprocess', disable_cache=disable_cache)
+ dependencies=dependencies, mode=CompileCheckMode.PREPROCESS, disable_cache=disable_cache)
def has_header_symbol(self, hname: str, symbol: str, prefix: str,
env: 'Environment', *,
@@ -389,8 +389,8 @@ class CLikeCompiler(Compiler):
dependencies=dependencies)
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]
+ cargs: T.List[str] = []
+ largs: T.List[str] = []
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
@@ -446,8 +446,8 @@ class CLikeCompiler(Compiler):
# TODO: we want to ensure the front end does the listifing here
dependencies = [dependencies]
# Collect compiler arguments
- cargs = self.compiler_args() # type: arglist.CompilerArgs
- largs = [] # type: T.List[str]
+ cargs: arglist.CompilerArgs = self.compiler_args()
+ largs: T.List[str] = []
for d in dependencies:
# Add compile flags needed by dependencies
cargs += d.get_compile_args()
@@ -475,7 +475,7 @@ class CLikeCompiler(Compiler):
need_exe_wrapper = env.need_exe_wrapper(self.for_machine)
if need_exe_wrapper and self.exe_wrapper is None:
raise compilers.CrossNoRunException('Can not run test applications in this cross environment.')
- with self._build_wrapper(code, env, extra_args, dependencies, mode='link', want_output=True) as p:
+ with self._build_wrapper(code, env, extra_args, dependencies, mode=CompileCheckMode.LINK, want_output=True) as p:
if p.returncode != 0:
mlog.debug(f'Could not compile test file {p.input_name}: {p.returncode}\n')
return compilers.RunResult(False)
@@ -678,9 +678,9 @@ class CLikeCompiler(Compiler):
{delim}\n{dname}'''
args = self.build_wrapper_args(env, extra_args, dependencies,
mode=CompileCheckMode.PREPROCESS).to_native()
- func = functools.partial(self.cached_compile, code, env.coredata, extra_args=args, mode='preprocess')
+ func = functools.partial(self.cached_compile, code, env.coredata, extra_args=args, mode=CompileCheckMode.PREPROCESS)
if disable_cache:
- func = functools.partial(self.compile, code, extra_args=args, mode='preprocess', temp_dir=env.scratch_dir)
+ func = functools.partial(self.compile, code, extra_args=args, mode=CompileCheckMode.PREPROCESS)
with func() as p:
cached = p.cached
if p.returncode != 0:
@@ -805,7 +805,7 @@ class CLikeCompiler(Compiler):
#
# class StrProto(typing.Protocol):
# def __str__(self) -> str: ...
- fargs = {'prefix': prefix, 'func': funcname} # type: T.Dict[str, T.Union[str, bool, int]]
+ fargs: T.Dict[str, T.Union[str, bool, int]] = {'prefix': prefix, 'func': funcname}
# glibc defines functions that are not available on Linux as stubs that
# fail with ENOSYS (such as e.g. lchmod). In this case we want to fail
@@ -919,7 +919,7 @@ class CLikeCompiler(Compiler):
'''
args = self.get_compiler_check_args(CompileCheckMode.COMPILE)
n = '_symbols_have_underscore_prefix_searchbin'
- with self._build_wrapper(code, env, extra_args=args, mode='compile', want_output=True, temp_dir=env.scratch_dir) as p:
+ with self._build_wrapper(code, env, extra_args=args, mode=CompileCheckMode.COMPILE, want_output=True) as p:
if p.returncode != 0:
raise RuntimeError(f'BUG: Unable to compile {n!r} check: {p.stderr}')
if not os.path.isfile(p.output_name):
@@ -954,7 +954,7 @@ class CLikeCompiler(Compiler):
#endif
{delim}MESON_UNDERSCORE_PREFIX
'''
- with self._build_wrapper(code, env, mode='preprocess', want_output=False, temp_dir=env.scratch_dir) as p:
+ with self._build_wrapper(code, env, mode=CompileCheckMode.PREPROCESS, want_output=False) as p:
if p.returncode != 0:
raise RuntimeError(f'BUG: Unable to preprocess _symbols_have_underscore_prefix_define check: {p.stdout}')
symbol_prefix = p.stdout.partition(delim)[-1].rstrip()
@@ -1002,7 +1002,7 @@ class CLikeCompiler(Compiler):
return self._symbols_have_underscore_prefix_searchbin(env)
def _get_patterns(self, env: 'Environment', prefixes: T.List[str], suffixes: T.List[str], shared: bool = False) -> T.List[str]:
- patterns = [] # type: T.List[str]
+ patterns: T.List[str] = []
for p in prefixes:
for s in suffixes:
patterns.append(p + '{}.' + s)
@@ -1066,7 +1066,7 @@ class CLikeCompiler(Compiler):
@staticmethod
def _sort_shlibs_openbsd(libs: T.List[str]) -> T.List[str]:
- filtered = [] # type: T.List[str]
+ filtered: T.List[str] = []
for lib in libs:
# Validate file as a shared library of type libfoo.so.X.Y
ret = lib.rsplit('.so.', maxsplit=1)
@@ -1205,7 +1205,7 @@ class CLikeCompiler(Compiler):
os_env = os.environ.copy()
os_env['LC_ALL'] = 'C'
_, _, stde = mesonlib.Popen_safe(commands, env=os_env, stdin=subprocess.PIPE)
- paths = [] # T.List[str]
+ paths: T.List[str] = []
for line in stde.split('\n'):
if '(framework directory)' not in line:
continue
@@ -1216,7 +1216,7 @@ class CLikeCompiler(Compiler):
def _find_framework_real(self, name: str, env: 'Environment', extra_dirs: T.List[str], allow_system: bool) -> T.Optional[T.List[str]]:
code = 'int main(void) { return 0; }'
- link_args = []
+ link_args: T.List[str] = []
for d in extra_dirs:
link_args += ['-F' + d]
# We can pass -Z to disable searching in the system frameworks, but
@@ -1269,11 +1269,11 @@ class CLikeCompiler(Compiler):
return args.copy()
def has_arguments(self, args: T.List[str], env: 'Environment', code: str,
- mode: str) -> T.Tuple[bool, bool]:
+ mode: CompileCheckMode) -> T.Tuple[bool, bool]:
return self.compiles(code, env, extra_args=args, mode=mode)
def _has_multi_arguments(self, args: T.List[str], env: 'Environment', code: str) -> T.Tuple[bool, bool]:
- new_args = [] # type: T.List[str]
+ new_args: T.List[str] = []
for arg in args:
# some compilers, e.g. GCC, don't warn for unsupported warning-disable
# flags, so when we are testing a flag like "-Wno-forgotten-towel", also
@@ -1289,7 +1289,7 @@ class CLikeCompiler(Compiler):
'the compiler you are using. has_link_argument or '
'other similar method can be used instead.')
new_args.append(arg)
- return self.has_arguments(new_args, env, code, mode='compile')
+ return self.has_arguments(new_args, env, code, mode=CompileCheckMode.COMPILE)
def has_multi_arguments(self, args: T.List[str], env: 'Environment') -> T.Tuple[bool, bool]:
return self._has_multi_arguments(args, env, 'extern int i;\nint i;\n')
@@ -1300,7 +1300,7 @@ class CLikeCompiler(Compiler):
# false positive.
args = self.linker.fatal_warnings() + args
args = self.linker_to_compiler_args(args)
- return self.has_arguments(args, env, code, mode='link')
+ return self.has_arguments(args, env, code, mode=CompileCheckMode.LINK)
def has_multi_link_arguments(self, args: T.List[str], env: 'Environment') -> T.Tuple[bool, bool]:
return self._has_multi_link_arguments(args, env, 'int main(void) { return 0; }\n')
@@ -1340,7 +1340,7 @@ class CLikeCompiler(Compiler):
@functools.lru_cache(maxsize=None)
def can_compile(self, src: 'mesonlib.FileOrString') -> bool:
# Files we preprocess can be anything, e.g. .in
- if self.mode == 'PREPROCESSOR':
+ if self.mode == CompileCheckMode.PREPROCESS:
return True
return super().can_compile(src)
@@ -1348,6 +1348,6 @@ class CLikeCompiler(Compiler):
if not self.preprocessor:
self.preprocessor = copy.copy(self)
self.preprocessor.exelist = self.exelist + self.get_preprocess_to_file_args()
- self.preprocessor.mode = 'PREPROCESSOR'
+ self.preprocessor.mode = CompileCheckMode.PREPROCESS
self.modes.append(self.preprocessor)
return self.preprocessor