modules/qt: Allow using generated sources for compile_translations ts_files

pull/9012/head
Dylan Baker 3 years ago
parent a16335a958
commit a7f3703440
  1. 4
      docs/markdown/_include_qt_base.md
  2. 15
      mesonbuild/modules/qt.py

@ -85,7 +85,9 @@ It returns an array of targets and sources to pass to a compilation target.
This method generates the necessary targets to build translation files with
lrelease, it takes no positional arguments, and the following keyword arguments:
- `ts_files` (str | File)[], the list of input translation files produced by Qt's lupdate tool.
- `ts_files` (File | string | custom_target | custom_target index | generator_output)[]:
the list of input translation files produced by Qt's lupdate tool.
*New in 0.60.0*: support for custom_target, custom_target_index, and generator_output.
- `install` bool: when true, this target is installed during the install step (optional).
- `install_dir` string: directory to install to (optional).
- `build_by_default` bool: when set to true, to have this target be built by

@ -93,7 +93,7 @@ if T.TYPE_CHECKING:
method: str
qresource: T.Optional[str]
rcc_extra_arguments: T.List[str]
ts_files: T.List[str]
ts_files: T.List[T.Union[str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList]]
class QtBaseModule(ExtensionModule):
@ -514,10 +514,12 @@ class QtBaseModule(ExtensionModule):
KwargInfo('method', str, default='auto'),
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=[]),
KwargInfo('ts_files', ContainerTypeInfo(list, (str, File, build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)), listify=True, default=[]),
)
def compile_translations(self, state: 'ModuleState', args: T.Tuple, kwargs: 'CompileTranslationsKwArgs') -> ModuleReturnValue:
ts_files = kwargs['ts_files']
if any(isinstance(s, (build.CustomTarget, build.CustomTargetIndex, build.GeneratedList)) for s in ts_files):
FeatureNew.single_use('qt.compile_translations: custom_target or generator for "ts_files" keyword argument', '0.60.0', state.subproject)
install_dir = kwargs['install_dir']
qresource = kwargs['qresource']
if qresource:
@ -546,6 +548,11 @@ class QtBaseModule(ExtensionModule):
raise MesonException('qt.compile_translations: ' +
self.lrelease.name + ' not found')
if qresource:
# In this case we know that ts_files is always a List[str], as
# it's generated above and no ts_files are passed in. However,
# mypy can't figure that out so we use assert to assure it that
# what we're doing is safe
assert isinstance(ts, str), 'for mypy'
outdir = os.path.dirname(os.path.normpath(os.path.join(state.subdir, ts)))
ts = os.path.basename(ts)
else:
@ -553,9 +560,9 @@ class QtBaseModule(ExtensionModule):
cmd = [self.lrelease, '@INPUT@', '-qm', '@OUTPUT@']
lrelease_kwargs = {'output': '@BASENAME@.qm',
'input': ts,
'install': kwargs.get('install', False),
'install': kwargs['install'],
'install_tag': 'i18n',
'build_by_default': kwargs.get('build_by_default', False),
'build_by_default': kwargs['build_by_default'],
'command': cmd}
if install_dir is not None:
lrelease_kwargs['install_dir'] = install_dir

Loading…
Cancel
Save