forked from kiss-community/repo
76 lines
3.0 KiB
Diff
76 lines
3.0 KiB
Diff
From a87e69fa10544310f6e7ef60a01377c8c52b3b2c Mon Sep 17 00:00:00 2001
|
|
From: Jussi Pakkanen <jpakkane@gmail.com>
|
|
Date: Fri, 2 Aug 2019 19:25:19 +0300
|
|
Subject: [PATCH] Make gettext targets no-ops if gettext is not installed.
|
|
Closes: #821.
|
|
|
|
---
|
|
docs/markdown/snippets/nogettext.md | 7 +++++++
|
|
mesonbuild/modules/i18n.py | 16 ++++++++++++++--
|
|
2 files changed, 21 insertions(+), 2 deletions(-)
|
|
create mode 100644 docs/markdown/snippets/nogettext.md
|
|
|
|
diff --git a/docs/markdown/snippets/nogettext.md b/docs/markdown/snippets/nogettext.md
|
|
new file mode 100644
|
|
index 0000000000..5053226743
|
|
--- /dev/null
|
|
+++ b/docs/markdown/snippets/nogettext.md
|
|
@@ -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.
|
|
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
|
|
index 76b9d63018..1efc7b579f 100644
|
|
--- a/mesonbuild/modules/i18n.py
|
|
+++ b/mesonbuild/modules/i18n.py
|
|
@@ -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 @@
|
|
]
|
|
}
|
|
|
|
+
|
|
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 @@ def _get_data_dirs(state, dirs):
|
|
@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 @@ def gettext(self, state, args, kwargs):
|
|
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', [])))
|