Remove all special casing for gettext and use elementary operations instead.

pull/479/head
Jussi Pakkanen 9 years ago
parent 12a4e7d7e7
commit dc148e0702
  1. 50
      mesonbuild/backend/ninjabackend.py
  2. 7
      mesonbuild/build.py
  3. 5
      mesonbuild/interpreter.py
  4. 3
      mesonbuild/mesonmain.py
  5. 17
      mesonbuild/modules/i18n.py
  6. 65
      mesonbuild/scripts/gettext.py
  7. 14
      mesonbuild/scripts/meson_install.py

@ -175,9 +175,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')
@ -404,23 +401,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:
input_file = os.path.join(p.subdir, 'POTFILES')
elem = NinjaBuildElement(self.all_outputs, 'pot', 'GEN_POT', [])
elem.add_item('PACKAGENAME', p.packagename)
elem.add_item('OUTFILE', p.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(), p.subdir))
elem.write(outfile)
for l in p.languages:
infile = os.path.join(self.environment.get_source_dir(), p.subdir, l + '.po')
outfilename = os.path.join(p.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
@ -471,7 +451,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)
@ -479,16 +458,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:
# FIXME: assumes only one po package per source
d.po_package_name = p.packagename
for lang in p.languages:
rel_src = os.path.join(p.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()
@ -628,25 +597,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):

@ -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 = []
@ -1016,9 +1015,3 @@ class InstallScript:
def __init__(self, cmd_arr):
assert(isinstance(cmd_arr, list))
self.cmd_arr = cmd_arr
class PoInfo():
def __init__(self, packagename, languages, subdir):
self.packagename = packagename
self.languages = languages
self.subdir = subdir

@ -1036,13 +1036,10 @@ 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)
elif isinstance(v, build.PoInfo):
if len(self.build.pot) > 0:
raise coredata.MesonException('More than one gettext definition currently not supported.')
self.build.pot.append(v)
else:
print(v)
raise InterpreterException('Module returned a value of unknown type.')

@ -206,6 +206,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)

@ -13,6 +13,7 @@
# limitations under the License.
from .. import coredata, mesonlib, build
import sys
class I18nModule:
@ -23,7 +24,21 @@ class I18nModule:
languages = mesonlib.stringlistify(kwargs.get('languages', []))
if len(languages) == 0:
raise coredata.MesonException('List of languages empty.')
return build.PoInfo(packagename, languages, state.subdir)
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()

@ -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

@ -32,7 +32,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):
@ -50,19 +49,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]

Loading…
Cancel
Save