From 0fe3dc6571303458d361952059750bd8479a9a65 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 11:03:21 -0700 Subject: modules/qt: Deprecated the *sources variadic argument to preproccess It's confusing, and it's a duplicate of the `sources` keyword argument, which has always existed. --- mesonbuild/modules/qt.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index aecfe50..d14bfd2 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -24,7 +24,7 @@ from ..mesonlib import MesonException, extract_as_list, File, unholder, version_ from ..dependencies import Dependency import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule -from ..interpreterbase import noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs +from ..interpreterbase import FeatureDeprecated, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram @@ -194,7 +194,10 @@ class QtBaseModule(ExtensionModule): def preprocess(self, state, args, kwargs): rcc_files, ui_files, moc_headers, moc_sources, uic_extra_arguments, moc_extra_arguments, rcc_extra_arguments, sources, include_directories, dependencies \ = [extract_as_list(kwargs, c, pop=True) for c in ['qresources', 'ui_files', 'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'sources', 'include_directories', 'dependencies']] - sources += args[1:] + _sources = args[1:] + if _sources: + FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject, 'use the "sources" keyword argument instead') + sources.extend(_sources) method = kwargs.get('method', 'auto') self._detect_tools(state, method) err_msg = "{0} sources specified and couldn't find {1}, " \ -- cgit v1.1 From 4575ed3d31afc58bb286d260dee9d8dceb5fb3b3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 11:25:39 -0700 Subject: modules/qt: Deprecated the preprocess sources keyword argument --- mesonbuild/modules/qt.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index d14bfd2..c41ec9d 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -24,7 +24,7 @@ from ..mesonlib import MesonException, extract_as_list, File, unholder, version_ from ..dependencies import Dependency import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule -from ..interpreterbase import FeatureDeprecated, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs +from ..interpreterbase import FeatureDeprecated, FeatureDeprecatedKwargs, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram @@ -190,13 +190,14 @@ class QtBaseModule(ExtensionModule): @FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments']) + @FeatureDeprecatedKwargs('qt.preprocess', '0.59.0', ['sources']) @permittedKwargs({'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'include_directories', 'dependencies', 'ui_files', 'qresources', 'method'}) def preprocess(self, state, args, kwargs): rcc_files, ui_files, moc_headers, moc_sources, uic_extra_arguments, moc_extra_arguments, rcc_extra_arguments, sources, include_directories, dependencies \ = [extract_as_list(kwargs, c, pop=True) for c in ['qresources', 'ui_files', 'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'sources', 'include_directories', 'dependencies']] _sources = args[1:] if _sources: - FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject, 'use the "sources" keyword argument instead') + FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject) sources.extend(_sources) method = kwargs.get('method', 'auto') self._detect_tools(state, method) -- cgit v1.1 From d27948b1dc11303274b622ed2fa4e765a09feb38 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 13:45:42 -0700 Subject: modules/qt: Add a `compile_resources` method This is a separate method for just handling qrc resources. --- mesonbuild/modules/qt.py | 112 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 98 insertions(+), 14 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index c41ec9d..52fb2c3 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -24,16 +24,28 @@ from ..mesonlib import MesonException, extract_as_list, File, unholder, version_ from ..dependencies import Dependency import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule -from ..interpreterbase import FeatureDeprecated, FeatureDeprecatedKwargs, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs +from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram if T.TYPE_CHECKING: - from ..interpreter import Interpreter + from . import ModuleState from ..dependencies.qt import QtBaseDependency from ..environment import Environment + from ..interpreter import Interpreter from ..programs import ExternalProgram + from typing_extensions import TypedDict + + class ResourceCompilerKwArgs(TypedDict): + + """Keyword arguments for the Resource Compiler method.""" + + name: T.Optional[str] + sources: T.List[mesonlib.FileOrString] + extra_args: T.List[str] + method: str + class QtBaseModule(ExtensionModule): tools_detected = False @@ -50,6 +62,7 @@ class QtBaseModule(ExtensionModule): 'has_tools': self.has_tools, 'preprocess': self.preprocess, 'compile_translations': self.compile_translations, + 'compile_resources': self.compile_resources, }) def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None: @@ -96,7 +109,7 @@ class QtBaseModule(ExtensionModule): if p.found(): setattr(self, name, p) - def _detect_tools(self, state, method, required=True): + def _detect_tools(self, state: 'ModuleState', method: str, required: bool = True) -> None: if self.tools_detected: return self.tools_detected = True @@ -118,21 +131,24 @@ class QtBaseModule(ExtensionModule): self.rcc = NonExistingExternalProgram(name='rcc' + suffix) self.lrelease = NonExistingExternalProgram(name='lrelease' + suffix) - def qrc_nodes(self, state, rcc_file): - if type(rcc_file) is str: + @staticmethod + def _qrc_nodes(state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.Tuple[str, T.List[str]]: + abspath: str + if isinstance(rcc_file, str): abspath = os.path.join(state.environment.source_dir, state.subdir, rcc_file) rcc_dirname = os.path.dirname(abspath) - elif type(rcc_file) is File: + else: abspath = rcc_file.absolute_path(state.environment.source_dir, state.environment.build_dir) rcc_dirname = os.path.dirname(abspath) + # FIXME: what error are we actually tring to check here? try: tree = ET.parse(abspath) root = tree.getroot() - result = [] + result: T.List[str] = [] for child in root[0]: if child.tag != 'file': - mlog.warning("malformed rcc file: ", os.path.join(state.subdir, rcc_file)) + mlog.warning("malformed rcc file: ", os.path.join(state.subdir, str(rcc_file))) break else: result.append(child.text) @@ -141,9 +157,9 @@ class QtBaseModule(ExtensionModule): except Exception: raise MesonException(f'Unable to parse resource file {abspath}') - def parse_qrc_deps(self, state, rcc_file): - rcc_dirname, nodes = self.qrc_nodes(state, rcc_file) - result = [] + def _parse_qrc_deps(self, state: 'ModuleState', rcc_file: 'mesonlib.FileOrString') -> T.List[File]: + rcc_dirname, nodes = self._qrc_nodes(state, rcc_file) + result: T.List[File] = [] for resource_path in nodes: # We need to guess if the pointed resource is: # a) in build directory -> implies a generated file @@ -187,6 +203,73 @@ class QtBaseModule(ExtensionModule): return False return True + @FeatureNew('qt.compile_resources', '0.59.0') + @noPosargs + @typed_kwargs( + 'qt.compile_resources', + KwargInfo('name', str), + KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('method', str, default='auto') + ) + def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs'): + """Compile Qt resources files. + + Uses CustomTargets to generate .cpp files from .qrc files. + """ + self._detect_tools(state, kwargs['method']) + if not self.rcc.found(): + err_msg = ("{0} sources specified and couldn't find {1}, " + "please check your qt{2} installation") + raise MesonException(err_msg.format('RCC', f'rcc-qt{self.qt_version}', self.qt_version)) + + # List of generated CustomTargets + targets: T.List[build.CustomTarget] = [] + + # depfile arguments + DEPFILE_ARGS: T.List[str] = ['--depfile', '@DEPFILE@'] if self.rcc_supports_depfiles else [] + + name = kwargs['name'] + sources = kwargs['sources'] + extra_args = kwargs['extra_args'] or [] + + # If a name was set generate a single .cpp file from all of the qrc + # files, otherwise generate one .cpp file per qrc file. + if name: + qrc_deps: T.List[File] = [] + for s in sources: + qrc_deps.extend(self._parse_qrc_deps(state, s)) + + rcc_kwargs: T.Dict[str, T.Any] = { # TODO: if CustomTarget had typing information we could use that here... + 'input': sources, + 'output': name + '.cpp', + 'command': [self.rcc, '-name', name, '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS, + 'depend_files': qrc_deps, + 'depfile': f'{name}.d', + } + res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) + targets.append(res_target) + else: + for rcc_file in sources: + qrc_deps = self._parse_qrc_deps(state, rcc_file) + if isinstance(rcc_file, str): + basename = os.path.basename(rcc_file) + else: + basename = os.path.basename(rcc_file.fname) + name = f'qt{self.qt_version}-{basename.replace(".", "_")}' + rcc_kwargs = { + 'input': rcc_file, + 'output': f'{name}.cpp', + 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS, + 'depend_files': qrc_deps, + 'depfile': f'{name}.d', + } + res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) + targets.append(res_target) + + return ModuleReturnValue(targets, [targets]) + + @FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments']) @@ -209,10 +292,11 @@ class QtBaseModule(ExtensionModule): if not self.rcc.found(): raise MesonException(err_msg.format('RCC', f'rcc-qt{self.qt_version}', self.qt_version)) # custom output name set? -> one output file, multiple otherwise + rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': rcc_files, 'extra_args': rcc_extra_arguments, 'method': method} if args: qrc_deps = [] for i in rcc_files: - qrc_deps += self.parse_qrc_deps(state, i) + qrc_deps += self._parse_qrc_deps(state, i) name = args[0] rcc_kwargs = {'input': rcc_files, 'output': name + '.cpp', @@ -222,7 +306,7 @@ class QtBaseModule(ExtensionModule): sources.append(res_target) else: for rcc_file in rcc_files: - qrc_deps = self.parse_qrc_deps(state, rcc_file) + qrc_deps = self._parse_qrc_deps(state, rcc_file) if type(rcc_file) is str: basename = os.path.basename(rcc_file) elif type(rcc_file) is File: @@ -293,7 +377,7 @@ class QtBaseModule(ExtensionModule): shutil.copy2(infile_abs, outfile_abs) self.interpreter.add_build_def_file(infile_abs) - rcc_file, nodes = self.qrc_nodes(state, qresource) + rcc_file, nodes = self._qrc_nodes(state, qresource) for c in nodes: if c.endswith('.qm'): ts_files.append(c.rstrip('.qm')+'.ts') -- cgit v1.1 From ed06ae3db1ee56053663a812bdcc665c92e44cc6 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 13:57:39 -0700 Subject: modules/qt: Dispatch the preprocess method to the compile_resources method Which removes code duplication and makes our testing better --- mesonbuild/modules/qt.py | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 52fb2c3..d25c127 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -212,7 +212,7 @@ class QtBaseModule(ExtensionModule): KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), KwargInfo('method', str, default='auto') ) - def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs'): + def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue: """Compile Qt resources files. Uses CustomTargets to generate .cpp files from .qrc files. @@ -288,39 +288,14 @@ class QtBaseModule(ExtensionModule): "please check your qt{2} installation" if (moc_headers or moc_sources) and not self.moc.found(): raise MesonException(err_msg.format('MOC', f'moc-qt{self.qt_version}', self.qt_version)) + if rcc_files: - if not self.rcc.found(): - raise MesonException(err_msg.format('RCC', f'rcc-qt{self.qt_version}', self.qt_version)) # custom output name set? -> one output file, multiple otherwise rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': rcc_files, 'extra_args': rcc_extra_arguments, 'method': method} if args: - qrc_deps = [] - for i in rcc_files: - qrc_deps += self._parse_qrc_deps(state, i) - name = args[0] - rcc_kwargs = {'input': rcc_files, - 'output': name + '.cpp', - 'command': [self.rcc, '-name', name, '-o', '@OUTPUT@', rcc_extra_arguments, '@INPUT@'], - 'depend_files': qrc_deps} - res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) - sources.append(res_target) - else: - for rcc_file in rcc_files: - qrc_deps = self._parse_qrc_deps(state, rcc_file) - if type(rcc_file) is str: - basename = os.path.basename(rcc_file) - elif type(rcc_file) is File: - basename = os.path.basename(rcc_file.fname) - name = 'qt' + str(self.qt_version) + '-' + basename.replace('.', '_') - rcc_kwargs = {'input': rcc_file, - 'output': name + '.cpp', - 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', rcc_extra_arguments, '@INPUT@'], - 'depend_files': qrc_deps} - if self.rcc_supports_depfiles: - rcc_kwargs['depfile'] = name + '.d' - rcc_kwargs['command'] += ['--depfile', '@DEPFILE@'] - res_target = build.CustomTarget(name, state.subdir, state.subproject, rcc_kwargs) - sources.append(res_target) + rcc_kwargs['name'] = args[0] + sources.extend(self.compile_resources(state, tuple(), rcc_kwargs).return_value) + if ui_files: if not self.uic.found(): raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version)) -- cgit v1.1 From fcdb0f9879f134e1113c1a1c6bddb4fcac323d4c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 14:11:13 -0700 Subject: modules/qt: Add a compile_ui method Which is the same functionality split out of preprocess --- mesonbuild/modules/qt.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index d25c127..e4d2f5f 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -46,6 +46,14 @@ if T.TYPE_CHECKING: extra_args: T.List[str] method: str + class UICompilerKwArgs(TypedDict): + + """Keyword arguments for the Ui Compiler method.""" + + sources: T.List[mesonlib.FileOrString] + extra_args: T.List[str] + method: str + class QtBaseModule(ExtensionModule): tools_detected = False @@ -63,6 +71,7 @@ class QtBaseModule(ExtensionModule): 'preprocess': self.preprocess, 'compile_translations': self.compile_translations, 'compile_resources': self.compile_resources, + 'compile_ui': self.compile_ui, }) def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None: @@ -269,6 +278,29 @@ class QtBaseModule(ExtensionModule): return ModuleReturnValue(targets, [targets]) + @FeatureNew('qt.compile_ui', '0.59.0') + @noPosargs + @typed_kwargs( + 'qt.compile_ui', + KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('method', str, default='auto') + ) + def compile_ui(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue: + """Compile UI resources into cpp headers.""" + self._detect_tools(state, kwargs['method']) + if not self.uic.found(): + err_msg = ("{0} sources specified and couldn't find {1}, " + "please check your qt{2} installation") + raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version)) + + ui_kwargs: T.Dict[str, T.Any] = { # TODO: if Generator was properly annotated… + 'output': 'ui_@BASENAME@.h', + 'arguments': kwargs['extra_args'] or [] + ['-o', '@OUTPUT@', '@INPUT@']} + # TODO: This generator isn't added to the generator list in the Interpreter + gen = build.Generator([self.uic], ui_kwargs) + out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) + return ModuleReturnValue(out, [out]) # type: ignore @FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) @@ -305,6 +337,7 @@ class QtBaseModule(ExtensionModule): ui_gen = build.Generator([self.uic], ui_kwargs) ui_output = ui_gen.process_files(f'Qt{self.qt_version} ui', ui_files, state) sources.append(ui_output) + inc = state.get_include_args(include_dirs=include_directories) compile_args = [] for dep in unholder(dependencies): -- cgit v1.1 From ec592a4ecae1db61b9748ec7d2388f738cdb4737 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 14:12:29 -0700 Subject: modules/qt: use the compile_ui method inside the preprocess method for code deduplication --- mesonbuild/modules/qt.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index e4d2f5f..f3e6f27 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -329,14 +329,8 @@ class QtBaseModule(ExtensionModule): sources.extend(self.compile_resources(state, tuple(), rcc_kwargs).return_value) if ui_files: - if not self.uic.found(): - raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version)) - arguments = uic_extra_arguments + ['-o', '@OUTPUT@', '@INPUT@'] - ui_kwargs = {'output': 'ui_@BASENAME@.h', - 'arguments': arguments} - ui_gen = build.Generator([self.uic], ui_kwargs) - ui_output = ui_gen.process_files(f'Qt{self.qt_version} ui', ui_files, state) - sources.append(ui_output) + ui_kwargs: 'UICompilerKwArgs' = {'sources': ui_files, 'extra_args': uic_extra_arguments, 'method': method} + sources.extend(self.compile_ui(state, tuple(), ui_kwargs).return_value) inc = state.get_include_args(include_dirs=include_directories) compile_args = [] -- cgit v1.1 From 2322804a4df9811ba75db01230b5df36efd20aee Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 14:54:57 -0700 Subject: modules/qt: Add a compile_moc method This method only compiles moc resources, nothing else --- mesonbuild/modules/qt.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index f3e6f27..439f995 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -27,6 +27,7 @@ from . import ModuleReturnValue, ExtensionModule from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram +from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder if T.TYPE_CHECKING: from . import ModuleState @@ -54,6 +55,17 @@ if T.TYPE_CHECKING: extra_args: T.List[str] method: str + class MocCompilerKwArgs(TypedDict): + + """Keyword arguments for the Moc Compiler method.""" + + sources: T.Optional[T.List[mesonlib.FileOrString]] + headers: T.Optional[T.List[mesonlib.FileOrString]] + extra_args: T.Optional[T.List[str]] + method: str + include_directories: T.Optional[T.List[IncludeDirsHolder]] + dependencies: T.Optional[T.List[T.Union[DependencyHolder, ExternalLibraryHolder]]] + class QtBaseModule(ExtensionModule): tools_detected = False @@ -72,6 +84,7 @@ class QtBaseModule(ExtensionModule): 'compile_translations': self.compile_translations, 'compile_resources': self.compile_resources, 'compile_ui': self.compile_ui, + 'compile_moc': self.compile_moc, }) def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None: @@ -302,12 +315,57 @@ class QtBaseModule(ExtensionModule): out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) return ModuleReturnValue(out, [out]) # type: ignore + @FeatureNew('qt.compile_moc', '0.59.0') + @noPosargs + @typed_kwargs( + 'qt.compile_moc', + KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True), + KwargInfo('headers', ContainerTypeInfo(list, (File, str)), listify=True), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('method', str, default='auto'), + KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirsHolder), listify=True), + KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True), + ) + def compile_moc(self, state: 'ModuleState', args: T.Tuple, kwargs: 'MocCompilerKwArgs') -> ModuleReturnValue: + self._detect_tools(state, kwargs['method']) + if not self.moc.found(): + err_msg = ("{0} sources specified and couldn't find {1}, " + "please check your qt{2} installation") + raise MesonException(err_msg.format('MOC', f'uic-qt{self.qt_version}', self.qt_version)) + + if not (kwargs['headers'] or kwargs['sources']): + raise build.InvalidArguments('At least one of the "headers" or "sources" keyword arguments must be provied and not empty') + + inc = state.get_include_args(include_dirs=kwargs['include_directories'] or []) + compile_args: T.List[str] = [] + if kwargs['dependencies']: + for dep in unholder(kwargs['dependencies']): + compile_args.extend([a for a in dep.get_all_compile_args() if a.startswith(('-I', '-D'))]) + + output: T.List[build.GeneratedList] = [] + + extra_args: T.List[str] = kwargs['extra_args'] or [] + arguments = extra_args + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] + if kwargs['headers']: + moc_kwargs = {'output': 'moc_@BASENAME@.cpp', + 'arguments': arguments} + moc_gen = build.Generator([self.moc], moc_kwargs) + output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) + if kwargs['sources']: + moc_kwargs = {'output': '@BASENAME@.moc', + 'arguments': arguments} + moc_gen = build.Generator([self.moc], moc_kwargs) + output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) + + return ModuleReturnValue(output, [output]) + @FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments']) @FeatureDeprecatedKwargs('qt.preprocess', '0.59.0', ['sources']) @permittedKwargs({'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'include_directories', 'dependencies', 'ui_files', 'qresources', 'method'}) - def preprocess(self, state, args, kwargs): + # We can't use typed_pos_args here, the signature is ambiguious + def preprocess(self, state: 'ModuleState', args: T.List[str], kwargs): rcc_files, ui_files, moc_headers, moc_sources, uic_extra_arguments, moc_extra_arguments, rcc_extra_arguments, sources, include_directories, dependencies \ = [extract_as_list(kwargs, c, pop=True) for c in ['qresources', 'ui_files', 'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'sources', 'include_directories', 'dependencies']] _sources = args[1:] -- cgit v1.1 From 118f70fedef15c9b28cc4df01c0644596df4c42d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 14:58:26 -0700 Subject: modules/qt: have pre-process dispatch to moc_compile for ode sharing and simplicity --- mesonbuild/modules/qt.py | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 439f995..fa8b007 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -373,11 +373,6 @@ class QtBaseModule(ExtensionModule): FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject) sources.extend(_sources) method = kwargs.get('method', 'auto') - self._detect_tools(state, method) - err_msg = "{0} sources specified and couldn't find {1}, " \ - "please check your qt{2} installation" - if (moc_headers or moc_sources) and not self.moc.found(): - raise MesonException(err_msg.format('MOC', f'moc-qt{self.qt_version}', self.qt_version)) if rcc_files: # custom output name set? -> one output file, multiple otherwise @@ -390,32 +385,16 @@ class QtBaseModule(ExtensionModule): ui_kwargs: 'UICompilerKwArgs' = {'sources': ui_files, 'extra_args': uic_extra_arguments, 'method': method} sources.extend(self.compile_ui(state, tuple(), ui_kwargs).return_value) - inc = state.get_include_args(include_dirs=include_directories) - compile_args = [] - for dep in unholder(dependencies): - if isinstance(dep, Dependency): - for arg in dep.get_all_compile_args(): - if arg.startswith('-I') or arg.startswith('-D'): - compile_args.append(arg) - else: - raise MesonException('Argument is of an unacceptable type {!r}.\nMust be ' - 'either an external dependency (returned by find_library() or ' - 'dependency()) or an internal dependency (returned by ' - 'declare_dependency()).'.format(type(dep).__name__)) - if moc_headers: - arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] - moc_kwargs = {'output': 'moc_@BASENAME@.cpp', - 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) - moc_output = moc_gen.process_files(f'Qt{self.qt_version} moc header', moc_headers, state) - sources.append(moc_output) - if moc_sources: - arguments = moc_extra_arguments + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] - moc_kwargs = {'output': '@BASENAME@.moc', - 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) - moc_output = moc_gen.process_files(f'Qt{self.qt_version} moc source', moc_sources, state) - sources.append(moc_output) + if moc_headers or moc_sources: + moc_kwargs: 'MocCompilerKwArgs' = { + 'extra_args': moc_extra_arguments, + 'sources': moc_sources, + 'headers': moc_sources, + 'include_directories': include_directories, + 'dependencies': dependencies + } + sources.extend(self.compile_moc(state, tuple(), moc_kwargs).return_value) + return ModuleReturnValue(sources, sources) @FeatureNew('qt.compile_translations', '0.44.0') -- cgit v1.1 From ffa83f7f8a28289ada60ded86dc83e180625783b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 15:53:59 -0700 Subject: modules/qt: Type anotations and cleanups This adds a number of missing type annotations to existing functions, and makes a few members protected instead of public, as they were never meant to be public --- mesonbuild/modules/qt.py | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index fa8b007..e71b96a 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -21,7 +21,6 @@ from .. import mlog from .. import build from .. import mesonlib from ..mesonlib import MesonException, extract_as_list, File, unholder, version_compare -from ..dependencies import Dependency import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs @@ -31,11 +30,12 @@ from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHo if T.TYPE_CHECKING: from . import ModuleState - from ..dependencies.qt import QtBaseDependency - from ..environment import Environment + from ..dependencies.qt import QtPkgConfigDependency, QmakeQtDependency from ..interpreter import Interpreter from ..programs import ExternalProgram + QtDependencyType = T.Union[QtPkgConfigDependency, QmakeQtDependency] + from typing_extensions import TypedDict class ResourceCompilerKwArgs(TypedDict): @@ -59,19 +59,32 @@ if T.TYPE_CHECKING: """Keyword arguments for the Moc Compiler method.""" - sources: T.Optional[T.List[mesonlib.FileOrString]] - headers: T.Optional[T.List[mesonlib.FileOrString]] - extra_args: T.Optional[T.List[str]] + sources: T.List[mesonlib.FileOrString] + headers: T.List[mesonlib.FileOrString] + extra_args: T.List[str] + method: str + include_directories: T.List[IncludeDirsHolder] + dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] + + class PreprocessKwArgs(TypedDict): + + sources: T.List[mesonlib.FileOrString] + moc_sources: T.List[mesonlib.FileOrString] + qresources: T.List[mesonlib.FileOrString] + ui_files: T.List[mesonlib.FileOrString] + moc_extra_arguments: T.List[str] + rcc_extra_arguments: T.List[str] + uic_extra_arguments: T.List[str] + include_directories: T.List[IncludeDirsHolder] + dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] method: str - include_directories: T.Optional[T.List[IncludeDirsHolder]] - dependencies: T.Optional[T.List[T.Union[DependencyHolder, ExternalLibraryHolder]]] class QtBaseModule(ExtensionModule): - tools_detected = False - rcc_supports_depfiles = False + _tools_detected = False + _rcc_supports_depfiles = False - def __init__(self, interpreter: 'Interpreter', qt_version=5): + def __init__(self, interpreter: 'Interpreter', qt_version: int = 5): ExtensionModule.__init__(self, interpreter) self.qt_version = qt_version self.moc: 'ExternalProgram' = NonExistingExternalProgram('moc') @@ -87,7 +100,7 @@ class QtBaseModule(ExtensionModule): 'compile_moc': self.compile_moc, }) - def compilers_detect(self, state, qt_dep: 'QtBaseDependency') -> None: + def compilers_detect(self, state: 'ModuleState', qt_dep: 'QtDependencyType') -> None: """Detect Qt (4 or 5) moc, uic, rcc in the specified bindir or in PATH""" # It is important that this list does not change order as the order of # the returned ExternalPrograms will change as well @@ -132,9 +145,9 @@ class QtBaseModule(ExtensionModule): setattr(self, name, p) def _detect_tools(self, state: 'ModuleState', method: str, required: bool = True) -> None: - if self.tools_detected: + if self._tools_detected: return - self.tools_detected = True + self._tools_detected = True mlog.log(f'Detecting Qt{self.qt_version} tools') kwargs = {'required': required, 'modules': 'Core', 'method': method} qt = find_external_dependency(f'qt{self.qt_version}', state.environment, kwargs) @@ -142,7 +155,7 @@ class QtBaseModule(ExtensionModule): # Get all tools and then make sure that they are the right version self.compilers_detect(state, qt) if version_compare(qt.version, '>=5.14.0'): - self.rcc_supports_depfiles = True + self._rcc_supports_depfiles = True else: mlog.warning('rcc dependencies will not work properly until you move to Qt >= 5.14:', mlog.bold('https://bugreports.qt.io/browse/QTBUG-45460'), fatal=False) @@ -211,7 +224,7 @@ class QtBaseModule(ExtensionModule): @noPosargs @permittedKwargs({'method', 'required'}) @FeatureNew('qt.has_tools', '0.54.0') - def has_tools(self, state, args, kwargs): + def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs) -> bool: method = kwargs.get('method', 'auto') disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, default=False) if disabled: @@ -249,7 +262,7 @@ class QtBaseModule(ExtensionModule): targets: T.List[build.CustomTarget] = [] # depfile arguments - DEPFILE_ARGS: T.List[str] = ['--depfile', '@DEPFILE@'] if self.rcc_supports_depfiles else [] + DEPFILE_ARGS: T.List[str] = ['--depfile', '@DEPFILE@'] if self._rcc_supports_depfiles else [] name = kwargs['name'] sources = kwargs['sources'] -- cgit v1.1 From 61ddceb3b99928de78a97e406c990377cd3085b4 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 15:54:36 -0700 Subject: modules/qt: Make use of the default=[] availability --- mesonbuild/modules/qt.py | 73 +++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index e71b96a..0d27c2a 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -244,7 +244,7 @@ class QtBaseModule(ExtensionModule): 'qt.compile_resources', KwargInfo('name', str), KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True), - KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('method', str, default='auto') ) def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue: @@ -309,7 +309,7 @@ class QtBaseModule(ExtensionModule): @typed_kwargs( 'qt.compile_ui', KwargInfo('sources', ContainerTypeInfo(list, (File, str), allow_empty=False), listify=True, required=True), - KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('method', str, default='auto') ) def compile_ui(self, state: 'ModuleState', args: T.Tuple, kwargs: 'ResourceCompilerKwArgs') -> ModuleReturnValue: @@ -332,12 +332,12 @@ class QtBaseModule(ExtensionModule): @noPosargs @typed_kwargs( 'qt.compile_moc', - KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True), - KwargInfo('headers', ContainerTypeInfo(list, (File, str)), listify=True), - KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True), + KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('headers', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]), KwargInfo('method', str, default='auto'), - KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirsHolder), listify=True), - KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True), + KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirsHolder), listify=True, default=[]), + KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True, default=[]), ) def compile_moc(self, state: 'ModuleState', args: T.Tuple, kwargs: 'MocCompilerKwArgs') -> ModuleReturnValue: self._detect_tools(state, kwargs['method']) @@ -349,16 +349,14 @@ class QtBaseModule(ExtensionModule): if not (kwargs['headers'] or kwargs['sources']): raise build.InvalidArguments('At least one of the "headers" or "sources" keyword arguments must be provied and not empty') - inc = state.get_include_args(include_dirs=kwargs['include_directories'] or []) + inc = state.get_include_args(include_dirs=kwargs['include_directories']) compile_args: T.List[str] = [] - if kwargs['dependencies']: - for dep in unholder(kwargs['dependencies']): - compile_args.extend([a for a in dep.get_all_compile_args() if a.startswith(('-I', '-D'))]) + for dep in unholder(kwargs['dependencies']): + compile_args.extend([a for a in dep.get_all_compile_args() if a.startswith(('-I', '-D'))]) output: T.List[build.GeneratedList] = [] - extra_args: T.List[str] = kwargs['extra_args'] or [] - arguments = extra_args + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = kwargs['extra_args'] + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] if kwargs['headers']: moc_kwargs = {'output': 'moc_@BASENAME@.cpp', 'arguments': arguments} @@ -376,35 +374,52 @@ class QtBaseModule(ExtensionModule): @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) @FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments']) @FeatureDeprecatedKwargs('qt.preprocess', '0.59.0', ['sources']) - @permittedKwargs({'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'include_directories', 'dependencies', 'ui_files', 'qresources', 'method'}) # We can't use typed_pos_args here, the signature is ambiguious - def preprocess(self, state: 'ModuleState', args: T.List[str], kwargs): - rcc_files, ui_files, moc_headers, moc_sources, uic_extra_arguments, moc_extra_arguments, rcc_extra_arguments, sources, include_directories, dependencies \ - = [extract_as_list(kwargs, c, pop=True) for c in ['qresources', 'ui_files', 'moc_headers', 'moc_sources', 'uic_extra_arguments', 'moc_extra_arguments', 'rcc_extra_arguments', 'sources', 'include_directories', 'dependencies']] + @typed_kwargs( + 'qt.preprocess', + KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('qresources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('ui_files', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('moc_sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('moc_headers', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('moc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('uic_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('method', str, default='auto'), + KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirsHolder), listify=True, default=[]), + KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True, default=[]), + ) + def preprocess(self, state: 'ModuleState', args: T.List[T.Union[str, File]], kwargs: 'PreprocessKwArgs') -> ModuleReturnValue: _sources = args[1:] if _sources: FeatureDeprecated.single_use('qt.preprocess positional sources', '0.59', state.subproject) - sources.extend(_sources) - method = kwargs.get('method', 'auto') + sources = _sources + kwargs['sources'] + for s in sources: + if not isinstance(s, (str, File)): + raise build.InvalidArguments('Variadic arguments to qt.preprocess must be Strings or Files') + method = kwargs['method'] - if rcc_files: + if kwargs['qresources']: # custom output name set? -> one output file, multiple otherwise - rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': rcc_files, 'extra_args': rcc_extra_arguments, 'method': method} + rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': kwargs['qresources'], 'extra_args': kwargs['rcc_extra_arguments'], 'method': method} if args: + if not isinstance(args[0], str): + raise build.InvalidArguments('First argument to qt.preprocess must be a string') rcc_kwargs['name'] = args[0] sources.extend(self.compile_resources(state, tuple(), rcc_kwargs).return_value) - if ui_files: - ui_kwargs: 'UICompilerKwArgs' = {'sources': ui_files, 'extra_args': uic_extra_arguments, 'method': method} + if kwargs['ui_files']: + ui_kwargs: 'UICompilerKwArgs' = {'sources': kwargs['ui_files'], 'extra_args': kwargs['uic_extra_arguments'], 'method': method} sources.extend(self.compile_ui(state, tuple(), ui_kwargs).return_value) - if moc_headers or moc_sources: + if kwargs['moc_headers'] or kwargs['moc_sources']: moc_kwargs: 'MocCompilerKwArgs' = { - 'extra_args': moc_extra_arguments, - 'sources': moc_sources, - 'headers': moc_sources, - 'include_directories': include_directories, - 'dependencies': dependencies + 'extra_args': kwargs['moc_extra_arguments'], + 'sources': kwargs['moc_sources'], + 'headers': kwargs['moc_headers'], + 'include_directories': kwargs['include_directories'], + 'dependencies': kwargs['dependencies'], + 'method': method, } sources.extend(self.compile_moc(state, tuple(), moc_kwargs).return_value) -- cgit v1.1 From 2bc7a1b3dad998b12d80a52f83bab9a5981b2ec8 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 16:05:09 -0700 Subject: modules/qt: fully annotate and check qt.has_tools --- mesonbuild/modules/qt.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 0d27c2a..4e01393 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -26,12 +26,13 @@ from . import ModuleReturnValue, ExtensionModule from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram -from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder +from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder if T.TYPE_CHECKING: from . import ModuleState from ..dependencies.qt import QtPkgConfigDependency, QmakeQtDependency from ..interpreter import Interpreter + from ..interpreter import kwargs from ..programs import ExternalProgram QtDependencyType = T.Union[QtPkgConfigDependency, QmakeQtDependency] @@ -79,6 +80,10 @@ if T.TYPE_CHECKING: dependencies: T.List[T.Union[DependencyHolder, ExternalLibraryHolder]] method: str + class HasToolKwArgs(kwargs.ExtractRequired): + + method: str + class QtBaseModule(ExtensionModule): _tools_detected = False @@ -221,11 +226,19 @@ class QtBaseModule(ExtensionModule): result.append(File(is_built=False, subdir=state.subdir, fname=path_from_rcc)) return result + @FeatureNew('qt.has_tools', '0.54.0') @noPosargs + @typed_kwargs( + 'qt.has_tools', + KwargInfo('required', (bool, FeatureOptionHolder), default=False), + KwargInfo('method', str, default='auto'), + ) @permittedKwargs({'method', 'required'}) - @FeatureNew('qt.has_tools', '0.54.0') - def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs) -> bool: + def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs: 'HasToolKwArgs') -> bool: method = kwargs.get('method', 'auto') + # We have to cast here because TypedDicts are invariant, even though + # ExtractRequiredKwArgs is a subset of HasToolKwArgs, type checkers + # will insist this is wrong disabled, required, feature = extract_required_kwarg(kwargs, state.subproject, default=False) if disabled: mlog.log('qt.has_tools skipped: feature', mlog.bold(feature), 'disabled') @@ -429,7 +442,8 @@ class QtBaseModule(ExtensionModule): @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['qresource']) @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['rcc_extra_arguments']) @permittedKwargs({'ts_files', 'qresource', 'rcc_extra_arguments', 'install', 'install_dir', 'build_by_default', 'method'}) - def compile_translations(self, state, args, kwargs): + @noPosargs + def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue: ts_files, install_dir = [extract_as_list(kwargs, c, pop=True) for c in ['ts_files', 'install_dir']] qresource = kwargs.get('qresource') if qresource: -- cgit v1.1 From 3c4c7d042932c23a8ea24d85f24cd290d0a5ea13 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 16:32:05 -0700 Subject: modules/qt: use type checking and annotations for compile_translations --- mesonbuild/modules/qt.py | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 4e01393..1a30555 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -84,6 +84,16 @@ if T.TYPE_CHECKING: method: str + class CompileTranslationsKwArgs(TypedDict): + + build_by_default: bool + install: bool + install_dir: T.Optional[str] + method: str + qresource: T.Optional[str] + rcc_extra_arguments: T.List[str] + ts_files: T.List[str] + class QtBaseModule(ExtensionModule): _tools_detected = False @@ -436,37 +446,48 @@ class QtBaseModule(ExtensionModule): } sources.extend(self.compile_moc(state, tuple(), moc_kwargs).return_value) - return ModuleReturnValue(sources, sources) + return ModuleReturnValue(sources, [sources]) @FeatureNew('qt.compile_translations', '0.44.0') @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['qresource']) @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['rcc_extra_arguments']) @permittedKwargs({'ts_files', 'qresource', 'rcc_extra_arguments', 'install', 'install_dir', 'build_by_default', 'method'}) @noPosargs - def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: T.Dict[str, T.Any]) -> ModuleReturnValue: - ts_files, install_dir = [extract_as_list(kwargs, c, pop=True) for c in ['ts_files', 'install_dir']] - qresource = kwargs.get('qresource') + @typed_kwargs( + 'qt.compile_translations', + KwargInfo('build_by_default', bool, default=False), + KwargInfo('install', bool, default=False), + KwargInfo('install_dir', str), + KwargInfo('method', str, default='auto'), + KwargInfo('qresource', str), + KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('ts_files', ContainerTypeInfo(list, (str, File)), listify=True, default=[]), + ) + def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: 'CompileTranslationsKwArgs') -> ModuleReturnValue: + ts_files = kwargs['ts_files'] + install_dir = kwargs['install_dir'] + qresource = kwargs['qresource'] if qresource: if ts_files: raise MesonException('qt.compile_translations: Cannot specify both ts_files and qresource') if os.path.dirname(qresource) != '': raise MesonException('qt.compile_translations: qresource file name must not contain a subdirectory.') - qresource = File.from_built_file(state.subdir, qresource) - infile_abs = os.path.join(state.environment.source_dir, qresource.relative_name()) - outfile_abs = os.path.join(state.environment.build_dir, qresource.relative_name()) + qresource_file = File.from_built_file(state.subdir, qresource) + infile_abs = os.path.join(state.environment.source_dir, qresource_file.relative_name()) + outfile_abs = os.path.join(state.environment.build_dir, qresource_file.relative_name()) os.makedirs(os.path.dirname(outfile_abs), exist_ok=True) shutil.copy2(infile_abs, outfile_abs) self.interpreter.add_build_def_file(infile_abs) - rcc_file, nodes = self._qrc_nodes(state, qresource) + _, nodes = self._qrc_nodes(state, qresource_file) for c in nodes: if c.endswith('.qm'): - ts_files.append(c.rstrip('.qm')+'.ts') + ts_files.append(c.rstrip('.qm') + '.ts') else: raise MesonException(f'qt.compile_translations: qresource can only contain qm files, found {c}') - results = self.preprocess(state, [], {'qresources': qresource, 'rcc_extra_arguments': kwargs.get('rcc_extra_arguments', [])}) - self._detect_tools(state, kwargs.get('method', 'auto')) - translations = [] + results = self.preprocess(state, [], {'qresources': qresource, 'rcc_extra_arguments': kwargs['rcc_extra_arguments']}) + self._detect_tools(state, kwargs['method']) + translations: T.List[build.CustomTarget] = [] for ts in ts_files: if not self.lrelease.found(): raise MesonException('qt.compile_translations: ' + @@ -489,4 +510,4 @@ class QtBaseModule(ExtensionModule): if qresource: return ModuleReturnValue(results.return_value[0], [results.new_objects, translations]) else: - return ModuleReturnValue(translations, translations) + return ModuleReturnValue(translations, [translations]) -- cgit v1.1 From 3824e30f7a9851e2a61a326692f93faa1ddf32c3 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 16:33:09 -0700 Subject: modules/qt: fix remaining typing issues and add to run_mypy This just ignores the fact taht Generator is unchecked. Generator needs some real love in terms of type checking. --- mesonbuild/modules/qt.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 1a30555..3b5d7cf 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -20,7 +20,7 @@ import typing as T from .. import mlog from .. import build from .. import mesonlib -from ..mesonlib import MesonException, extract_as_list, File, unholder, version_compare +from ..mesonlib import MesonException, File, version_compare import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs @@ -71,6 +71,7 @@ if T.TYPE_CHECKING: sources: T.List[mesonlib.FileOrString] moc_sources: T.List[mesonlib.FileOrString] + moc_headers: T.List[mesonlib.FileOrString] qresources: T.List[mesonlib.FileOrString] ui_files: T.List[mesonlib.FileOrString] moc_extra_arguments: T.List[str] @@ -165,7 +166,8 @@ class QtBaseModule(ExtensionModule): self._tools_detected = True mlog.log(f'Detecting Qt{self.qt_version} tools') kwargs = {'required': required, 'modules': 'Core', 'method': method} - qt = find_external_dependency(f'qt{self.qt_version}', state.environment, kwargs) + # Just pick one to make mypy happy + qt = T.cast('QtPkgConfigDependency', find_external_dependency(f'qt{self.qt_version}', state.environment, kwargs)) if qt.found(): # Get all tools and then make sure that they are the right version self.compilers_detect(state, qt) @@ -289,7 +291,7 @@ class QtBaseModule(ExtensionModule): name = kwargs['name'] sources = kwargs['sources'] - extra_args = kwargs['extra_args'] or [] + extra_args = kwargs['extra_args'] # If a name was set generate a single .cpp file from all of the qrc # files, otherwise generate one .cpp file per qrc file. @@ -301,7 +303,7 @@ class QtBaseModule(ExtensionModule): rcc_kwargs: T.Dict[str, T.Any] = { # TODO: if CustomTarget had typing information we could use that here... 'input': sources, 'output': name + '.cpp', - 'command': [self.rcc, '-name', name, '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS, + 'command': self.rcc.get_command() + ['-name', name, '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS, 'depend_files': qrc_deps, 'depfile': f'{name}.d', } @@ -318,7 +320,7 @@ class QtBaseModule(ExtensionModule): rcc_kwargs = { 'input': rcc_file, 'output': f'{name}.cpp', - 'command': [self.rcc, '-name', '@BASENAME@', '-o', '@OUTPUT@', extra_args, '@INPUT@'] + DEPFILE_ARGS, + 'command': self.rcc.get_command() + ['-name', '@BASENAME@', '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS, 'depend_files': qrc_deps, 'depfile': f'{name}.d', } @@ -345,11 +347,11 @@ class QtBaseModule(ExtensionModule): ui_kwargs: T.Dict[str, T.Any] = { # TODO: if Generator was properly annotated… 'output': 'ui_@BASENAME@.h', - 'arguments': kwargs['extra_args'] or [] + ['-o', '@OUTPUT@', '@INPUT@']} + 'arguments': kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@']} # TODO: This generator isn't added to the generator list in the Interpreter - gen = build.Generator([self.uic], ui_kwargs) + gen = build.Generator([self.uic], ui_kwargs) # type: ignore out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) - return ModuleReturnValue(out, [out]) # type: ignore + return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') @noPosargs @@ -374,8 +376,8 @@ class QtBaseModule(ExtensionModule): inc = state.get_include_args(include_dirs=kwargs['include_directories']) compile_args: T.List[str] = [] - for dep in unholder(kwargs['dependencies']): - compile_args.extend([a for a in dep.get_all_compile_args() if a.startswith(('-I', '-D'))]) + for dep in kwargs['dependencies']: + compile_args.extend([a for a in dep.held_object.get_all_compile_args() if a.startswith(('-I', '-D'))]) output: T.List[build.GeneratedList] = [] @@ -383,12 +385,12 @@ class QtBaseModule(ExtensionModule): if kwargs['headers']: moc_kwargs = {'output': 'moc_@BASENAME@.cpp', 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) + moc_gen = build.Generator([self.moc], moc_kwargs) # type: ignore output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) if kwargs['sources']: moc_kwargs = {'output': '@BASENAME@.moc', 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) + moc_gen = build.Generator([self.moc], moc_kwargs) # type: ignore output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) return ModuleReturnValue(output, [output]) @@ -424,7 +426,7 @@ class QtBaseModule(ExtensionModule): if kwargs['qresources']: # custom output name set? -> one output file, multiple otherwise - rcc_kwargs: 'ResourceCompilerKwArgs' = {'sources': kwargs['qresources'], 'extra_args': kwargs['rcc_extra_arguments'], 'method': method} + rcc_kwargs: 'ResourceCompilerKwArgs' = {'name': '', 'sources': kwargs['qresources'], 'extra_args': kwargs['rcc_extra_arguments'], 'method': method} if args: if not isinstance(args[0], str): raise build.InvalidArguments('First argument to qt.preprocess must be a string') -- cgit v1.1 From d064466e8bffb958d75cab30f68ae17c2c022b92 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 17:26:02 -0700 Subject: modues/qt: Make use of typed_kwargs since/deprecation abiltiy --- mesonbuild/modules/qt.py | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 3b5d7cf..297ef09 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -23,7 +23,7 @@ from .. import mesonlib from ..mesonlib import MesonException, File, version_compare import xml.etree.ElementTree as ET from . import ModuleReturnValue, ExtensionModule -from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, FeatureDeprecatedKwargs, KwargInfo, noPosargs, permittedKwargs, FeatureNew, FeatureNewKwargs, typed_kwargs +from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder @@ -245,7 +245,6 @@ class QtBaseModule(ExtensionModule): KwargInfo('required', (bool, FeatureOptionHolder), default=False), KwargInfo('method', str, default='auto'), ) - @permittedKwargs({'method', 'required'}) def has_tools(self, state: 'ModuleState', args: T.Tuple, kwargs: 'HasToolKwArgs') -> bool: method = kwargs.get('method', 'auto') # We have to cast here because TypedDicts are invariant, even though @@ -395,21 +394,17 @@ class QtBaseModule(ExtensionModule): return ModuleReturnValue(output, [output]) - @FeatureNewKwargs('qt.preprocess', '0.49.0', ['uic_extra_arguments']) - @FeatureNewKwargs('qt.preprocess', '0.44.0', ['moc_extra_arguments']) - @FeatureNewKwargs('qt.preprocess', '0.49.0', ['rcc_extra_arguments']) - @FeatureDeprecatedKwargs('qt.preprocess', '0.59.0', ['sources']) # We can't use typed_pos_args here, the signature is ambiguious @typed_kwargs( 'qt.preprocess', - KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), + KwargInfo('sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[], deprecated='0.59.0'), KwargInfo('qresources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), KwargInfo('ui_files', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), KwargInfo('moc_sources', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), KwargInfo('moc_headers', ContainerTypeInfo(list, (File, str)), listify=True, default=[]), - KwargInfo('moc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), - KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), - KwargInfo('uic_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('moc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.44.0'), + KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.49.0'), + KwargInfo('uic_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.49.0'), KwargInfo('method', str, default='auto'), KwargInfo('include_directories', ContainerTypeInfo(list, IncludeDirsHolder), listify=True, default=[]), KwargInfo('dependencies', ContainerTypeInfo(list, (DependencyHolder, ExternalLibraryHolder)), listify=True, default=[]), @@ -451,9 +446,6 @@ class QtBaseModule(ExtensionModule): return ModuleReturnValue(sources, [sources]) @FeatureNew('qt.compile_translations', '0.44.0') - @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['qresource']) - @FeatureNewKwargs('qt.compile_translations', '0.56.0', ['rcc_extra_arguments']) - @permittedKwargs({'ts_files', 'qresource', 'rcc_extra_arguments', 'install', 'install_dir', 'build_by_default', 'method'}) @noPosargs @typed_kwargs( 'qt.compile_translations', @@ -461,8 +453,8 @@ class QtBaseModule(ExtensionModule): KwargInfo('install', bool, default=False), KwargInfo('install_dir', str), KwargInfo('method', str, default='auto'), - KwargInfo('qresource', str), - KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[]), + KwargInfo('qresource', str, since='0.56.0'), + KwargInfo('rcc_extra_arguments', ContainerTypeInfo(list, str), listify=True, default=[], since='0.56.0'), KwargInfo('ts_files', ContainerTypeInfo(list, (str, File)), listify=True, default=[]), ) def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: 'CompileTranslationsKwArgs') -> ModuleReturnValue: -- cgit v1.1 From d2c1ab40a0c94209d8e13886f3c7d697d30f2507 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 20:48:35 -0700 Subject: interpreter|build: Pass just the executable down to Generator This requires that the interpreter has done the validation, which it now does at all callsites. This simplifies the Generator initializer. --- mesonbuild/modules/qt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 297ef09..76cc4db 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -348,7 +348,7 @@ class QtBaseModule(ExtensionModule): 'output': 'ui_@BASENAME@.h', 'arguments': kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@']} # TODO: This generator isn't added to the generator list in the Interpreter - gen = build.Generator([self.uic], ui_kwargs) # type: ignore + gen = build.Generator(self.uic, ui_kwargs) # type: ignore out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) return ModuleReturnValue(out, [out]) @@ -384,12 +384,12 @@ class QtBaseModule(ExtensionModule): if kwargs['headers']: moc_kwargs = {'output': 'moc_@BASENAME@.cpp', 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) # type: ignore + moc_gen = build.Generator(self.moc, moc_kwargs) # type: ignore output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) if kwargs['sources']: moc_kwargs = {'output': '@BASENAME@.moc', 'arguments': arguments} - moc_gen = build.Generator([self.moc], moc_kwargs) # type: ignore + moc_gen = build.Generator(self.moc, moc_kwargs) # type: ignore output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) return ModuleReturnValue(output, [output]) -- cgit v1.1 From 35bdaada1dfb64366f1533a79fea670502f69732 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 21:13:38 -0700 Subject: interpreter|build: Do Generator keyword argument checking in the interpreter For qt we already have all of the necissary checking in place. Now in the interpreter we have the same, the intrperter does all of the checking, then passed the arguments to the Generator initializer, which just assigns the passed values. This is nice, neat, and clean and fixes the layering violatino between build and interpreter. --- mesonbuild/modules/qt.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 76cc4db..f328027 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -344,12 +344,12 @@ class QtBaseModule(ExtensionModule): "please check your qt{2} installation") raise MesonException(err_msg.format('UIC', f'uic-qt{self.qt_version}', self.qt_version)) - ui_kwargs: T.Dict[str, T.Any] = { # TODO: if Generator was properly annotated… - 'output': 'ui_@BASENAME@.h', - 'arguments': kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@']} # TODO: This generator isn't added to the generator list in the Interpreter - gen = build.Generator(self.uic, ui_kwargs) # type: ignore - out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) + gen = build.Generator( + self.uic, + kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], + ['ui_@BASENAME@.h']) + out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) # type: ignore return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') @@ -382,15 +382,11 @@ class QtBaseModule(ExtensionModule): arguments = kwargs['extra_args'] + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] if kwargs['headers']: - moc_kwargs = {'output': 'moc_@BASENAME@.cpp', - 'arguments': arguments} - moc_gen = build.Generator(self.moc, moc_kwargs) # type: ignore - output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) + moc_gen = build.Generator(self.moc, arguments, ['moc_@BASENAME@.cpp']) + output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) # type: ignore if kwargs['sources']: - moc_kwargs = {'output': '@BASENAME@.moc', - 'arguments': arguments} - moc_gen = build.Generator(self.moc, moc_kwargs) # type: ignore - output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) + moc_gen = build.Generator(self.moc, arguments, ['@BASENAME@.moc']) + output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) # type: ignore return ModuleReturnValue(output, [output]) -- cgit v1.1 From 2043461b87eb93a50fc2ede3783efb157261ed86 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 21:18:49 -0700 Subject: build: Pass name of generator to initializer It's really a property of the Generator what name to use, not something that should be passed to each call to process files. --- mesonbuild/modules/qt.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index f328027..adfc8e2 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -348,8 +348,9 @@ class QtBaseModule(ExtensionModule): gen = build.Generator( self.uic, kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], - ['ui_@BASENAME@.h']) - out = gen.process_files(f'Qt{self.qt_version} ui', kwargs['sources'], state) # type: ignore + ['ui_@BASENAME@.h'], + name=f'Qt{self.qt_version} ui') + out = gen.process_files(kwargs['sources'], state) # type: ignore return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') @@ -382,11 +383,15 @@ class QtBaseModule(ExtensionModule): arguments = kwargs['extra_args'] + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] if kwargs['headers']: - moc_gen = build.Generator(self.moc, arguments, ['moc_@BASENAME@.cpp']) - output.append(moc_gen.process_files(f'Qt{self.qt_version} moc header', kwargs['headers'], state)) # type: ignore + moc_gen = build.Generator( + self.moc, arguments, ['moc_@BASENAME@.cpp'], + name=f'Qt{self.qt_version} moc header') + output.append(moc_gen.process_files(kwargs['headers'], state)) # type: ignore if kwargs['sources']: - moc_gen = build.Generator(self.moc, arguments, ['@BASENAME@.moc']) - output.append(moc_gen.process_files(f'Qt{self.qt_version} moc source', kwargs['sources'], state)) # type: ignore + moc_gen = build.Generator( + self.moc, arguments, ['@BASENAME@.moc'], + name=f'Qt{self.qt_version} moc source') + output.append(moc_gen.process_files(kwargs['sources'], state)) # type: ignore return ModuleReturnValue(output, [output]) -- cgit v1.1 From c42262131706143e1a213d0bac659085822a0759 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 1 Jun 2021 21:39:42 -0700 Subject: interpreterobjects|build: use typed_kwargs for generator.process --- mesonbuild/modules/qt.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index adfc8e2..1d38cbe 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -350,7 +350,7 @@ class QtBaseModule(ExtensionModule): kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], ['ui_@BASENAME@.h'], name=f'Qt{self.qt_version} ui') - out = gen.process_files(kwargs['sources'], state) # type: ignore + out = gen.process_files(kwargs['sources'], state) return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') @@ -386,12 +386,12 @@ class QtBaseModule(ExtensionModule): moc_gen = build.Generator( self.moc, arguments, ['moc_@BASENAME@.cpp'], name=f'Qt{self.qt_version} moc header') - output.append(moc_gen.process_files(kwargs['headers'], state)) # type: ignore + output.append(moc_gen.process_files(kwargs['headers'], state)) if kwargs['sources']: moc_gen = build.Generator( self.moc, arguments, ['@BASENAME@.moc'], name=f'Qt{self.qt_version} moc source') - output.append(moc_gen.process_files(kwargs['sources'], state)) # type: ignore + output.append(moc_gen.process_files(kwargs['sources'], state)) return ModuleReturnValue(output, [output]) -- cgit v1.1 From 2a8a6bb8814bbeeea7b52d1871ed49562fe4575f Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 2 Jun 2021 11:24:22 -0700 Subject: modules/qt: Return GeneratedListHolder instead of GeneratedList This really shouldn't be necissary, but fixing the typing annotations of ModuleReturnValue is much harder than just returning the Holder directly. --- mesonbuild/modules/qt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index 1d38cbe..fb6c3c7 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -26,7 +26,7 @@ from . import ModuleReturnValue, ExtensionModule from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs from ..interpreter import extract_required_kwarg from ..programs import NonExistingExternalProgram -from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder +from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder, GeneratedListHolder if T.TYPE_CHECKING: from . import ModuleState @@ -350,7 +350,7 @@ class QtBaseModule(ExtensionModule): kwargs['extra_args'] + ['-o', '@OUTPUT@', '@INPUT@'], ['ui_@BASENAME@.h'], name=f'Qt{self.qt_version} ui') - out = gen.process_files(kwargs['sources'], state) + out = GeneratedListHolder(gen.process_files(kwargs['sources'], state)) return ModuleReturnValue(out, [out]) @FeatureNew('qt.compile_moc', '0.59.0') -- cgit v1.1 From bfaa529a7a35039d4a782615a428935df5336b94 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Fri, 4 Jun 2021 09:21:15 -0700 Subject: modules/qt: sort and clean up dependencies --- mesonbuild/modules/qt.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'mesonbuild/modules/qt.py') diff --git a/mesonbuild/modules/qt.py b/mesonbuild/modules/qt.py index fb6c3c7..7d752db 100644 --- a/mesonbuild/modules/qt.py +++ b/mesonbuild/modules/qt.py @@ -1,4 +1,5 @@ # Copyright 2015 The Meson development team +# Copyright © 2021 Intel Corporation # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,21 +13,21 @@ # See the License for the specific language governing permissions and # limitations under the License. -from mesonbuild.dependencies import find_external_dependency import os import shutil import typing as T +import xml.etree.ElementTree as ET -from .. import mlog +from . import ModuleReturnValue, ExtensionModule from .. import build from .. import mesonlib -from ..mesonlib import MesonException, File, version_compare -import xml.etree.ElementTree as ET -from . import ModuleReturnValue, ExtensionModule -from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs +from .. import mlog +from ..dependencies import find_external_dependency from ..interpreter import extract_required_kwarg -from ..programs import NonExistingExternalProgram from ..interpreter.interpreterobjects import DependencyHolder, ExternalLibraryHolder, IncludeDirsHolder, FeatureOptionHolder, GeneratedListHolder +from ..interpreterbase import ContainerTypeInfo, FeatureDeprecated, KwargInfo, noPosargs, FeatureNew, typed_kwargs +from ..mesonlib import MesonException, File +from ..programs import NonExistingExternalProgram if T.TYPE_CHECKING: from . import ModuleState @@ -171,7 +172,7 @@ class QtBaseModule(ExtensionModule): if qt.found(): # Get all tools and then make sure that they are the right version self.compilers_detect(state, qt) - if version_compare(qt.version, '>=5.14.0'): + if mesonlib.version_compare(qt.version, '>=5.14.0'): self._rcc_supports_depfiles = True else: mlog.warning('rcc dependencies will not work properly until you move to Qt >= 5.14:', -- cgit v1.1