From 1624354f33bf0a33f0e715ba1ca391ae0154ad19 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 15:12:36 -0500 Subject: Use CompileCheckMode enum There were a ton of naked strings with TODOs telling us to use the enum. --- mesonbuild/compilers/mixins/gnu.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers/mixins/gnu.py') diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 93b367b..6517a3e 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -27,6 +27,7 @@ import typing as T from ... import mesonlib from ... import mlog from ...mesonlib import OptionKey +from mesonbuild.compilers.compilers import CompileCheckMode if T.TYPE_CHECKING: from ..._typing import ImmutableListProtocol @@ -464,7 +465,7 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta): def _get_search_dirs(self, env: 'Environment') -> str: extra_args = ['--print-search-dirs'] with self._build_wrapper('', env, extra_args=extra_args, - dependencies=None, mode='compile', + dependencies=None, mode=CompileCheckMode.COMPILE, want_output=True) as p: return p.stdout @@ -613,7 +614,7 @@ class GnuCompiler(GnuLikeCompiler): return ['-fopenmp'] def has_arguments(self, args: T.List[str], env: 'Environment', code: str, - mode: str) -> T.Tuple[bool, bool]: + mode: CompileCheckMode) -> T.Tuple[bool, bool]: # For some compiler command line arguments, the GNU compilers will # emit a warning on stderr indicating that an option is valid for a # another language, but still complete with exit_success -- cgit v1.1 From 921c2370a722cbaa42bd256c699fae3185084939 Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 17:36:25 -0500 Subject: Replace some type comments with annotations --- mesonbuild/compilers/mixins/gnu.py | 42 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'mesonbuild/compilers/mixins/gnu.py') diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 6517a3e..703fb1a 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -42,21 +42,21 @@ else: # XXX: prevent circular references. # FIXME: this really is a posix interface not a c-like interface -clike_debug_args = { +clike_debug_args: T.Dict[bool, T.List[str]] = { False: [], True: ['-g'], -} # type: T.Dict[bool, T.List[str]] +} -gnulike_buildtype_args = { +gnulike_buildtype_args: T.Dict[str, T.List[str]] = { 'plain': [], 'debug': [], 'debugoptimized': [], 'release': [], 'minsize': [], 'custom': [], -} # type: T.Dict[str, T.List[str]] +} -gnu_optimization_args = { +gnu_optimization_args: T.Dict[str, T.List[str]] = { 'plain': [], '0': ['-O0'], 'g': ['-Og'], @@ -64,9 +64,9 @@ gnu_optimization_args = { '2': ['-O2'], '3': ['-O3'], 's': ['-Os'], -} # type: T.Dict[str, T.List[str]] +} -gnulike_instruction_set_args = { +gnulike_instruction_set_args: T.Dict[str, T.List[str]] = { 'mmx': ['-mmmx'], 'sse': ['-msse'], 'sse2': ['-msse2'], @@ -77,22 +77,22 @@ gnulike_instruction_set_args = { 'avx': ['-mavx'], 'avx2': ['-mavx2'], 'neon': ['-mfpu=neon'], -} # type: T.Dict[str, T.List[str]] +} -gnu_symbol_visibility_args = { +gnu_symbol_visibility_args: T.Dict[str, T.List[str]] = { '': [], 'default': ['-fvisibility=default'], 'internal': ['-fvisibility=internal'], 'hidden': ['-fvisibility=hidden'], 'protected': ['-fvisibility=protected'], 'inlineshidden': ['-fvisibility=hidden', '-fvisibility-inlines-hidden'], -} # type: T.Dict[str, T.List[str]] +} -gnu_color_args = { +gnu_color_args: T.Dict[str, T.List[str]] = { 'auto': ['-fdiagnostics-color=auto'], 'always': ['-fdiagnostics-color=always'], 'never': ['-fdiagnostics-color=never'], -} # type: T.Dict[str, T.List[str]] +} # Warnings collected from the GCC source and documentation. This is an # objective set of all the warnings flags that apply to general projects: the @@ -118,7 +118,7 @@ gnu_color_args = { # # Omitted warnings enabled elsewhere in meson: # -Winvalid-pch (GCC 3.4.0) -gnu_common_warning_args = { +gnu_common_warning_args: T.Dict[str, T.List[str]] = { "0.0.0": [ "-Wcast-qual", "-Wconversion", @@ -213,7 +213,7 @@ gnu_common_warning_args = { "-Wopenacc-parallelism", "-Wtrivial-auto-var-init", ], -} # type: T.Dict[str, T.List[str]] +} # GCC warnings for C # Omitted non-general or legacy warnings: @@ -223,7 +223,7 @@ gnu_common_warning_args = { # -Wdeclaration-after-statement # -Wtraditional # -Wtraditional-conversion -gnu_c_warning_args = { +gnu_c_warning_args: T.Dict[str, T.List[str]] = { "0.0.0": [ "-Wbad-function-cast", "-Wmissing-prototypes", @@ -240,7 +240,7 @@ gnu_c_warning_args = { "4.5.0": [ "-Wunsuffixed-float-constants", ], -} # type: T.Dict[str, T.List[str]] +} # GCC warnings for C++ # Omitted non-general or legacy warnings: @@ -250,7 +250,7 @@ gnu_c_warning_args = { # -Wctad-maybe-unsupported # -Wnamespaces # -Wtemplates -gnu_cpp_warning_args = { +gnu_cpp_warning_args: T.Dict[str, T.List[str]] = { "0.0.0": [ "-Wctor-dtor-privacy", "-Weffc++", @@ -309,13 +309,13 @@ gnu_cpp_warning_args = { "-Wdeprecated-enum-float-conversion", "-Winvalid-imported-macros", ], -} # type: T.Dict[str, T.List[str]] +} # GCC warnings for Objective C and Objective C++ # Omitted non-general or legacy warnings: # -Wtraditional # -Wtraditional-conversion -gnu_objc_warning_args = { +gnu_objc_warning_args: T.Dict[str, T.List[str]] = { "0.0.0": [ "-Wselector", ], @@ -326,7 +326,7 @@ gnu_objc_warning_args = { "-Wassign-intercept", "-Wstrict-selector-match", ], -} # type: T.Dict[str, T.List[str]] +} _LANG_MAP = { 'c': 'c', @@ -345,7 +345,7 @@ def gnulike_default_include_dirs(compiler: T.Tuple[str, ...], lang: str) -> 'Imm cmd = list(compiler) + [f'-x{lang}', '-E', '-v', '-'] _, stdout, _ = mesonlib.Popen_safe(cmd, stderr=subprocess.STDOUT, env=env) parse_state = 0 - paths = [] # type: T.List[str] + paths: T.List[str] = [] for line in stdout.split('\n'): line = line.strip(' \n\r\t') if parse_state == 0: -- cgit v1.1 From d4bcf05c39e650d9651b5f2c60e7c12d59367e9c Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 17:47:12 -0500 Subject: Annotate naked fundamental Python types Although mypy wasn't complaining, pyright was. --- mesonbuild/compilers/mixins/gnu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers/mixins/gnu.py') diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 703fb1a..7b7bc89 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -483,7 +483,7 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta): # pathlib treats empty paths as '.', so filter those out paths = [p for p in pathstr.split(pathsep) if p] - result = [] + result: T.List[str] = [] for p in paths: # GCC returns paths like this: # /usr/lib/gcc/x86_64-linux-gnu/8/../../../../x86_64-linux-gnu/lib @@ -590,7 +590,7 @@ class GnuCompiler(GnuLikeCompiler): return args def supported_warn_args(self, warn_args_by_version: T.Dict[str, T.List[str]]) -> T.List[str]: - result = [] + result: T.List[str] = [] for version, warn_args in warn_args_by_version.items(): if mesonlib.version_compare(self.version, '>=' + version): result += warn_args -- cgit v1.1 From 33c8362a1cdd57dd60c7be8fdf3b0566ccdeb3bf Mon Sep 17 00:00:00 2001 From: Tristan Partin Date: Wed, 12 Jul 2023 17:56:18 -0500 Subject: Match the method signatures of parent classes Names and types of some methods did not match their parent methods. --- mesonbuild/compilers/mixins/gnu.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/compilers/mixins/gnu.py') diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index 7b7bc89..2b18732 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -529,8 +529,8 @@ class GnuLikeCompiler(Compiler, metaclass=abc.ABCMeta): args.append('-fno-omit-frame-pointer') return args - def get_output_args(self, target: str) -> T.List[str]: - return ['-o', target] + def get_output_args(self, outputname: str) -> T.List[str]: + return ['-o', outputname] def get_dependency_gen_args(self, outtarget: str, outfile: str) -> T.List[str]: return ['-MD', '-MQ', outtarget, '-MF', outfile] -- cgit v1.1