qt: register existing .qrc to fix build dependencies
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0217394..c4400dd 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py
@@ -2186,12 +2186,14 @@ depfile: T.Optional[str] = None, capture: bool = False, depends: T.Optional[T.Sequence[TargetDepends]] = None, + depend_files: T.Optional[T.Sequence[File]] = None, name: str = 'Generator'): self.environment = env self.exe = exe self.depfile = depfile self.capture = capture self.depends: T.List[TargetDepends] = list(depends or []) + self.depend_files: T.List[File] = list(depend_files or []) self.arglist = arguments self.outputs = output self.name = name @@ -2279,7 +2281,7 @@ self.infilelist: T.List[FileMaybeInTargetPrivateDir] = [] self.outfilelist: T.List[str] = [] self.outmap: T.Dict[FileMaybeInTargetPrivateDir, T.List[str]] = {} - self.depend_files: T.List[File] = [] + self.depend_files: T.List[File] = self.generator.depend_files.copy() if self.extra_args is None: self.extra_args: T.List[str] = []
diff --git a/mesonbuild/modules/_qt.py b/mesonbuild/modules/_qt.py index e775660..14e5e5e 100644 --- a/mesonbuild/modules/_qt.py +++ b/mesonbuild/modules/_qt.py
@@ -914,6 +914,7 @@ self.tools['qmlcachegen'], command_args, [f'{target_name}_@BASENAME@.cpp'], + depend_files=[kwargs['qml_qrc']], name=f'Qml cache generation for {target_name}') output: T.List[T.Union[build.CustomTarget, build.GeneratedList]] = []
diff --git a/test cases/unit/146 qml cache resource dependency/Main.qml b/test cases/unit/146 qml cache resource dependency/Main.qml new file mode 100644 index 0000000..f22142a --- /dev/null +++ b/test cases/unit/146 qml cache resource dependency/Main.qml
@@ -0,0 +1,5 @@ +import QtQml + +QtObject { + property int answer: 42 +}
diff --git a/test cases/unit/146 qml cache resource dependency/meson.build b/test cases/unit/146 qml cache resource dependency/meson.build new file mode 100644 index 0000000..732d850 --- /dev/null +++ b/test cases/unit/146 qml cache resource dependency/meson.build
@@ -0,0 +1,17 @@ +project('qml cache resource dependency', 'cpp', meson_version: '>= 1.7.0') + +qt = import('qt6') +qtdep = dependency('qt6', modules: ['Core', 'Qml'], version: '>= 6.2', required: false) +if not qtdep.found() or not qt.has_tools(tools: ['qmlcachegen', 'rcc'], required: false) + error('MESON_SKIP_TEST Qt6 QML tools not found') +endif + +sources = qt.qml_module( + 'MyModule', + qml_sources: files('Main.qml'), + generate_qmltype: false, + resources_prefix: get_option('resource_prefix'), +) + +# Only build the generated sources: compiling them would require Qt's private headers. +static_library('cache', sources, name_prefix: '', name_suffix: 'a', dependencies: qtdep)
diff --git a/test cases/unit/146 qml cache resource dependency/meson.options b/test cases/unit/146 qml cache resource dependency/meson.options new file mode 100644 index 0000000..1fc5a20 --- /dev/null +++ b/test cases/unit/146 qml cache resource dependency/meson.options
@@ -0,0 +1 @@ +option('resource_prefix', type: 'string', value: '/old')
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py index b8532ed..b719b59 100644 --- a/unittests/allplatformstests.py +++ b/unittests/allplatformstests.py
@@ -1521,6 +1521,22 @@ self.utime(os.path.join(testdir, 'srcgen.py')) self.assertRebuiltTarget('basic') + def test_qml_cache_resource_dependency(self): + if self.backend is not Backend.ninja: + raise SkipTest('This test requires the Ninja backend') + testdir = os.path.join(self.unit_test_dir, '146 qml cache resource dependency') + self.init(testdir) + cache_source = 'cache.a.p/MyModule_Main.cpp' + loader = 'MyModule_qmlcache_loader.cpp' + self.build(cache_source, extra_args=[loader]) + for source in (cache_source, loader): + self.assertIn('_old_MyModule_Main_qml', Path(self.builddir, source).read_text(encoding='utf-8')) + + self.setconf('-Dresource_prefix=/new', will_build=False) + self.build(cache_source, extra_args=[loader]) + for source in (cache_source, loader): + self.assertIn('_new_MyModule_Main_qml', Path(self.builddir, source).read_text(encoding='utf-8')) + def test_long_opt_vs_D(self): ''' Test that conflicts between -D for builtin options and the corresponding