Skip to content

Commit

Permalink
i18n: be build-compatible (but not developer-compatible) with gettext…
Browse files Browse the repository at this point in the history
…-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.
  • Loading branch information
eli-schwartz authored and nirbheek committed Jun 2, 2022
1 parent 86d1f10 commit 9ed4948
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions mesonbuild/modules/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -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}'

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 9ed4948

Please sign in to comment.