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.
pull/10365/head
Eli Schwartz 3 years ago
parent de2c091ba6
commit 915a468ed3
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 21
      mesonbuild/modules/i18n.py

@ -140,10 +140,6 @@ class I18nModule(ExtensionModule):
'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"""
@ -223,13 +219,18 @@ class I18nModule(ExtensionModule):
),
)
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}'
@ -258,7 +259,8 @@ class I18nModule(ExtensionModule):
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,
state.environment, default_env=False)
targets.append(pottarget)
@ -305,7 +307,8 @@ class I18nModule(ExtensionModule):
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,
state.environment, default_env=False)
targets.append(updatepotarget)

Loading…
Cancel
Save