Skip to content

WIP: qt: properly handle generated sources as inputs for resources #14604

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 30 additions & 29 deletions mesonbuild/modules/_qt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2015 The Meson development team
# Copyright © 2021-2023 Intel Corporation
# Copyright © 2021-2025 Intel Corporation

from __future__ import annotations

Expand Down Expand Up @@ -178,6 +178,8 @@ class QmlModuleKwArgs(TypedDict):
install_dir: str
install: bool

_RESOURCE_GENERATED_ERR_MSG = 'This feature was added in 0.60, but does not work correctly due to bugs until 1.9'

def _list_in_set_validator(choices: T.Set[str]) -> T.Callable[[T.List[str]], T.Optional[str]]:
"""Check that the choice given was one of the given set."""
def inner(checklist: T.List[str]) -> T.Optional[str]:
Expand Down Expand Up @@ -400,6 +402,11 @@ def has_tools(self, state: ModuleState, args: T.Tuple, kwargs: HasToolKwArgs) ->
ContainerTypeInfo(list, (File, str, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList), allow_empty=False),
listify=True,
required=True,
since_values={
build.CustomTarget: ('1.9', _RESOURCE_GENERATED_ERR_MSG),
build.CustomTargetIndex: ('1.9', _RESOURCE_GENERATED_ERR_MSG),
build.GeneratedList: ('1.9', _RESOURCE_GENERATED_ERR_MSG),
}
),
KwargInfo('extra_args', ContainerTypeInfo(list, str), listify=True, default=[]),
KwargInfo('method', str, default='auto')
Expand All @@ -409,9 +416,6 @@ def compile_resources(self, state: 'ModuleState', args: T.Tuple, kwargs: 'Resour

Uses CustomTargets to generate .cpp files from .qrc files.
"""
if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in kwargs['sources']):
FeatureNew.single_use('qt.compile_resources: custom_target or generator for "sources" keyword argument',
'0.60.0', state.subproject, location=state.current_node)
out = self._compile_resources_impl(state, kwargs)
return ModuleReturnValue(out, [out])

Expand All @@ -430,19 +434,13 @@ def _compile_resources_impl(self, state: 'ModuleState', kwargs: 'ResourceCompile
DEPFILE_ARGS: T.List[str] = ['--depfile', '@DEPFILE@'] if self._rcc_supports_depfiles else []

name = kwargs['name']
sources: T.List['FileOrString'] = []
for s in kwargs['sources']:
if isinstance(s, (str, File)):
sources.append(s)
else:
sources.extend(s.get_outputs())
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.
if name:
qrc_deps: T.List[File] = []
for s in sources:
for s in kwargs['sources']:
qrc_deps.extend(self._parse_qrc_deps(state, s))

res_target = build.CustomTarget(
Expand All @@ -451,34 +449,37 @@ def _compile_resources_impl(self, state: 'ModuleState', kwargs: 'ResourceCompile
state.subproject,
state.environment,
self.tools['rcc'].get_command() + ['-name', name, '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS,
sources,
kwargs['sources'],
[f'{name}.cpp'],
depend_files=qrc_deps,
depfile=f'{name}.d',
description='Compiling Qt resources {}',
)
targets.append(res_target)
else:
for rcc_file in sources:
for rcc_file in kwargs['sources']:
qrc_deps = self._parse_qrc_deps(state, rcc_file)
if isinstance(rcc_file, str):
basename = os.path.basename(rcc_file)
basenames = [os.path.basename(rcc_file)]
elif isinstance(rcc_file, File):
basenames = [rcc_file.fname]
else:
basename = os.path.basename(rcc_file.fname)
name = f'qt{self.qt_version}-{basename.replace(".", "_")}'
res_target = build.CustomTarget(
name,
state.subdir,
state.subproject,
state.environment,
self.tools['rcc'].get_command() + ['-name', '@BASENAME@', '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS,
[rcc_file],
[f'{name}.cpp'],
depend_files=qrc_deps,
depfile=f'{name}.d',
description='Compiling Qt resources {}',
)
targets.append(res_target)
basenames = rcc_file.get_outputs()
for basename in basenames:
name = f'qt{self.qt_version}-{basename.replace(".", "_")}'
res_target = build.CustomTarget(
name,
state.subdir,
state.subproject,
state.environment,
self.tools['rcc'].get_command() + ['-name', '@BASENAME@', '-o', '@OUTPUT@'] + extra_args + ['@INPUT@'] + DEPFILE_ARGS,
[rcc_file],
[f'{name}.cpp'],
depend_files=qrc_deps,
depfile=f'{name}.d',
description='Compiling Qt resources {}',
)
targets.append(res_target)

return targets

Expand Down
5 changes: 4 additions & 1 deletion test cases/frameworks/4 qt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ project('qt4, qt5, and qt6 build test', 'cpp',
# Qt6 requires C++ 17 support
default_options : ['cpp_std=c++17'])

fs = import('fs')
stuff2_copy = fs.copyfile('stuff2.qrc')

# Visit the subdir before entering the loop
subdir('mocdep')

Expand Down Expand Up @@ -89,7 +92,7 @@ foreach qt : ['qt4', 'qt5', 'qt6']
# Test that setting a unique name with a positional argument works
qtmodule.compile_resources(
name : qt + 'teststuff',
sources : files(['stuff.qrc', 'stuff2.qrc']),
sources : [files('stuff.qrc'), stuff2_copy],
method : get_option('method')
)

Expand Down
Loading