Repository: mesonbuild/meson

Issue:
gettext() does not allow keywords to be specified
If one uses helpers or wrappers for gettext library, one needs to tell `xgettext` about the keywords.

For example, if i use glib gettext helpers, i need to pass `--keyword=_', '--keyword=N_', '--keyword=C_:1c,2', '--keyword=NC_:1c,2', '--keyword=g_dngettext:2,3'` (`intltoolize` adds appropriate magic to autotools-based buildsystem, so with autotools you don't need to add these yourself) to `xgettext` for it to be able to find all the macro and function invocations.

One should probably read [xgettext man](https://www.gnu.org/software/gettext/manual/html_node/xgettext-Invocation.html) and see which commandline arguments should be supported by `gettext()` in meson. Or maybe it's easier to just allow flags to be passed to `xgettext` as-is (the same way CFLAGS are passed to C compiler). Note that `xgettext` is not a compiler- or platform-specific tool (AFAIK; though its counterpart gettext _library_ _can_ be part of libc, IIRC; Wikipedia mentions Sun gettext, but i don't know whether anyone uses its tools anymore, if it had any; it might not have supported .pot/.po/.mo at all and used different file formats altogether, for all i know), so abstracting away all of its arguments doesn't make much sense, not for portability reasons (i.e. there's no MSVC- or Windows-specific gettext program that expects `/kw foo` instead of `--keyword=foo`). IMHO.



Discussion:
Allowing raw args to be passed directly seems like the most feasible solution.


Resolving patch:
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1052,7 +1052,6 @@ def module_method_callback(self, invalues):
                     raise InterpreterException('Tried to create target %s which already exists.' % v.name)
                 self.build.targets[v.name] = v
             elif isinstance(v, build.InstallScript):
-                print('x')
                 self.build.install_scripts.append(v)
             elif isinstance(v, build.Data):
                 self.build.data.append(v)
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
--- a/mesonbuild/modules/i18n.py
+++ b/mesonbuild/modules/i18n.py
@@ -24,7 +24,8 @@ def gettext(self, state, args, kwargs):
         languages = mesonlib.stringlistify(kwargs.get('languages', []))
         if len(languages) == 0:
             raise coredata.MesonException('List of languages empty.')
-        potargs = [state.environment.get_build_command(), '--internal', 'gettext', 'pot', packagename]
+        extra_args = mesonlib.stringlistify(kwargs.get('args', []))
+        potargs = [state.environment.get_build_command(), '--internal', 'gettext', 'pot', packagename] + extra_args
         pottarget = build.RunTarget(packagename + '-pot', sys.executable, potargs, state.subdir)
         gmoargs = [state.environment.get_build_command(), '--internal', 'gettext', 'gen_gmo'] + languages
         gmotarget = build.RunTarget(packagename + '-gmo', sys.executable, gmoargs, state.subdir)
diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py
--- a/mesonbuild/scripts/gettext.py
+++ b/mesonbuild/scripts/gettext.py
@@ -16,11 +16,11 @@
 
 import os, subprocess, shutil
 
-def run_potgen(src_sub, pkgname, langs):
+def run_potgen(src_sub, pkgname, args):
     listfile = os.path.join(src_sub, 'POTFILES')
     ofile = os.path.join(src_sub, pkgname + '.pot')
-    return subprocess.call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, listfile,
-                            '-D', os.environ['MESON_SOURCE_ROOT'], '-k_', '-o', ofile])
+    return subprocess.call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, '-f', listfile,
+                            '-D', os.environ['MESON_SOURCE_ROOT'], '-k_', '-o', ofile] + args)
 
 def gen_gmo(src_sub, bld_sub, langs):
     for l in langs:


Test patch: