diff options
| -rw-r--r-- | mesonbuild/environment.py | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py index 03e257766..d124a608b 100644 --- a/mesonbuild/environment.py +++ b/mesonbuild/environment.py @@ -44,6 +44,7 @@ if T.TYPE_CHECKING: from configparser import ConfigParser from .compilers import Compiler + from .compilers.mixins.visualstudio import VisualStudioLikeCompiler from .wrap.wrap import Resolver from . import cargo @@ -53,6 +54,11 @@ if T.TYPE_CHECKING: build_filename = 'meson.build' +def _as_str(val: object) -> str: + assert isinstance(val, str), 'for mypy' + return val + + def _get_env_var(for_machine: MachineChoice, is_cross: bool, var_name: str) -> T.Optional[str]: """ Returns the exact env var and the value. @@ -338,6 +344,7 @@ def detect_windows_arch(compilers: CompilersDict) -> str: # 32-bit and pretend like we're running under WOW64. Else, return the # actual Windows architecture that we deduced above. for compiler in compilers.values(): + compiler = T.cast('VisualStudioLikeCompiler', compiler) if compiler.id == 'msvc' and (compiler.target in {'x86', '80x86'}): return 'x86' if compiler.id == 'clang-cl' and (compiler.target in {'x86', 'i686'}): @@ -869,7 +876,12 @@ class Environment: # re-initialized with project options by the interpreter during # build file parsing. # meson_command is used by the regenchecker script, which runs meson - self.coredata = coredata.CoreData(options, self.scratch_dir, mesonlib.get_meson_command()) + meson_command = mesonlib.get_meson_command() + if meson_command is None: + meson_command = [] + else: + meson_command = meson_command.copy() + self.coredata = coredata.CoreData(options, self.scratch_dir, meson_command) self.first_invocation = True def is_cross_build(self, when_building_for: MachineChoice = MachineChoice.HOST) -> bool: @@ -950,25 +962,25 @@ class Environment: return self.get_libdir() def get_prefix(self) -> str: - return self.coredata.get_option(OptionKey('prefix')) + return _as_str(self.coredata.get_option(OptionKey('prefix'))) def get_libdir(self) -> str: - return self.coredata.get_option(OptionKey('libdir')) + return _as_str(self.coredata.get_option(OptionKey('libdir'))) def get_libexecdir(self) -> str: - return self.coredata.get_option(OptionKey('libexecdir')) + return _as_str(self.coredata.get_option(OptionKey('libexecdir'))) def get_bindir(self) -> str: - return self.coredata.get_option(OptionKey('bindir')) + return _as_str(self.coredata.get_option(OptionKey('bindir'))) def get_includedir(self) -> str: - return self.coredata.get_option(OptionKey('includedir')) + return _as_str(self.coredata.get_option(OptionKey('includedir'))) def get_mandir(self) -> str: - return self.coredata.get_option(OptionKey('mandir')) + return _as_str(self.coredata.get_option(OptionKey('mandir'))) def get_datadir(self) -> str: - return self.coredata.get_option(OptionKey('datadir')) + return _as_str(self.coredata.get_option(OptionKey('datadir'))) def get_compiler_system_lib_dirs(self, for_machine: MachineChoice) -> T.List[str]: for comp in self.coredata.compilers[for_machine].values(): @@ -986,8 +998,8 @@ class Environment: p, out, _ = Popen_safe(comp.get_exelist() + ['-print-search-dirs']) if p.returncode != 0: raise mesonlib.MesonException('Could not calculate system search dirs') - out = out.split('\n')[index].lstrip('libraries: =').split(':') - return [os.path.normpath(p) for p in out] + split = out.split('\n')[index].lstrip('libraries: =').split(':') + return [os.path.normpath(p) for p in split] def get_compiler_system_include_dirs(self, for_machine: MachineChoice) -> T.List[str]: for comp in self.coredata.compilers[for_machine].values(): @@ -1016,7 +1028,7 @@ class Environment: return self.exe_wrapper def has_exe_wrapper(self) -> bool: - return self.exe_wrapper and self.exe_wrapper.found() + return self.exe_wrapper is not None and self.exe_wrapper.found() def get_env_for_paths(self, library_paths: T.Set[str], extra_paths: T.Set[str]) -> mesonlib.EnvironmentVariables: env = mesonlib.EnvironmentVariables() |
