4444 from configparser import ConfigParser
4545
4646 from .compilers import Compiler
47+ from .compilers .mixins .visualstudio import VisualStudioLikeCompiler
4748 from .wrap .wrap import Resolver
4849 from . import cargo
4950
5354build_filename = 'meson.build'
5455
5556
57+ def _as_str (val : object ) -> str :
58+ assert isinstance (val , str ), 'for mypy'
59+ return val
60+
61+
5662def _get_env_var (for_machine : MachineChoice , is_cross : bool , var_name : str ) -> T .Optional [str ]:
5763 """
5864 Returns the exact env var and the value.
@@ -338,6 +344,7 @@ def detect_windows_arch(compilers: CompilersDict) -> str:
338344 # 32-bit and pretend like we're running under WOW64. Else, return the
339345 # actual Windows architecture that we deduced above.
340346 for compiler in compilers .values ():
347+ compiler = T .cast ('VisualStudioLikeCompiler' , compiler )
341348 if compiler .id == 'msvc' and (compiler .target in {'x86' , '80x86' }):
342349 return 'x86'
343350 if compiler .id == 'clang-cl' and (compiler .target in {'x86' , 'i686' }):
@@ -869,7 +876,12 @@ def create_new_coredata(self, options: coredata.SharedCMDOptions) -> None:
869876 # re-initialized with project options by the interpreter during
870877 # build file parsing.
871878 # meson_command is used by the regenchecker script, which runs meson
872- self .coredata = coredata .CoreData (options , self .scratch_dir , mesonlib .get_meson_command ())
879+ meson_command = mesonlib .get_meson_command ()
880+ if meson_command is None :
881+ meson_command = []
882+ else :
883+ meson_command = meson_command .copy ()
884+ self .coredata = coredata .CoreData (options , self .scratch_dir , meson_command )
873885 self .first_invocation = True
874886
875887 def is_cross_build (self , when_building_for : MachineChoice = MachineChoice .HOST ) -> bool :
@@ -950,25 +962,25 @@ def get_static_lib_dir(self) -> str:
950962 return self .get_libdir ()
951963
952964 def get_prefix (self ) -> str :
953- return self .coredata .get_option (OptionKey ('prefix' ))
965+ return _as_str ( self .coredata .get_option (OptionKey ('prefix' ) ))
954966
955967 def get_libdir (self ) -> str :
956- return self .coredata .get_option (OptionKey ('libdir' ))
968+ return _as_str ( self .coredata .get_option (OptionKey ('libdir' ) ))
957969
958970 def get_libexecdir (self ) -> str :
959- return self .coredata .get_option (OptionKey ('libexecdir' ))
971+ return _as_str ( self .coredata .get_option (OptionKey ('libexecdir' ) ))
960972
961973 def get_bindir (self ) -> str :
962- return self .coredata .get_option (OptionKey ('bindir' ))
974+ return _as_str ( self .coredata .get_option (OptionKey ('bindir' ) ))
963975
964976 def get_includedir (self ) -> str :
965- return self .coredata .get_option (OptionKey ('includedir' ))
977+ return _as_str ( self .coredata .get_option (OptionKey ('includedir' ) ))
966978
967979 def get_mandir (self ) -> str :
968- return self .coredata .get_option (OptionKey ('mandir' ))
980+ return _as_str ( self .coredata .get_option (OptionKey ('mandir' ) ))
969981
970982 def get_datadir (self ) -> str :
971- return self .coredata .get_option (OptionKey ('datadir' ))
983+ return _as_str ( self .coredata .get_option (OptionKey ('datadir' ) ))
972984
973985 def get_compiler_system_lib_dirs (self , for_machine : MachineChoice ) -> T .List [str ]:
974986 for comp in self .coredata .compilers [for_machine ].values ():
@@ -986,8 +998,8 @@ def get_compiler_system_lib_dirs(self, for_machine: MachineChoice) -> T.List[str
986998 p , out , _ = Popen_safe (comp .get_exelist () + ['-print-search-dirs' ])
987999 if p .returncode != 0 :
9881000 raise mesonlib .MesonException ('Could not calculate system search dirs' )
989- out = out .split ('\n ' )[index ].lstrip ('libraries: =' ).split (':' )
990- return [os .path .normpath (p ) for p in out ]
1001+ split = out .split ('\n ' )[index ].lstrip ('libraries: =' ).split (':' )
1002+ return [os .path .normpath (p ) for p in split ]
9911003
9921004 def get_compiler_system_include_dirs (self , for_machine : MachineChoice ) -> T .List [str ]:
9931005 for comp in self .coredata .compilers [for_machine ].values ():
@@ -1016,7 +1028,7 @@ def get_exe_wrapper(self) -> T.Optional[ExternalProgram]:
10161028 return self .exe_wrapper
10171029
10181030 def has_exe_wrapper (self ) -> bool :
1019- return self .exe_wrapper and self .exe_wrapper .found ()
1031+ return self .exe_wrapper is not None and self .exe_wrapper .found ()
10201032
10211033 def get_env_for_paths (self , library_paths : T .Set [str ], extra_paths : T .Set [str ]) -> mesonlib .EnvironmentVariables :
10221034 env = mesonlib .EnvironmentVariables ()
0 commit comments