Skip to content

Add qt6.generate_qrc #14619

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 2 commits 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
13 changes: 13 additions & 0 deletions docs/markdown/Qt6-module.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,19 @@ replaced with `_`. Type registration may be invoked explicitly using
See [Qt documentation](https://doc.qt.io/qt-6/resources.html#explicit-loading-and-unloading-of-embedded-resources)
for more information

## generate_qrc

*New in 1.9.0*

Generates a `.qrc` file that contains teh given files.

It takes no positional arguments, and the following keyword arguments:
- `files` (File | string | custom_target | custom_target index | generator_output)[]:
A list of files that to be included in the `.qrc`.<br/>
- `output` string:
The name of the `.qrc` file.<br/>
- `prefix` (string | empty):
If provides it sets the `prefix` property in the `.qrc`.<br/>

## Dependencies

Expand Down
42 changes: 42 additions & 0 deletions mesonbuild/modules/_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@ class QmlModuleKwArgs(TypedDict):
install_dir: str
install: bool

class GenerateQrcKwArgs(TypedDict):

files: T.Sequence[T.Union[FileOrString, build.GeneratedTypes]]
output: str
prefix: str


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 @@ -219,6 +226,7 @@ def __init__(self, interpreter: Interpreter, qt_version: int = 5):
'compile_ui': self.compile_ui,
'compile_moc': self.compile_moc,
'qml_module': self.qml_module,
'generate_qrc': self.generate_qrc,
})

def compilers_detect(self, state: ModuleState, qt_dep: QtDependencyType) -> None:
Expand Down Expand Up @@ -1170,3 +1178,37 @@ def qml_module(self, state: ModuleState, args: T.Tuple[str], kwargs: QmlModuleKw
output.extend(self._compile_resources_impl(state, compile_resource_kwargs))

return ModuleReturnValue(output, [output])

@FeatureNew('qt.generate_qrc', '1.8')
@noPosargs
@typed_kwargs(
'qt.generate_qrc',
KwargInfo('output', str, required=True),
KwargInfo('files', ContainerTypeInfo(list, (File, str, build.CustomTarget)), listify=True, required=True),
KwargInfo('prefix', str, default=''),
)
def generate_qrc(self, state: ModuleState, args: T.Tuple[str], kwargs: GenerateQrcKwArgs) -> ModuleReturnValue:
command = [
'--internal',
'generate_qrc',
'--output',
'@OUTPUT@',
]

if kwargs['prefix'] != '':
command += ['--prefix', kwargs['prefix']]

command.append('@INPUT')

qrc_target = build.CustomTarget(
"generate_qrc_" + kwargs['output'],
state.subdir,
state.subproject,
state.environment,
state.environment.get_build_command() + command,
kwargs['files'],
[kwargs['output']],
description='Generate qrc ' + kwargs["output"],
)

return ModuleReturnValue(qrc_target, [qrc_target])
27 changes: 27 additions & 0 deletions mesonbuild/scripts/generate_qrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import argparse
import typing as T
import xml.etree.ElementTree as ET

parser = argparse.ArgumentParser()
parser.add_argument('--output')
parser.add_argument("--prefix")
parser.add_argument('sources', default=[], nargs='*')

def run(argv: T.List[str]) -> int:
options, args = parser.parse_known_args(argv)

rcc = ET.Element('RCC')
qresource = ET.SubElement(rcc, 'qresource')

if options.prefix:
qresource.set("prefix", options.prefix)

for source in options.sources:
ET.SubElement(qresource, 'file').text = source

tree = ET.ElementTree(rcc)
ET.indent(tree, space=' ', level=0)
tree.write(os.path.join(options.output))

return 0
1 change: 1 addition & 0 deletions test cases/frameworks/4 qt/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,6 @@ foreach qt : ['qt4', 'qt5', 'qt6']
accept_versions = ['>=@0@'.format(qtdep.version()), '<@0@'.format(qtdep.version()[0].to_int() + 1)]
dependency(qt, modules: qt_modules, version: accept_versions, method : get_option('method'))

qtmodule.generate_qrc(files: ['test.json'], output: 'test.qrc')
endif
endforeach
Loading