From db0bcd06477c1331e9b204e5dc354216848a314e Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 6 Jan 2022 14:53:31 -0800 Subject: [PATCH 01/17] build: Fix annotations to RunTarget and AliasTarget RunTargets and AliasTargets may depend on RunTargets, so annotate them that way. The Gnome module relies on this internally. --- mesonbuild/build.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 93bf29d9d90a..aaae7247a260 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -2610,7 +2610,7 @@ class RunTarget(Target, CommandBase): def __init__(self, name: str, command: T.Sequence[T.Union[str, File, BuildTarget, 'CustomTarget', 'CustomTargetIndex', programs.ExternalProgram]], - dependencies: T.Sequence[T.Union[BuildTarget, 'CustomTarget']], + dependencies: T.Sequence[Target], subdir: str, subproject: str, env: T.Optional['EnvironmentVariables'] = None): @@ -2654,7 +2654,7 @@ def type_suffix(self) -> str: return "@run" class AliasTarget(RunTarget): - def __init__(self, name: str, dependencies: T.Sequence[T.Union[BuildTarget, 'CustomTarget']], + def __init__(self, name: str, dependencies: T.Sequence['Target'], subdir: str, subproject: str): super().__init__(name, [], dependencies, subdir, subproject) From d05934dc86506f01bc1ec9d5205b767c01ffa9ef Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:09:08 -0800 Subject: [PATCH 02/17] modules/gnome: define and annotate all instance variables in the initializer --- mesonbuild/modules/gnome.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 78e09e6d1c79..7b8097f63247 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -255,12 +255,14 @@ def annotations_validator(annotations: T.List[T.Union[str, T.List[str]]]) -> T.O class GnomeModule(ExtensionModule): def __init__(self, interpreter: 'Interpreter') -> None: super().__init__(interpreter) - self.gir_dep = None + self.gir_dep: T.Optional[Dependency] = None + self.giscanner: T.Optional[T.Union[ExternalProgram, build.Executable, OverrideProgram]] = None + self.gicompiler: T.Optional[T.Union[ExternalProgram, build.Executable, OverrideProgram]] = None self.install_glib_compile_schemas = False - self.install_gio_querymodules = [] + self.install_gio_querymodules: T.List[str] = [] self.install_gtk_update_icon_cache = False self.install_update_desktop_database = False - self.devenv = None + self.devenv: T.Optional[build.EnvironmentVariables] = None self.methods.update({ 'post_install': self.post_install, 'compile_resources': self.compile_resources, From 97385b81645f5e3d319f1692635ab1d96cff6466 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:14:45 -0800 Subject: [PATCH 03/17] modules/gnome: fix type annotations and issues with _gather_typelib_includes_and_update_depends There is the problem of the annotations themselves, then there is the problem with depends being mutated. The mutation side effect is a problem in itself, but there's also the problem that we really want to use Sequence, which isn't mutable. --- mesonbuild/modules/gnome.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 7b8097f63247..211d1f2171d5 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -943,19 +943,23 @@ def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, typeli return TypelibTarget(typelib_output, state.subdir, state.subproject, typelib_kwargs) - # May mutate depends - def _gather_typelib_includes_and_update_depends(self, state: 'ModuleState', deps: T.List[Dependency], depends: T.List[build.Target]) -> T.List[str]: + def _gather_typelib_includes_and_update_depends( + self, state: 'ModuleState', + deps: T.Sequence[T.Union[Dependency, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]], + depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']] + ) -> T.Tuple[T.List[str], T.List[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']]]: # Need to recursively add deps on GirTarget sources from our # dependencies and also find the include directories needed for the # typelib generation custom target below. typelib_includes: T.List[str] = [] + new_depends = list(depends) for dep in deps: # Add a dependency on each GirTarget listed in dependencies and add # the directory where it will be generated to the typelib includes if isinstance(dep, InternalDependency): for source in dep.sources: if isinstance(source, GirTarget) and source not in depends: - depends.append(source) + new_depends.append(source) subdir = os.path.join(state.environment.get_build_dir(), source.get_subdir()) if subdir not in typelib_includes: @@ -977,7 +981,7 @@ def _gather_typelib_includes_and_update_depends(self, state: 'ModuleState', deps assert isinstance(girdir, str), 'for mypy' if girdir and girdir not in typelib_includes: typelib_includes.append(girdir) - return typelib_includes + return typelib_includes, new_depends def _get_external_args_for_langs(self, state: 'ModuleState', langs: T.Sequence[str]) -> T.List[str]: ret: T.List[str] = [] @@ -1053,7 +1057,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. deps = self._get_gir_targets_deps(girtargets) deps += kwargs['dependencies'] deps += [gir_dep] - typelib_includes = self._gather_typelib_includes_and_update_depends(state, deps, depends) + typelib_includes, depends = self._gather_typelib_includes_and_update_depends(state, deps, depends) # ldflags will be misinterpreted by gir scanner (showing # spurious dependencies) but building GStreamer fails if they # are not used here. From 01f01c162759daff66352de39b1dff8d18c715c2 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:18:03 -0800 Subject: [PATCH 04/17] modules/gnome: ignore the return type of _get_dep This is hard to fix, and it's really doing something bad anyway. But we know it's right, so just tell mypy to not worry about it. --- mesonbuild/modules/gnome.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 211d1f2171d5..1bf2d37d53cd 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -310,7 +310,10 @@ def _print_gdbus_warning() -> None: def _get_dep(self, state: 'ModuleState', depname: str, native: bool = False, required: bool = True) -> Dependency: kwargs = {'native': native, 'required': required} - return self.interpreter.func_dependency(state.current_node, [depname], kwargs) + # FIXME: Even if we fix the function, mypy still can't figure out what's + # going on here. And we really dont want to call interpreter + # implementations of meson functions anyway. + return self.interpreter.func_dependency(state.current_node, [depname], kwargs) # type: ignore def _get_native_binary(self, state: 'ModuleState', name: str, depname: str, varname: str, required: bool = True) -> T.Union[ExternalProgram, OverrideProgram, 'build.Executable']: @@ -1048,7 +1051,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. srcdir = os.path.join(state.environment.get_source_dir(), state.subdir) builddir = os.path.join(state.environment.get_build_dir(), state.subdir) - depends: T.List[T.Union['FileOrString', build.GeneratedTypes, build.Executable, build.SharedLibrary, build.StaticLibrary]] = [] + depends: T.List[T.Union['FileOrString', 'build.GeneratedTypes', build.BuildTarget]] = [] depends.extend(gir_dep.sources) depends.extend(girtargets) From 4ada3673a6654bb75a73f78d20329cc395d7677c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:20:59 -0800 Subject: [PATCH 05/17] dependencies: fix libraries and whole_libraries types gnome points out that CustomTargets can be linked with, so we should allow that. --- mesonbuild/dependencies/base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mesonbuild/dependencies/base.py b/mesonbuild/dependencies/base.py index 6881a34af8d5..e610a6f431f8 100644 --- a/mesonbuild/dependencies/base.py +++ b/mesonbuild/dependencies/base.py @@ -29,7 +29,7 @@ if T.TYPE_CHECKING: from ..compilers.compilers import Compiler from ..environment import Environment - from ..build import BuildTarget, CustomTarget + from ..build import BuildTarget, CustomTarget, IncludeDirs from ..mesonlib import FileOrString @@ -216,9 +216,10 @@ def generate_system_dependency(self, include_type: str) -> 'Dependency': return new_dep class InternalDependency(Dependency): - def __init__(self, version: str, incdirs: T.List[str], compile_args: T.List[str], - link_args: T.List[str], libraries: T.List['BuildTarget'], - whole_libraries: T.List['BuildTarget'], + def __init__(self, version: str, incdirs: T.List['IncludeDirs'], compile_args: T.List[str], + link_args: T.List[str], + libraries: T.List[T.Union['BuildTarget', 'CustomTarget']], + whole_libraries: T.List[T.Union['BuildTarget', 'CustomTarget']], sources: T.Sequence[T.Union['FileOrString', 'CustomTarget']], ext_deps: T.List[Dependency], variables: T.Dict[str, T.Any]): super().__init__(DependencyTypeName('internal'), {}) From 0c853a259133c3e7a08984467b0a3abf8fb7089f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:24:59 -0800 Subject: [PATCH 06/17] modules/gnome: use itertools.chain instead of list concatenation This is better as it avoids building unnecessary lists, and two fixes the typing issue from concatenating lists of different types. --- mesonbuild/modules/gnome.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 1bf2d37d53cd..55cb569b533a 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -16,6 +16,7 @@ functionality such as gobject-introspection, gresources and gtk-doc''' import copy +import itertools import functools import os import subprocess @@ -1106,7 +1107,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. scan_command += scan_cflags scan_command += ['--cflags-end'] scan_command += state.get_include_args(inc_dirs) - scan_command += state.get_include_args(list(gi_includes) + gir_inc_dirs + inc_dirs, prefix='--add-include-path=') + scan_command += state.get_include_args(itertools.chain(gi_includes, gir_inc_dirs, inc_dirs), prefix='--add-include-path=') scan_command += list(scan_internal_ldflags) scan_command += self._scan_gir_targets(state, girtargets) scan_command += self._scan_langs(state, [lc[0] for lc in langs_compilers]) From 669208841d889e09cee7226c9ace4f09edee9e20 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:26:21 -0800 Subject: [PATCH 07/17] modules/gnome: use T.Sequence instead of T.List Which is pretty much necessary to make anything involving unions of lists work --- mesonbuild/modules/gnome.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 55cb569b533a..c330c39bb284 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1795,7 +1795,8 @@ def _make_mkenum_impl( *, install: bool = False, install_dir: T.Optional[T.Sequence[T.Union[str, bool]]] = None, - depends: T.Optional[T.List[CustomTarget]] = None) -> build.CustomTarget: + depends: T.Optional[T.Sequence[T.Union[CustomTarget, CustomTargetIndex, BuildTarget]]] = None + ) -> build.CustomTarget: real_cmd: T.List[T.Union[str, ExternalProgram]] = [state.find_program(['glib-mkenums', 'mkenums'])] real_cmd.extend(cmd) custom_kwargs = { @@ -1805,7 +1806,7 @@ def _make_mkenum_impl( 'command': real_cmd, 'install': install, 'install_dir': install_dir or state.environment.coredata.get_option(mesonlib.OptionKey('includedir')), - 'depends': depends or [], + 'depends': list(depends or []), } return build.CustomTarget(output, state.subdir, state.subproject, custom_kwargs, # https://github.com/mesonbuild/meson/issues/973 From 0d236861e24f9b3d8e4a408ebda8e150112c1527 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:28:09 -0800 Subject: [PATCH 08/17] modules/gnome: fix declared type of list --- mesonbuild/modules/gnome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index c330c39bb284..fdc36eb8936a 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1958,7 +1958,7 @@ def _get_vapi_link_with(self, target: build.CustomTarget) -> T.List[T.Union[buil KwargInfo('packages', ContainerTypeInfo(list, (str, InternalDependency)), listify=True, default=[]), ) def generate_vapi(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GenerateVapi') -> ModuleReturnValue: - created_values: T.List[Dependency] = [] + created_values: T.List[T.Union[Dependency, build.Data]] = [] library = args[0] build_dir = os.path.join(state.environment.get_build_dir(), state.subdir) source_dir = os.path.join(state.environment.get_source_dir(), state.subdir) From 212096dd745e0a510b37bc1e5242ee0564cbcb98 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Sat, 4 Dec 2021 21:33:33 -0800 Subject: [PATCH 09/17] modules/gnome: fix issues with _make_gir_target --- mesonbuild/modules/gnome.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index fdc36eb8936a..d136509dd059 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -30,7 +30,7 @@ from .. import interpreter from .. import mesonlib from .. import mlog -from ..build import BuildTarget, CustomTarget, CustomTargetIndex, GeneratedList, InvalidArguments +from ..build import BuildTarget, CustomTarget, CustomTargetIndex, Executable, GeneratedList, InvalidArguments from ..dependencies import Dependency, PkgConfigDependency, InternalDependency from ..interpreter.type_checking import DEPENDS_KW, DEPEND_FILES_KW, INSTALL_KW, NoneType, in_set_validator from ..interpreterbase import noPosargs, noKwargs, FeatureNew, FeatureDeprecated @@ -896,9 +896,14 @@ def _make_gir_filelist(self, state: 'ModuleState', srcdir: str, ns: str, return gir_filelist_filename - def _make_gir_target(self, state: 'ModuleState', girfile: str, scan_command: T.List[str], - generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], - depends: T.List[build.Target], kwargs: T.Dict[str, T.Any]) -> GirTarget: + def _make_gir_target( + self, + state: 'ModuleState', + girfile: str, + scan_command: T.Sequence[T.Union['FileOrString', Executable, ExternalProgram, OverrideProgram]], + generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], + depends: T.Sequence[T.Union['FileOrString', build.BuildTarget, 'build.GeneratedTypes']], + kwargs: T.Dict[str, T.Any]) -> GirTarget: install = kwargs['install_gir'] if install is None: install = kwargs['install'] @@ -1125,7 +1130,10 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. generated_files = [f for f in libsources if isinstance(f, (GeneratedList, CustomTarget, CustomTargetIndex))] - scan_target = self._make_gir_target(state, girfile, scan_command, generated_files, depends, kwargs) + scan_target = self._make_gir_target( + state, girfile, scan_command, generated_files, depends, + # We have to cast here because mypy can't figure this out + T.cast(T.Dict[str, T.Any], kwargs)) typelib_output = f'{ns}-{nsversion}.typelib' typelib_cmd = [gicompiler, scan_target, '--output', '@OUTPUT@'] From e805f6cd1379521d15d28a1c669dc5b5bcbc48e9 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 12:54:52 -0800 Subject: [PATCH 10/17] build: Fix return types of a couple of methods These don't return `Target`, they return `BuildTarget | CustomTarget | CustomTargetIndex` --- mesonbuild/backend/backends.py | 2 +- mesonbuild/build.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 957b259e7eff..e43c8c76cba7 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -1058,7 +1058,7 @@ def determine_windows_extra_paths( tests. """ result: T.Set[str] = set() - prospectives: T.Set[build.Target] = set() + prospectives: T.Set[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]] = set() if isinstance(target, build.BuildTarget): prospectives.update(target.get_transitive_link_deps()) # External deps diff --git a/mesonbuild/build.py b/mesonbuild/build.py index aaae7247a260..fb650e8547a7 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -1001,11 +1001,11 @@ def extract_all_objects(self, recursive: bool = True) -> ExtractedObjects: return ExtractedObjects(self, self.sources, self.generated, self.objects, recursive) - def get_all_link_deps(self) -> 'ImmutableListProtocol[Target]': + def get_all_link_deps(self) -> 'ImmutableListProtocol[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]': return self.get_transitive_link_deps() @lru_cache(maxsize=None) - def get_transitive_link_deps(self) -> 'ImmutableListProtocol[Target]': + def get_transitive_link_deps(self) -> 'ImmutableListProtocol[T.Union[BuildTarget, CustomTarget, CustomTargetIndex]]': result: T.List[Target] = [] for i in self.link_targets: result += i.get_all_link_deps() From 2098a11f41b2addc669fa26050441f60f86228a3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 12:56:42 -0800 Subject: [PATCH 11/17] modules/gnome: Fix typing with _get_dependencies_flags and _get_gir_target_deps The typing issues with these are tightly intertwined, so it didn't really make sense to solve them independently --- mesonbuild/modules/gnome.py | 42 ++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index d136509dd059..360daa8a5c5d 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -596,17 +596,19 @@ def _get_gresource_dependencies( def _get_link_args(self, state: 'ModuleState', lib: T.Union[build.SharedLibrary, build.StaticLibrary], - depends: T.List[build.BuildTarget], + depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']], include_rpath: bool = False, - use_gir_args: bool = False) -> T.List[str]: + use_gir_args: bool = False + ) -> T.Tuple[T.List[str], T.List[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']]]: link_command: T.List[str] = [] + new_depends = list(depends) # Construct link args if isinstance(lib, build.SharedLibrary): libdir = os.path.join(state.environment.get_build_dir(), state.backend.get_target_dir(lib)) link_command.append('-L' + libdir) if include_rpath: link_command.append('-Wl,-rpath,' + libdir) - depends.append(lib) + new_depends.append(lib) # Needed for the following binutils bug: # https://github.com/mesonbuild/meson/issues/1911 # However, g-ir-scanner does not understand -Wl,-rpath @@ -620,13 +622,17 @@ def _get_link_args(self, state: 'ModuleState', link_command.append('--extra-library=' + lib.name) else: link_command.append('-l' + lib.name) - return link_command + return link_command, new_depends def _get_dependencies_flags( - self, deps: T.Sequence[T.Union['Dependency', build.SharedLibrary, build.StaticLibrary]], - state: 'ModuleState', depends: T.List[build.BuildTarget], include_rpath: bool = False, - use_gir_args: bool = False, separate_nodedup: bool = False - ) -> T.Tuple[OrderedSet[str], OrderedSet[str], OrderedSet[str], T.Optional[T.List[str]], OrderedSet[str]]: + self, deps: T.Sequence[T.Union['Dependency', build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]], + state: 'ModuleState', + depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']], + include_rpath: bool = False, + use_gir_args: bool = False, + separate_nodedup: bool = False + ) -> T.Tuple[OrderedSet[str], OrderedSet[str], OrderedSet[str], T.Optional[T.List[str]], OrderedSet[str], + T.List[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']]]: cflags: OrderedSet[str] = OrderedSet() internal_ldflags: OrderedSet[str] = OrderedSet() external_ldflags: OrderedSet[str] = OrderedSet() @@ -635,6 +641,7 @@ def _get_dependencies_flags( external_ldflags_nodedup: T.List[str] = [] gi_includes: OrderedSet[str] = OrderedSet() deps = mesonlib.listify(deps) + depends = list(depends) for dep in deps: if isinstance(dep, Dependency): @@ -647,7 +654,8 @@ def _get_dependencies_flags( cflags.update(state.get_include_args(dep.include_directories)) for lib in dep.libraries: if isinstance(lib, build.SharedLibrary): - internal_ldflags.update(self._get_link_args(state, lib, depends, include_rpath)) + _ld, depends = self._get_link_args(state, lib, depends, include_rpath) + internal_ldflags.update(_ld) libdepflags = self._get_dependencies_flags(lib.get_external_deps(), state, depends, include_rpath, use_gir_args, True) cflags.update(libdepflags[0]) @@ -711,9 +719,9 @@ def fix_ldflags(ldflags: T.Iterable[str]) -> OrderedSet[str]: external_ldflags = fix_ldflags(external_ldflags) if not separate_nodedup: external_ldflags.update(external_ldflags_nodedup) - return cflags, internal_ldflags, external_ldflags, None, gi_includes + return cflags, internal_ldflags, external_ldflags, None, gi_includes, depends else: - return cflags, internal_ldflags, external_ldflags, external_ldflags_nodedup, gi_includes + return cflags, internal_ldflags, external_ldflags, external_ldflags_nodedup, gi_includes, depends def _unwrap_gir_target(self, girtarget: T.Union[build.Executable, build.StaticLibrary, build.SharedLibrary], state: 'ModuleState' ) -> T.Union[build.Executable, build.StaticLibrary, build.SharedLibrary]: @@ -827,8 +835,8 @@ def _get_girtargets_langs_compilers(self, girtargets: T.Sequence[build.BuildTarg return ret def _get_gir_targets_deps(self, girtargets: T.Sequence[build.BuildTarget] - ) -> T.List[T.Union[build.Target, Dependency]]: - ret: T.List[T.Union[build.Target, Dependency]] = [] + ) -> T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, Dependency]]: + ret: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, Dependency]] = [] for girtarget in girtargets: ret += girtarget.get_all_link_deps() ret += girtarget.get_external_deps() @@ -979,10 +987,10 @@ def _gather_typelib_includes_and_update_depends( # FIXME: Store this in the original form from declare_dependency() # so it can be used here directly. elif isinstance(dep, build.SharedLibrary): - for source in dep.generated: - if isinstance(source, GirTarget): + for g_source in dep.generated: + if isinstance(g_source, GirTarget): subdir = os.path.join(state.environment.get_build_dir(), - source.get_subdir()) + g_source.get_subdir()) if subdir not in typelib_includes: typelib_includes.append(subdir) if isinstance(dep, Dependency): @@ -1070,7 +1078,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. # ldflags will be misinterpreted by gir scanner (showing # spurious dependencies) but building GStreamer fails if they # are not used here. - dep_cflags, dep_internal_ldflags, dep_external_ldflags, _, gi_includes = \ + dep_cflags, dep_internal_ldflags, dep_external_ldflags, _, gi_includes, depends = \ self._get_dependencies_flags(deps, state, depends, use_gir_args=True) scan_cflags = [] scan_cflags += list(self._get_scanner_cflags(cflags)) From 53a885bf33114065f18ab9df5e32ba406384f960 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 13:00:59 -0800 Subject: [PATCH 12/17] modules/gnome: fix _make_typelib_target types --- mesonbuild/modules/gnome.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 360daa8a5c5d..c623f0c8d86c 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -935,7 +935,8 @@ def _make_gir_target( return GirTarget(girfile, state.subdir, state.subproject, scankwargs) - def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, typelib_cmd: T.List[str], + def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, + typelib_cmd: T.Sequence[T.Union[str, build.Executable, ExternalProgram, build.CustomTarget]], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], kwargs: T.Dict[str, T.Any]) -> TypelibTarget: install = kwargs['install_typelib'] @@ -951,7 +952,7 @@ def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, typeli typelib_kwargs = { 'input': generated_files, 'output': [typelib_output], - 'command': typelib_cmd, + 'command': list(typelib_cmd), 'install': install, 'install_dir': install_dir, 'install_tag': 'typelib', @@ -1150,7 +1151,7 @@ def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build. for incdir in typelib_includes: typelib_cmd += ["--includedir=" + incdir] - typelib_target = self._make_typelib_target(state, typelib_output, typelib_cmd, generated_files, kwargs) + typelib_target = self._make_typelib_target(state, typelib_output, typelib_cmd, generated_files, T.cast(T.Dict[str, T.Any], kwargs)) self._devenv_prepend('GI_TYPELIB_PATH', os.path.join(state.environment.get_build_dir(), state.subdir)) From 559aed5297161c94445218d83523b8fa3c40f6df Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 13:02:47 -0800 Subject: [PATCH 13/17] modules/gnome: fix _get_build_args type annotations --- mesonbuild/modules/gnome.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index c623f0c8d86c..df16a4f1a7b2 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1437,7 +1437,8 @@ def abs_filenames(files: T.Iterable['FileOrString']) -> T.Iterator[str]: def _get_build_args(self, c_args: T.List[str], inc_dirs: T.List[T.Union[str, build.IncludeDirs]], deps: T.List[T.Union[Dependency, build.SharedLibrary, build.StaticLibrary]], - state: 'ModuleState', depends: T.List[build.BuildTarget]) -> T.List[str]: + state: 'ModuleState', + depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes']]) -> T.List[str]: args: T.List[str] = [] cflags = c_args.copy() deps_cflags, internal_ldflags, external_ldflags, *_ = \ From 02382ec420cd329d1beed55fccab0fac4e541e18 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 6 Jan 2022 14:46:20 -0800 Subject: [PATCH 14/17] modules/gnome: fix annotation to type that isn't defined --- mesonbuild/modules/gnome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index df16a4f1a7b2..acec400acbfd 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1213,7 +1213,7 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y media = kwargs['media'] symlinks = kwargs['symlink_media'] - targets: T.List[T.Union['Target', build.Data, build.SymlinkData]] = [] + targets: T.List[T.Union['build.Target', build.Data, build.SymlinkData]] = [] potargets: T.List[build.RunTarget] = [] itstool = state.find_program('itstool') From 10ecdb7fe2849910a24585b5fc3c823cd868f105 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 13:12:44 -0800 Subject: [PATCH 15/17] modules/gnome: fix remaining typing errors Which is one incorrect type annotation, and a couple of instances of concatenating lists of unlike types. List being invariant is super annoying. --- mesonbuild/modules/gnome.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index acec400acbfd..b12215295ab4 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1238,7 +1238,8 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y pot_file = os.path.join('@SOURCE_ROOT@', state.subdir, 'C', project_id + '.pot') pot_sources = [os.path.join('@SOURCE_ROOT@', state.subdir, 'C', s) for s in sources] - pot_args = [itstool, '-o', pot_file] + pot_sources + pot_args: T.List[T.Union['ExternalProgram', str]] = [itstool, '-o', pot_file] + pot_args.extend(pot_sources) pottarget = build.RunTarget(f'help-{project_id}-pot', pot_args, [], os.path.join(state.subdir, 'C'), state.subproject) targets.append(pottarget) @@ -1250,6 +1251,7 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y for i, m in enumerate(media): m_dir = os.path.dirname(m) m_install_dir = os.path.join(l_install_dir, m_dir) + l_data: T.Union[build.Data, build.SymlinkData] if symlinks: link_target = os.path.join(os.path.relpath(c_install_dir, start=m_install_dir), m) l_data = build.SymlinkData(link_target, os.path.basename(m), @@ -1264,9 +1266,10 @@ def yelp(self, state: 'ModuleState', args: T.Tuple[str, T.List[str]], kwargs: 'Y targets.append(l_data) po_file = l + '.po' - po_args = [msgmerge, '-q', '-o', - os.path.join('@SOURCE_ROOT@', l_subdir, po_file), - os.path.join('@SOURCE_ROOT@', l_subdir, po_file), pot_file] + po_args: T.List[T.Union['ExternalProgram', str]] = [ + msgmerge, '-q', '-o', + os.path.join('@SOURCE_ROOT@', l_subdir, po_file), + os.path.join('@SOURCE_ROOT@', l_subdir, po_file), pot_file] potarget = build.RunTarget(f'help-{project_id}-{l}-update-po', po_args, [pottarget], l_subdir, state.subproject) targets.append(potarget) @@ -1663,7 +1666,8 @@ def mkenums(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'MkEnums') - # We always set template as the first element in the source array # so --template consumes it. h_cmd = cmd + ['--template', '@INPUT@'] - h_sources = [h_template] + kwargs['sources'] + h_sources: T.List[T.Union[FileOrString, 'build.GeneratedTypes']] = [h_template] + h_sources.extend(kwargs['sources']) h_target = self._make_mkenum_impl( state, h_sources, h_output, h_cmd, install=kwargs['install_header'], install_dir=kwargs['install_dir']) @@ -1674,7 +1678,8 @@ def mkenums(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'MkEnums') - # We always set template as the first element in the source array # so --template consumes it. c_cmd = cmd + ['--template', '@INPUT@'] - c_sources = [c_template] + kwargs['sources'] + c_sources: T.List[T.Union[FileOrString, 'build.GeneratedTypes']] = [c_template] + c_sources.extend(kwargs['sources']) depends = kwargs['depends'].copy() if h_target is not None: @@ -1903,7 +1908,7 @@ def genmarshal(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'GenMarsh return ModuleReturnValue(rv, rv) def _extract_vapi_packages(self, state: 'ModuleState', packages: T.List[T.Union[InternalDependency, str]], - ) -> T.Tuple[T.List[str], T.List[build.Target], T.List[str], T.List[str], T.List[str]]: + ) -> T.Tuple[T.List[str], T.List[VapiTarget], T.List[str], T.List[str], T.List[str]]: ''' Packages are special because we need to: - Get a list of packages for the .deps file @@ -1913,7 +1918,7 @@ def _extract_vapi_packages(self, state: 'ModuleState', packages: T.List[T.Union[ ''' if not packages: return [], [], [], [], [] - vapi_depends: T.List[build.Target] = [] + vapi_depends: T.List[VapiTarget] = [] vapi_packages: T.List[str] = [] vapi_includes: T.List[str] = [] vapi_args: T.List[str] = [] From cb2267fe4de45be1aa0f516a3353d6ee56513b9f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 6 Dec 2021 13:13:59 -0800 Subject: [PATCH 16/17] run_mypy: add gnome module --- run_mypy.py | 1 + 1 file changed, 1 insertion(+) diff --git a/run_mypy.py b/run_mypy.py index 1c2759a52e98..00d490bab9cd 100755 --- a/run_mypy.py +++ b/run_mypy.py @@ -41,6 +41,7 @@ 'mesonbuild/mlog.py', 'mesonbuild/msubprojects.py', 'mesonbuild/modules/fs.py', + 'mesonbuild/modules/gnome.py', 'mesonbuild/modules/i18n.py', 'mesonbuild/modules/java.py', 'mesonbuild/modules/keyval.py', From 26e87bc5ee845bdc02f83d9ebf0d2d7805f2d144 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 8 Dec 2021 10:11:50 -0800 Subject: [PATCH 17/17] modules/gnome: make some methods static Since they don't use the instance or class state, they should be static methods. --- mesonbuild/modules/gnome.py | 38 ++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index b12215295ab4..9435c5d4aa99 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -521,8 +521,9 @@ def compile_resources(self, state: 'ModuleState', args: T.Tuple[str, 'FileOrStri rv = [target_c, target_h] return ModuleReturnValue(rv, rv) + @staticmethod def _get_gresource_dependencies( - self, state: 'ModuleState', input_file: str, source_dirs: T.List[str], + state: 'ModuleState', input_file: str, source_dirs: T.List[str], dependencies: T.Sequence[T.Union[mesonlib.File, build.CustomTarget, build.CustomTargetIndex]] ) -> T.Tuple[T.List[mesonlib.FileOrString], T.List[T.Union[build.CustomTarget, build.CustomTargetIndex]], T.List[str]]: @@ -763,7 +764,8 @@ def _gir_has_option(self, option: str) -> bool: return p.returncode == 0 and option in o # May mutate depends and gir_inc_dirs - def _scan_include(self, state: 'ModuleState', includes: T.List[T.Union[str, GirTarget]] + @staticmethod + def _scan_include(state: 'ModuleState', includes: T.List[T.Union[str, GirTarget]] ) -> T.Tuple[T.List[str], T.List[str], T.List[GirTarget]]: ret: T.List[str] = [] gir_inc_dirs: T.List[str] = [] @@ -779,7 +781,8 @@ def _scan_include(self, state: 'ModuleState', includes: T.List[T.Union[str, GirT return ret, gir_inc_dirs, depends - def _scan_langs(self, state: 'ModuleState', langs: T.Iterable[str]) -> T.List[str]: + @staticmethod + def _scan_langs(state: 'ModuleState', langs: T.Iterable[str]) -> T.List[str]: ret: T.List[str] = [] for lang in langs: @@ -790,7 +793,8 @@ def _scan_langs(self, state: 'ModuleState', langs: T.Iterable[str]) -> T.List[st return ret - def _scan_gir_targets(self, state: 'ModuleState', girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Union[str, build.Executable]]: + @staticmethod + def _scan_gir_targets(state: 'ModuleState', girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Union[str, build.Executable]]: ret: T.List[T.Union[str, build.Executable]] = [] for girtarget in girtargets: @@ -823,7 +827,8 @@ def _scan_gir_targets(self, state: 'ModuleState', girtargets: T.Sequence[build.B return ret - def _get_girtargets_langs_compilers(self, girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Tuple[str, 'Compiler']]: + @staticmethod + def _get_girtargets_langs_compilers(girtargets: T.Sequence[build.BuildTarget]) -> T.List[T.Tuple[str, 'Compiler']]: ret: T.List[T.Tuple[str, 'Compiler']] = [] for girtarget in girtargets: for lang, compiler in girtarget.compilers.items(): @@ -834,7 +839,8 @@ def _get_girtargets_langs_compilers(self, girtargets: T.Sequence[build.BuildTarg return ret - def _get_gir_targets_deps(self, girtargets: T.Sequence[build.BuildTarget] + @staticmethod + def _get_gir_targets_deps(girtargets: T.Sequence[build.BuildTarget] ) -> T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, Dependency]]: ret: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, Dependency]] = [] for girtarget in girtargets: @@ -842,13 +848,15 @@ def _get_gir_targets_deps(self, girtargets: T.Sequence[build.BuildTarget] ret += girtarget.get_external_deps() return ret - def _get_gir_targets_inc_dirs(self, girtargets: T.Sequence[build.BuildTarget]) -> T.List[build.IncludeDirs]: + @staticmethod + def _get_gir_targets_inc_dirs(girtargets: T.Sequence[build.BuildTarget]) -> T.List[build.IncludeDirs]: ret: T.List[build.IncludeDirs] = [] for girtarget in girtargets: ret += girtarget.get_include_dirs() return ret - def _get_langs_compilers_flags(self, state: 'ModuleState', langs_compilers: T.List[T.Tuple[str, 'Compiler']] + @staticmethod + def _get_langs_compilers_flags(state: 'ModuleState', langs_compilers: T.List[T.Tuple[str, 'Compiler']] ) -> T.Tuple[T.List[str], T.List[str], T.List[str]]: cflags: T.List[str] = [] internal_ldflags: T.List[str] = [] @@ -876,7 +884,8 @@ def _get_langs_compilers_flags(self, state: 'ModuleState', langs_compilers: T.Li return cflags, internal_ldflags, external_ldflags - def _make_gir_filelist(self, state: 'ModuleState', srcdir: str, ns: str, + @staticmethod + def _make_gir_filelist(state: 'ModuleState', srcdir: str, ns: str, nsversion: str, girtargets: T.Sequence[build.BuildTarget], libsources: T.Sequence[T.Union[ str, mesonlib.File, build.GeneratedList, @@ -904,8 +913,8 @@ def _make_gir_filelist(self, state: 'ModuleState', srcdir: str, ns: str, return gir_filelist_filename + @staticmethod def _make_gir_target( - self, state: 'ModuleState', girfile: str, scan_command: T.Sequence[T.Union['FileOrString', Executable, ExternalProgram, OverrideProgram]], @@ -935,7 +944,8 @@ def _make_gir_target( return GirTarget(girfile, state.subdir, state.subproject, scankwargs) - def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, + @staticmethod + def _make_typelib_target(state: 'ModuleState', typelib_output: str, typelib_cmd: T.Sequence[T.Union[str, build.Executable, ExternalProgram, build.CustomTarget]], generated_files: T.Sequence[T.Union[str, mesonlib.File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]], kwargs: T.Dict[str, T.Any]) -> TypelibTarget: @@ -961,8 +971,9 @@ def _make_typelib_target(self, state: 'ModuleState', typelib_output: str, return TypelibTarget(typelib_output, state.subdir, state.subproject, typelib_kwargs) + @staticmethod def _gather_typelib_includes_and_update_depends( - self, state: 'ModuleState', + state: 'ModuleState', deps: T.Sequence[T.Union[Dependency, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]], depends: T.Sequence[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']] ) -> T.Tuple[T.List[str], T.List[T.Union[build.BuildTarget, 'build.GeneratedTypes', 'FileOrString']]]: @@ -1001,7 +1012,8 @@ def _gather_typelib_includes_and_update_depends( typelib_includes.append(girdir) return typelib_includes, new_depends - def _get_external_args_for_langs(self, state: 'ModuleState', langs: T.Sequence[str]) -> T.List[str]: + @staticmethod + def _get_external_args_for_langs(state: 'ModuleState', langs: T.Sequence[str]) -> T.List[str]: ret: T.List[str] = [] for lang in langs: ret += mesonlib.listify(state.environment.coredata.get_external_args(MachineChoice.HOST, lang))