From 9ed49480309343615e3c948a56afcd3c6d29251d Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sat, 7 May 2022 23:10:13 -0400 Subject: [PATCH] i18n: be build-compatible (but not developer-compatible) with gettext-tiny For maintainer targets, we need some more tools that gettext-tiny doesn't implement. It's a shame to cause NLS to be completely disabled in such environments, so instead just issue a warning and continue. Before 0.62.0 these were never checked for, and would simply fail at runtime, probably. In theory, the user might install the tools in between configuring and building, and then the maintainer targets would begin to work. Return to that behavior -- we still create the targets, which will *probably* fail, but might not -- and for existing integrations, failing at `ninja foo-update-po` with "error, program msgmerge not found" is a bit more discoverable than ninja saying "what do you mean, there's no such target". We still have the 0.62.0 preferred behavior of trying to find the programs, succeeding in all cases other than gettext-tiny, and guaranteeing that their paths are set up in a machine-file-respecting manner. --- mesonbuild/modules/i18n.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index 6c6c7fd9b33a..9235014ca5d6 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -140,10 +140,6 @@ def __init__(self, interpreter: 'Interpreter'): 'xgettext': None, } - @staticmethod - def nogettext_warning(location: BaseNode) -> None: - mlog.warning('Gettext not found, all translation targets will be ignored.', once=True, location=location) - @staticmethod def _get_data_dirs(state: 'ModuleState', dirs: T.Iterable[str]) -> T.List[str]: """Returns source directories of relative paths""" @@ -222,13 +218,18 @@ def merge_file(self, state: 'ModuleState', args: T.List['TYPE_var'], kwargs: 'Me ), ) def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gettext') -> ModuleReturnValue: - for tool in ['msgfmt', 'msginit', 'msgmerge', 'xgettext']: + for tool, strict in [('msgfmt', True), ('msginit', False), ('msgmerge', False), ('xgettext', False)]: if self.tools[tool] is None: self.tools[tool] = state.find_program(tool, required=False, for_machine=mesonlib.MachineChoice.BUILD) # still not found? if not self.tools[tool].found(): - self.nogettext_warning(state.current_node) - return ModuleReturnValue(None, []) + if strict: + mlog.warning('Gettext not found, all translation (po) targets will be ignored.', + once=True, location=state.current_node) + return ModuleReturnValue(None, []) + else: + mlog.warning(f'{tool!r} not found, maintainer targets will not work', + once=True, fatal=False, location=state.current_node) packagename = args[0] pkg_arg = f'--pkgname={packagename}' @@ -254,7 +255,8 @@ def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gettext') - potargs.append(datadirs) if extra_arg: potargs.append(extra_arg) - potargs.append('--xgettext=' + self.tools['xgettext'].get_path()) + if self.tools['xgettext'].found(): + potargs.append('--xgettext=' + self.tools['xgettext'].get_path()) pottarget = build.RunTarget(packagename + '-pot', potargs, [], state.subdir, state.subproject) targets.append(pottarget) @@ -295,7 +297,8 @@ def gettext(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gettext') - if extra_arg: updatepoargs.append(extra_arg) for tool in ['msginit', 'msgmerge']: - updatepoargs.append(f'--{tool}=' + self.tools[tool].get_path()) + if self.tools[tool].found(): + updatepoargs.append(f'--{tool}=' + self.tools[tool].get_path()) updatepotarget = build.RunTarget(packagename + '-update-po', updatepoargs, [], state.subdir, state.subproject) targets.append(updatepotarget)