aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/modules/i18n.py
diff options
context:
space:
mode:
authorMatthias Klumpp <matthias@tenstral.net>2021-12-18 04:26:46 +0100
committerMatthias Klumpp <matthias@tenstral.net>2022-01-21 22:26:17 +0100
commit02fb0c3f8bb60d88998c8a8c7d090ecc864ed04c (patch)
treed94965290f00c5d1a4173c274ca9575328a43624 /mesonbuild/modules/i18n.py
parente60d358e0482edc56b6441aaa3021d83dd14b527 (diff)
downloadmeson-02fb0c3f8bb60d88998c8a8c7d090ecc864ed04c.zip
meson-02fb0c3f8bb60d88998c8a8c7d090ecc864ed04c.tar.gz
meson-02fb0c3f8bb60d88998c8a8c7d090ecc864ed04c.tar.bz2
i18n: Add support for joining XML localization via itstool
Diffstat (limited to 'mesonbuild/modules/i18n.py')
-rw-r--r--mesonbuild/modules/i18n.py79
1 files changed, 79 insertions, 0 deletions
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
index 379b766..d92e334 100644
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -59,6 +59,20 @@ if T.TYPE_CHECKING:
languages: T.List[str]
preset: T.Optional[str]
+ class ItsJoinFile(TypedDict):
+
+ input: T.List[T.Union[
+ str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex,
+ build.ExtractedObjects, build.GeneratedList, ExternalProgram,
+ mesonlib.File]]
+ output: T.List[str]
+ build_by_default: bool
+ install: bool
+ install_dir: T.List[T.Union[str, bool]]
+ install_tag: T.List[str]
+ its_files: T.List[str]
+ mo_targets: T.List[T.Union[build.BuildTarget, build.CustomTarget, build.CustomTargetIndex]]
+
_ARGS: KwargInfo[T.List[str]] = KwargInfo(
'args',
@@ -115,6 +129,7 @@ class I18nModule(ExtensionModule):
self.methods.update({
'merge_file': self.merge_file,
'gettext': self.gettext,
+ 'itstool_join': self.itstool_join,
})
@staticmethod
@@ -122,6 +137,10 @@ class I18nModule(ExtensionModule):
mlog.warning('Gettext not found, all translation targets will be ignored.', once=True)
@staticmethod
+ def noitstool_error() -> T.NoReturn:
+ raise mesonlib.MesonException('Did not find itstool. Please install it to continue.')
+
+ @staticmethod
def _get_data_dirs(state: 'ModuleState', dirs: T.Iterable[str]) -> T.List[str]:
"""Returns source directories of relative paths"""
src_dir = path.join(state.environment.get_source_dir(), state.subdir)
@@ -269,5 +288,65 @@ class I18nModule(ExtensionModule):
return ModuleReturnValue([gmotargets, pottarget, updatepotarget], targets)
+ @FeatureNew('i18n.itstool_join', '0.61.0')
+ @noPosargs
+ @typed_kwargs(
+ 'i18n.itstool_join',
+ CT_BUILD_BY_DEFAULT,
+ CT_INPUT_KW,
+ CT_INSTALL_DIR_KW,
+ CT_INSTALL_TAG_KW,
+ CT_OUTPUT_KW,
+ INSTALL_KW,
+ _ARGS.evolve(),
+ KwargInfo('its_files', ContainerTypeInfo(list, str)),
+ KwargInfo('mo_targets', ContainerTypeInfo(list, build.CustomTarget), required=True),
+ )
+ def itstool_join(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'ItsJoinFile') -> ModuleReturnValue:
+ if not shutil.which('itstool'):
+ self.noitstool_error()
+ mo_targets = kwargs['mo_targets']
+ its_files = kwargs.get('its_files', [])
+
+ mo_fnames = []
+ for target in mo_targets:
+ mo_fnames.append(path.join(target.get_subdir(), target.get_outputs()[0]))
+
+ command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget,
+ build.CustomTargetIndex, 'ExternalProgram', mesonlib.File]] = []
+ command.extend(state.environment.get_build_command())
+ command.extend([
+ '--internal', 'itstool', 'join',
+ '-i', '@INPUT@',
+ '-o', '@OUTPUT@'
+ ])
+ if its_files:
+ for fname in its_files:
+ if not path.isabs(fname):
+ fname = path.join(state.environment.source_dir, state.subdir, fname)
+ command.extend(['--its', fname])
+ command.extend(mo_fnames)
+
+ build_by_default = kwargs['build_by_default']
+ if build_by_default is None:
+ build_by_default = kwargs['install']
+
+ real_kwargs = {
+ 'build_by_default': build_by_default,
+ 'command': command,
+ 'depends': mo_targets,
+ 'install': kwargs['install'],
+ 'install_dir': kwargs['install_dir'],
+ 'output': kwargs['output'],
+ 'input': kwargs['input'],
+ 'install_tag': kwargs['install_tag'],
+ }
+
+ ct = build.CustomTarget('', state.subdir, state.subproject,
+ T.cast(T.Dict[str, T.Any], real_kwargs))
+
+ return ModuleReturnValue(ct, [ct])
+
+
def initialize(interp: 'Interpreter') -> I18nModule:
return I18nModule(interp)