diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index 522e97982353..4630815954f1 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py @@ -61,6 +61,7 @@ class MocCompilerKwArgs(TypedDict): include_directories: T.List[T.Union[str, build.IncludeDirs]] dependencies: T.List[T.Union[Dependency, ExternalLibrary]] preserve_paths: bool + output_json: bool class PreprocessKwArgs(TypedDict): @@ -75,6 +76,7 @@ class PreprocessKwArgs(TypedDict): include_directories: T.List[T.Union[str, build.IncludeDirs]] dependencies: T.List[T.Union[Dependency, ExternalLibrary]] method: str + output_json: bool preserve_paths: bool class HasToolKwArgs(kwargs.ExtractRequired): @@ -106,6 +108,7 @@ class QtBaseModule(ExtensionModule): _tools_detected = False _rcc_supports_depfiles = False _moc_supports_depfiles = False + _moc_supports_json = False def __init__(self, interpreter: 'Interpreter', qt_version: int = 5): ExtensionModule.__init__(self, interpreter) @@ -183,6 +186,7 @@ def _detect_tools(self, state: 'ModuleState', method: str, required: bool = True self.compilers_detect(state, qt) if version_compare(qt.version, '>=5.15.0'): self._moc_supports_depfiles = True + self._moc_supports_json = True else: mlog.warning('moc dependencies will not work properly until you move to Qt >= 5.15', fatal=False) if version_compare(qt.version, '>=5.14.0'): @@ -444,6 +448,7 @@ def _compile_ui_impl(self, state: ModuleState, kwargs: UICompilerKwArgs) -> buil KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), KwargInfo('preserve_paths', bool, default=False, since='1.4.0'), + KwargInfo('output_json', bool, default=False, since='1.6.0'), ) def compile_moc(self, state: ModuleState, args: T.Tuple, kwargs: MocCompilerKwArgs) -> ModuleReturnValue: if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in kwargs['headers']): @@ -476,20 +481,28 @@ def _compile_moc_impl(self, state: ModuleState, kwargs: MocCompilerKwArgs) -> T. output: T.List[build.GeneratedList] = [] + do_output_json : bool = self._moc_supports_json and kwargs['output_json'] # depfile arguments (defaults to .d) DEPFILE_ARGS: T.List[str] = ['--output-dep-file'] if self._moc_supports_depfiles else [] + JSON_ARGS: T.List[str] = ['--output-json'] if do_output_json else [] - arguments = kwargs['extra_args'] + DEPFILE_ARGS + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT@'] + arguments = kwargs['extra_args'] + DEPFILE_ARGS + JSON_ARGS + inc + compile_args + ['@INPUT@', '-o', '@OUTPUT0@'] preserve_path_from = os.path.join(state.source_root, state.subdir) if kwargs['preserve_paths'] else None if kwargs['headers']: + header_gen_output: T.List[str] = ['moc_@BASENAME@.cpp'] + if do_output_json: + header_gen_output.append('moc_@BASENAME@.cpp.json') moc_gen = build.Generator( - self.tools['moc'], arguments, ['moc_@BASENAME@.cpp'], + self.tools['moc'], arguments, header_gen_output, depfile='moc_@BASENAME@.cpp.d', name=f'Qt{self.qt_version} moc header') output.append(moc_gen.process_files(kwargs['headers'], state, preserve_path_from)) if kwargs['sources']: + source_gen_output: T.List[str] = ['@BASENAME@.moc'] + if do_output_json: + source_gen_output.append('@BASENAME@.moc.json') moc_gen = build.Generator( - self.tools['moc'], arguments, ['@BASENAME@.moc'], + self.tools['moc'], arguments, source_gen_output, depfile='@BASENAME@.moc.d', name=f'Qt{self.qt_version} moc source') output.append(moc_gen.process_files(kwargs['sources'], state, preserve_path_from)) @@ -511,6 +524,7 @@ def _compile_moc_impl(self, state: ModuleState, kwargs: MocCompilerKwArgs) -> T. KwargInfo('include_directories', ContainerTypeInfo(list, (build.IncludeDirs, str)), listify=True, default=[]), KwargInfo('dependencies', ContainerTypeInfo(list, (Dependency, ExternalLibrary)), listify=True, default=[]), KwargInfo('preserve_paths', bool, default=False, since='1.4.0'), + KwargInfo('output_json', bool, default=False, since='1.6.0'), ) def preprocess(self, state: ModuleState, args: T.List[T.Union[str, File]], kwargs: PreprocessKwArgs) -> ModuleReturnValue: _sources = args[1:] @@ -552,6 +566,7 @@ def preprocess(self, state: ModuleState, args: T.List[T.Union[str, File]], kwarg 'dependencies': kwargs['dependencies'], 'method': method, 'preserve_paths': kwargs['preserve_paths'], + 'output_json': kwargs['output_json'] } sources.extend(self._compile_moc_impl(state, moc_kwargs))