aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/backend/ninjabackend.py52
-rw-r--r--mesonbuild/build.py1
-rw-r--r--mesonbuild/interpreter.py11
-rw-r--r--mesonbuild/mesonmain.py3
-rw-r--r--mesonbuild/modules/i18n.py44
-rw-r--r--mesonbuild/scripts/gettext.py65
-rw-r--r--mesonbuild/scripts/meson_install.py14
-rw-r--r--test cases/frameworks/6 gettext/meson.build2
-rw-r--r--test cases/frameworks/6 gettext/po/intltest.pot4
-rw-r--r--test cases/frameworks/6 gettext/po/meson.build3
10 files changed, 119 insertions, 80 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 73fd389..bd6f4db 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -176,9 +176,6 @@ int dummy;
self.generate_phony(outfile)
outfile.write('# Build rules for targets\n\n')
[self.generate_target(t, outfile) for t in self.build.get_targets().values()]
- if len(self.build.pot) > 0:
- outfile.write('# Build rules for localisation.\n\n')
- self.generate_po(outfile)
outfile.write('# Test rules\n\n')
self.generate_tests(outfile)
outfile.write('# Install rules\n\n')
@@ -428,24 +425,6 @@ int dummy;
elem.write(outfile)
self.processed_targets[target.name + target.type_suffix()] = True
- def generate_po(self, outfile):
- for p in self.build.pot:
- (packagename, languages, subdir) = p
- input_file = os.path.join(subdir, 'POTFILES')
- elem = NinjaBuildElement(self.all_outputs, 'pot', 'GEN_POT', [])
- elem.add_item('PACKAGENAME', packagename)
- elem.add_item('OUTFILE', packagename + '.pot')
- elem.add_item('FILELIST', os.path.join(self.environment.get_source_dir(), input_file))
- elem.add_item('OUTDIR', os.path.join(self.environment.get_source_dir(), subdir))
- elem.write(outfile)
- for l in languages:
- infile = os.path.join(self.environment.get_source_dir(), subdir, l + '.po')
- outfilename = os.path.join(subdir, l + '.gmo')
- lelem = NinjaBuildElement(self.all_outputs, outfilename, 'GEN_GMO', infile)
- lelem.add_item('INFILE', infile)
- lelem.add_item('OUTFILE', outfilename)
- lelem.write(outfile)
-
def generate_coverage_rules(self, outfile):
(gcovr_exe, lcov_exe, genhtml_exe) = environment.find_coverage_tools()
added_rule = False
@@ -496,7 +475,6 @@ int dummy;
self.generate_header_install(d)
self.generate_man_install(d)
self.generate_data_install(d)
- self.generate_po_install(d, elem)
self.generate_custom_install_script(d)
self.generate_subdir_install(d)
elem.write(outfile)
@@ -504,17 +482,6 @@ int dummy;
ofile = open(install_data_file, 'wb')
pickle.dump(d, ofile)
- def generate_po_install(self, d, elem):
- for p in self.build.pot:
- (package_name, languages, subdir) = p
- # FIXME: assumes only one po package per source
- d.po_package_name = package_name
- for lang in languages:
- rel_src = os.path.join(subdir, lang + '.gmo')
- src_file = os.path.join(self.environment.get_build_dir(), rel_src)
- d.po.append((src_file, self.environment.coredata.get_builtin_option('localedir'), lang))
- elem.add_dep(rel_src)
-
def generate_target_install(self, d):
libdir = self.environment.get_libdir()
bindir = self.environment.get_bindir()
@@ -658,25 +625,6 @@ int dummy;
outfile.write(" command = %s %s %s %s %s %s --backend ninja\n" % c)
outfile.write(' description = Regenerating build files\n')
outfile.write(' generator = 1\n\n')
- if len(self.build.pot) > 0:
- self.generate_gettext_rules(outfile)
- outfile.write('\n')
-
- def generate_gettext_rules(self, outfile):
- rule = 'rule GEN_POT\n'
- command = " command = xgettext --package-name=$PACKAGENAME -p $OUTDIR -f $FILELIST -D '%s' -k_ -o $OUTFILE\n" % \
- self.environment.get_source_dir()
- desc = " description = Creating pot file for package $PACKAGENAME.\n"
- outfile.write(rule)
- outfile.write(command)
- outfile.write(desc)
- outfile.write('\n')
- rule = 'rule GEN_GMO\n'
- command = ' command = msgfmt $INFILE -o $OUTFILE\n'
- desc = ' description = Generating gmo file $OUTFILE\n'
- outfile.write(rule)
- outfile.write(command)
- outfile.write(desc)
outfile.write('\n')
def generate_phony(self, outfile):
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
index 105fb0b..1e9a1bb 100644
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -95,7 +95,6 @@ class Build:
self.data = []
self.static_linker = None
self.static_cross_linker = None
- self.pot = []
self.subprojects = {}
self.install_scripts = []
self.postconf_scripts = []
diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py
index ae119de..da90814 100644
--- a/mesonbuild/interpreter.py
+++ b/mesonbuild/interpreter.py
@@ -1052,6 +1052,7 @@ class Interpreter():
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)
@@ -1285,15 +1286,7 @@ class Interpreter():
@stringArgs
def func_gettext(self, nodes, args, kwargs):
- if len(args) != 1:
- raise InterpreterException('Gettext requires one positional argument (package name).')
- packagename = args[0]
- languages = kwargs.get('languages', None)
- check_stringlist(languages, 'Argument languages must be a list of strings.')
- # TODO: check that elements are strings
- if len(self.build.pot) > 0:
- raise InterpreterException('More than one gettext definition currently not supported.')
- self.build.pot.append((packagename, languages, self.subdir))
+ raise InterpreterException('Gettext() function has been moved to module i18n. Import it and use i18n.gettext() instead')
def func_option(self, nodes, args, kwargs):
raise InterpreterException('Tried to call option() in build description file. All options must be in the option file.')
diff --git a/mesonbuild/mesonmain.py b/mesonbuild/mesonmain.py
index 059c76b..4f8314c 100644
--- a/mesonbuild/mesonmain.py
+++ b/mesonbuild/mesonmain.py
@@ -202,6 +202,9 @@ def run_script_command(args):
elif cmdname == 'vcstagger':
import mesonbuild.scripts.vcstagger as abc
cmdfunc = abc.run
+ elif cmdname == 'gettext':
+ import mesonbuild.scripts.gettext as abc
+ cmdfunc = abc.run
else:
raise MesonException('Unknown internal command {}.'.format(cmdname))
return cmdfunc(cmdargs)
diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py
new file mode 100644
index 0000000..51668cb
--- /dev/null
+++ b/mesonbuild/modules/i18n.py
@@ -0,0 +1,44 @@
+# Copyright 2016 The Meson development team
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from .. import coredata, mesonlib, build
+import sys
+
+class I18nModule:
+
+ def gettext(self, state, args, kwargs):
+ if len(args) != 1:
+ raise coredata.MesonException('Gettext requires one positional argument (package name).')
+ packagename = args[0]
+ 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]
+ 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)
+ installcmd = [sys.executable,
+ state.environment.get_build_command(),
+ '--internal',
+ 'gettext',
+ 'install',
+ state.subdir,
+ packagename,
+ state.environment.coredata.get_builtin_option('localedir'),
+ ] + languages
+ iscript = build.InstallScript(installcmd)
+ return [pottarget, gmotarget, iscript]
+
+def initialize():
+ return I18nModule()
diff --git a/mesonbuild/scripts/gettext.py b/mesonbuild/scripts/gettext.py
new file mode 100644
index 0000000..adc4483
--- /dev/null
+++ b/mesonbuild/scripts/gettext.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+
+# Copyright 2016 The Meson development team
+
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import os, subprocess, shutil
+
+def run_potgen(src_sub, pkgname, langs):
+ 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])
+
+def gen_gmo(src_sub, bld_sub, langs):
+ for l in langs:
+ subprocess.check_call(['msgfmt', os.path.join(src_sub, l + '.po'),
+ '-o', os.path.join(bld_sub, l + '.gmo')])
+ return 0
+
+def do_install(src_sub, bld_sub, dest, pkgname, langs):
+ for l in langs:
+ srcfile = os.path.join(bld_sub, l + '.gmo')
+ outfile = os.path.join(dest, l, 'LC_MESSAGES',
+ pkgname + '.mo')
+ os.makedirs(os.path.split(outfile)[0], exist_ok=True)
+ shutil.copyfile(srcfile, outfile)
+ shutil.copystat(srcfile, outfile)
+ print('Installing %s to %s.' % (srcfile, outfile))
+ return 0
+
+def run(args):
+ subcmd = args[0]
+ if subcmd == 'pot':
+ src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
+ bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR'])
+ return run_potgen(src_sub, args[1], args[2:])
+ elif subcmd == 'gen_gmo':
+ src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], os.environ['MESON_SUBDIR'])
+ bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], os.environ['MESON_SUBDIR'])
+ return gen_gmo(src_sub, bld_sub, args[1:])
+ elif subcmd == 'install':
+ subdir = args[1]
+ pkgname = args[2]
+ instsubdir = args[3]
+ langs = args[4:]
+ src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir)
+ bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir)
+ dest = os.environ.get('DESTDIR') + os.path.join(os.environ['MESON_INSTALL_PREFIX'], instsubdir)
+ if gen_gmo(src_sub, bld_sub, langs) != 0:
+ return 1
+ do_install(src_sub, bld_sub, dest, pkgname, langs)
+ else:
+ print('Unknown subcommand.')
+ return 1
diff --git a/mesonbuild/scripts/meson_install.py b/mesonbuild/scripts/meson_install.py
index cc86b62..20a50f7 100644
--- a/mesonbuild/scripts/meson_install.py
+++ b/mesonbuild/scripts/meson_install.py
@@ -33,7 +33,6 @@ def do_install(datafilename):
install_headers(d)
install_man(d)
install_data(d)
- install_po(d)
run_install_script(d)
def install_subdirs(d):
@@ -51,19 +50,6 @@ def install_subdirs(d):
shutil.copytree(src_dir, final_dst, symlinks=True)
print('Installing subdir %s to %s.' % (src_dir, dst_dir))
-def install_po(d):
- packagename = d.po_package_name
- for f in d.po:
- srcfile = f[0]
- localedir = f[1]
- languagename = f[2]
- outfile = os.path.join(d.fullprefix, localedir, languagename, 'LC_MESSAGES',
- packagename + '.mo')
- os.makedirs(os.path.split(outfile)[0], exist_ok=True)
- shutil.copyfile(srcfile, outfile)
- shutil.copystat(srcfile, outfile)
- print('Installing %s to %s.' % (srcfile, outfile))
-
def install_data(d):
for i in d.data:
fullfilename = i[0]
diff --git a/test cases/frameworks/6 gettext/meson.build b/test cases/frameworks/6 gettext/meson.build
index 4384978..6bba7e0 100644
--- a/test cases/frameworks/6 gettext/meson.build
+++ b/test cases/frameworks/6 gettext/meson.build
@@ -1,4 +1,6 @@
project('gettext example', 'c')
+i18n = import('i18n')
+
subdir('po')
subdir('src')
diff --git a/test cases/frameworks/6 gettext/po/intltest.pot b/test cases/frameworks/6 gettext/po/intltest.pot
index 05da67d..d65e2c1 100644
--- a/test cases/frameworks/6 gettext/po/intltest.pot
+++ b/test cases/frameworks/6 gettext/po/intltest.pot
@@ -1,6 +1,6 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
-# This file is distributed under the same license as the PACKAGE package.
+# This file is distributed under the same license as the intltest package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: intltest\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2013-09-12 19:04+0300\n"
+"POT-Creation-Date: 2016-03-28 19:59+0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
diff --git a/test cases/frameworks/6 gettext/po/meson.build b/test cases/frameworks/6 gettext/po/meson.build
index 3376c84..8ea2c11 100644
--- a/test cases/frameworks/6 gettext/po/meson.build
+++ b/test cases/frameworks/6 gettext/po/meson.build
@@ -1,4 +1,3 @@
langs = ['fi', 'de']
-gettext('intltest',
-languages : langs)
+i18n.gettext('intltest', languages : langs)