Make gettext targets no-ops if gettext is not installed. Closes: #821.

pull/5769/head
Jussi Pakkanen 6 years ago
parent 32bd8a3847
commit 5f2e44b0dd
  1. 7
      docs/markdown/snippets/nogettext.md
  2. 16
      mesonbuild/modules/i18n.py

@ -0,0 +1,7 @@
## Gettext targets are ignored if `gettext` is not installed
Previously the `i18n` module has errored out when `gettext` tools are
not installed on the system. Starting with this version they will
become no-ops instead. This makes it easier to build projects on
minimal environments (such as when bootstrapping) that do not have
translation tools installed.

@ -15,7 +15,7 @@
import shutil
from os import path
from .. import coredata, mesonlib, build
from .. import coredata, mesonlib, build, mlog
from ..mesonlib import MesonException
from . import ModuleReturnValue
from . import ExtensionModule
@ -55,8 +55,18 @@ PRESET_ARGS = {
]
}
class I18nModule(ExtensionModule):
nogettext_warning_printed = False
@classmethod
def nogettext_warning(cls):
if not cls.nogettext_warning_printed:
mlog.warning('Gettext not found, all translation targets will be ignored.')
cls.nogettext_warning_printed = True
return ModuleReturnValue(None, [])
@staticmethod
def _get_data_dirs(state, dirs):
"""Returns source directories of relative paths"""
@ -67,6 +77,8 @@ class I18nModule(ExtensionModule):
@FeatureNewKwargs('i18n.merge_file', '0.51.0', ['args'])
@permittedKwargs(build.CustomTarget.known_kwargs | {'data_dirs', 'po_dir', 'type', 'args'})
def merge_file(self, state, args, kwargs):
if not shutil.which('xgettext'):
return self.nogettext_warning()
podir = kwargs.pop('po_dir', None)
if not podir:
raise MesonException('i18n: po_dir is a required kwarg')
@ -120,7 +132,7 @@ class I18nModule(ExtensionModule):
if len(args) != 1:
raise coredata.MesonException('Gettext requires one positional argument (package name).')
if not shutil.which('xgettext'):
raise coredata.MesonException('Can not do gettext because xgettext is not installed.')
return self.nogettext_warning()
packagename = args[0]
languages = mesonlib.stringlistify(kwargs.get('languages', []))
datadirs = self._get_data_dirs(state, mesonlib.stringlistify(kwargs.get('data_dirs', [])))

Loading…
Cancel
Save