diff --git a/mesonbuild/build.py b/mesonbuild/build.py index b9a3dc29d..bd6661bc3 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -255,7 +255,7 @@ class Build: self.test_setups: T.Dict[str, TestSetup] = {} self.test_setup_default_name = None self.find_overrides: T.Dict[str, T.Union['Executable', programs.ExternalProgram, programs.OverrideProgram]] = {} - self.searched_programs = set() # The list of all programs that have been searched for. + self.searched_programs: T.Set[str] = set() # The list of all programs that have been searched for. # If we are doing a cross build we need two caches, if we're doing a # build == host compilation the both caches should point to the same place. @@ -292,7 +292,7 @@ class Build: for k, v in other.__dict__.items(): self.__dict__[k] = v - def ensure_static_linker(self, compiler): + def ensure_static_linker(self, compiler: Compiler) -> None: if self.static_linker[compiler.for_machine] is None and compiler.needs_static_linker(): self.static_linker[compiler.for_machine] = detect_static_linker(self.environment, compiler) diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py index 397ea92f5..9f1271900 100644 --- a/mesonbuild/interpreter/interpreter.py +++ b/mesonbuild/interpreter/interpreter.py @@ -1393,7 +1393,8 @@ external dependencies (including libraries) must go to "dependencies".''') return success - def program_from_file_for(self, for_machine, prognames): + def program_from_file_for(self, for_machine: MachineChoice, prognames: T.List[mesonlib.FileOrString] + ) -> T.Optional[ExternalProgram]: for p in prognames: if isinstance(p, mesonlib.File): continue # Always points to a local (i.e. self generated) file. @@ -1404,7 +1405,8 @@ external dependencies (including libraries) must go to "dependencies".''') return prog return None - def program_from_system(self, args, search_dirs, extra_info): + def program_from_system(self, args: T.List[mesonlib.FileOrString], search_dirs: T.List[str], + extra_info: T.List[mlog.TV_Loggable]) -> T.Optional[ExternalProgram]: # Search for scripts relative to current subdir. # Do not cache found programs because find_program('foobar') # might give different results when run from different source dirs. @@ -1430,9 +1432,11 @@ external dependencies (including libraries) must go to "dependencies".''') if extprog.found(): extra_info.append(f"({' '.join(extprog.get_command())})") return extprog + return None - def program_from_overrides(self, command_names: T.List[str], extra_info: T.List['mlog.TV_Loggable']) -> \ - T.Optional[T.Union[ExternalProgram, 'OverrideProgram', 'build.Executable']]: + def program_from_overrides(self, command_names: T.List[mesonlib.FileOrString], + extra_info: T.List['mlog.TV_Loggable'] + ) -> T.Optional[T.Union[ExternalProgram, OverrideProgram, build.Executable]]: for name in command_names: if not isinstance(name, str): continue @@ -1442,7 +1446,7 @@ external dependencies (including libraries) must go to "dependencies".''') return exe return None - def store_name_lookups(self, command_names): + def store_name_lookups(self, command_names: T.List[mesonlib.FileOrString]) -> None: for name in command_names: if isinstance(name, str): self.build.searched_programs.add(name) @@ -1470,7 +1474,7 @@ external dependencies (including libraries) must go to "dependencies".''') ) -> T.Union['ExternalProgram', 'build.Executable', 'OverrideProgram']: args = mesonlib.listify(args) - extra_info = [] + extra_info: T.List[mlog.TV_Loggable] = [] progobj = self.program_lookup(args, for_machine, required, search_dirs, extra_info) if progobj is None: progobj = self.notfound_program(args) @@ -1487,14 +1491,15 @@ external dependencies (including libraries) must go to "dependencies".''') if version_func: version = version_func(progobj) elif isinstance(progobj, build.Executable): - interp = self if progobj.subproject: interp = self.subprojects[progobj.subproject].held_object - assert isinstance(interp, Interpreter) + else: + interp = self + assert isinstance(interp, Interpreter) version = interp.project_version else: version = progobj.get_version(self) - is_found, not_found, found = mesonlib.version_compare_many(version, wanted) + is_found, not_found, _ = mesonlib.version_compare_many(version, wanted) if not is_found: mlog.log('Program', mlog.bold(progobj.name), 'found:', mlog.red('NO'), 'found', mlog.normal_cyan(version), 'but need:', @@ -1513,7 +1518,9 @@ external dependencies (including libraries) must go to "dependencies".''') progobj.was_returned_by_find_program = True return progobj - def program_lookup(self, args, for_machine, required: bool, search_dirs, extra_info): + def program_lookup(self, args: T.List[mesonlib.FileOrString], for_machine: MachineChoice, + required: bool, search_dirs: T.List[str], extra_info: T.List[mlog.TV_Loggable] + ) -> T.Optional[T.Union[ExternalProgram, build.Executable, OverrideProgram]]: progobj = self.program_from_overrides(args, extra_info) if progobj: return progobj @@ -1536,7 +1543,9 @@ external dependencies (including libraries) must go to "dependencies".''') return progobj - def find_program_fallback(self, fallback: str, args, required: bool, extra_info): + def find_program_fallback(self, fallback: str, args: T.List[mesonlib.FileOrString], + required: bool, extra_info: T.List[mlog.TV_Loggable] + ) -> T.Optional[T.Union[ExternalProgram, build.Executable, OverrideProgram]]: mlog.log('Fallback to subproject', mlog.bold(fallback), 'which provides program', mlog.bold(' '.join(args))) sp_kwargs: kwargs.DoSubproject = {