Compilers/vala: Add type annotations

pull/7795/head
Dylan Baker 4 years ago
parent d3a059b55f
commit efceec9615
  1. 9
      mesonbuild/compilers/compilers.py
  2. 50
      mesonbuild/compilers/vala.py
  3. 1
      run_mypy.py

@ -1088,6 +1088,15 @@ class Compiler(metaclass=abc.ABCMeta):
"""Arguments to turn off default inclusion of standard libraries.""" """Arguments to turn off default inclusion of standard libraries."""
return [] return []
def get_warn_args(self, level: str) -> T.List[str]:
return []
def get_werror_args(self) -> T.List[str]:
return []
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
raise EnvironmentError('{} does not implement get_optimization_args'.format(self.id))
def get_args_from_envvars(lang: str, def get_args_from_envvars(lang: str,
for_machine: MachineChoice, for_machine: MachineChoice,

@ -18,64 +18,66 @@ import typing as T
from .. import mlog from .. import mlog
from ..mesonlib import EnvironmentException, MachineChoice, version_compare from ..mesonlib import EnvironmentException, MachineChoice, version_compare
from .compilers import Compiler from .compilers import Compiler, LibType
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..environment import Environment
class ValaCompiler(Compiler): class ValaCompiler(Compiler):
language = 'vala' language = 'vala'
def __init__(self, exelist, version, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo'): is_cross: bool, info: 'MachineInfo'):
super().__init__(exelist, version, for_machine, info, is_cross=is_cross) super().__init__(exelist, version, for_machine, info, is_cross=is_cross)
self.version = version self.version = version
self.id = 'valac' self.id = 'valac'
self.base_options = ['b_colorout'] self.base_options = ['b_colorout']
def needs_static_linker(self): def needs_static_linker(self) -> bool:
return False # Because compiles into C. return False # Because compiles into C.
def get_optimization_args(self, optimization_level): def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return [] return []
def get_debug_args(self, is_debug): def get_debug_args(self, is_debug: bool) -> T.List[str]:
return ['--debug'] if is_debug else [] return ['--debug'] if is_debug else []
def get_output_args(self, target): def get_output_args(self, target: str) -> T.List[str]:
return [] # Because compiles into C. return [] # Because compiles into C.
def get_compile_only_args(self): def get_compile_only_args(self) -> T.List[str]:
return [] # Because compiles into C. return [] # Because compiles into C.
def get_pic_args(self): def get_pic_args(self) -> T.List[str]:
return [] return []
def get_pie_args(self): def get_pie_args(self) -> T.List[str]:
return [] return []
def get_pie_link_args(self): def get_pie_link_args(self) -> T.List[str]:
return [] return []
def get_always_args(self): def get_always_args(self) -> T.List[str]:
return ['-C'] return ['-C']
def get_warn_args(self, warning_level): def get_warn_args(self, warning_level: str) -> T.List[str]:
return [] return []
def get_no_warn_args(self): def get_no_warn_args(self) -> T.List[str]:
return ['--disable-warnings'] return ['--disable-warnings']
def get_werror_args(self): def get_werror_args(self) -> T.List[str]:
return ['--fatal-warnings'] return ['--fatal-warnings']
def get_colorout_args(self, colortype): def get_colorout_args(self, colortype: str) -> T.List[str]:
if version_compare(self.version, '>=0.37.1'): if version_compare(self.version, '>=0.37.1'):
return ['--color=' + colortype] return ['--color=' + colortype]
return [] return []
def compute_parameters_with_absolute_paths(self, parameter_list, build_dir): def compute_parameters_with_absolute_paths(self, parameter_list: T.List[str],
build_dir: str) -> T.List[str]:
for idx, i in enumerate(parameter_list): for idx, i in enumerate(parameter_list):
if i[:9] == '--girdir=': if i[:9] == '--girdir=':
parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:])) parameter_list[idx] = i[:9] + os.path.normpath(os.path.join(build_dir, i[9:]))
@ -88,7 +90,7 @@ class ValaCompiler(Compiler):
return parameter_list return parameter_list
def sanity_check(self, work_dir, environment): def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
code = 'class MesonSanityCheck : Object { }' code = 'class MesonSanityCheck : Object { }'
extra_flags = [] extra_flags = []
extra_flags += environment.coredata.get_external_args(self.for_machine, self.language) extra_flags += environment.coredata.get_external_args(self.for_machine, self.language)
@ -98,16 +100,16 @@ class ValaCompiler(Compiler):
extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language) extra_flags += environment.coredata.get_external_link_args(self.for_machine, self.language)
with self.cached_compile(code, environment.coredata, extra_args=extra_flags, mode='compile') as p: with self.cached_compile(code, environment.coredata, extra_args=extra_flags, mode='compile') as p:
if p.returncode != 0: if p.returncode != 0:
msg = 'Vala compiler {!r} can not compile programs' \ msg = 'Vala compiler {!r} can not compile programs'.format(self.name_string())
''.format(self.name_string())
raise EnvironmentException(msg) raise EnvironmentException(msg)
def get_buildtype_args(self, buildtype): def get_buildtype_args(self, buildtype: str) -> T.List[str]:
if buildtype == 'debug' or buildtype == 'debugoptimized' or buildtype == 'minsize': if buildtype in {'debug', 'debugoptimized', 'minsize'}:
return ['--debug'] return ['--debug']
return [] return []
def find_library(self, libname, env, extra_dirs, *args): def find_library(self, libname: str, env: 'Environment', extra_dirs: T.List[str],
libtype: LibType = LibType.PREFER_SHARED) -> T.Optional[T.List[str]]:
if extra_dirs and isinstance(extra_dirs, str): if extra_dirs and isinstance(extra_dirs, str):
extra_dirs = [extra_dirs] extra_dirs = [extra_dirs]
# Valac always looks in the default vapi dir, so only search there if # Valac always looks in the default vapi dir, so only search there if
@ -129,8 +131,8 @@ class ValaCompiler(Compiler):
mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname)) mlog.debug('Searched {!r} and {!r} wasn\'t found'.format(extra_dirs, libname))
return None return None
def thread_flags(self, env): def thread_flags(self, env: 'Environment') -> T.List[str]:
return [] return []
def thread_link_flags(self, env): def thread_link_flags(self, env: 'Environment') -> T.List[str]:
return [] return []

@ -23,6 +23,7 @@ modules = [
'mesonbuild/compilers/cuda.py', 'mesonbuild/compilers/cuda.py',
'mesonbuild/compilers/objc.py', 'mesonbuild/compilers/objc.py',
'mesonbuild/compilers/objcpp.py', 'mesonbuild/compilers/objcpp.py',
'mesonbuild/compilers/vala.py',
# 'mesonbuild/coredata.py', # 'mesonbuild/coredata.py',
'mesonbuild/dependencies/boost.py', 'mesonbuild/dependencies/boost.py',
'mesonbuild/dependencies/hdf5.py', 'mesonbuild/dependencies/hdf5.py',

Loading…
Cancel
Save