|
|
|
# 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
|
|
|
|
import shutil
|
|
|
|
import argparse
|
|
|
|
import subprocess
|
|
|
|
from . import destdir_join
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument('command')
|
|
|
|
parser.add_argument('--pkgname', default='')
|
|
|
|
parser.add_argument('--datadirs', default='')
|
|
|
|
parser.add_argument('--langs', default='')
|
|
|
|
parser.add_argument('--localedir', default='')
|
|
|
|
parser.add_argument('--subdir', default='')
|
|
|
|
parser.add_argument('--extra-args', default='')
|
|
|
|
|
|
|
|
def read_linguas(src_sub):
|
|
|
|
# Syntax of this file is documented here:
|
|
|
|
# https://www.gnu.org/software/gettext/manual/html_node/po_002fLINGUAS.html
|
|
|
|
linguas = os.path.join(src_sub, 'LINGUAS')
|
|
|
|
try:
|
|
|
|
langs = []
|
|
|
|
with open(linguas) as f:
|
|
|
|
for line in f:
|
|
|
|
line = line.strip()
|
|
|
|
if line and not line.startswith('#'):
|
|
|
|
langs += line.split()
|
|
|
|
return langs
|
|
|
|
except (FileNotFoundError, PermissionError):
|
|
|
|
print('Could not find file LINGUAS in {}'.format(src_sub))
|
|
|
|
return []
|
|
|
|
|
|
|
|
def run_potgen(src_sub, pkgname, datadirs, args):
|
|
|
|
listfile = os.path.join(src_sub, 'POTFILES')
|
|
|
|
if not os.path.exists(listfile):
|
|
|
|
listfile = os.path.join(src_sub, 'POTFILES.in')
|
|
|
|
if not os.path.exists(listfile):
|
|
|
|
print('Could not find file POTFILES in %s' % src_sub)
|
|
|
|
return 1
|
|
|
|
|
|
|
|
child_env = os.environ.copy()
|
|
|
|
if datadirs:
|
|
|
|
child_env['GETTEXTDATADIRS'] = datadirs
|
|
|
|
|
|
|
|
ofile = os.path.join(src_sub, pkgname + '.pot')
|
|
|
|
return subprocess.call(['xgettext', '--package-name=' + pkgname, '-p', src_sub, '-f', listfile,
|
|
|
|
'-D', os.environ['MESON_SOURCE_ROOT'], '-k_', '-o', ofile] + args,
|
|
|
|
env=child_env)
|
|
|
|
|
|
|
|
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 update_po(src_sub, pkgname, langs):
|
|
|
|
potfile = os.path.join(src_sub, pkgname + '.pot')
|
|
|
|
for l in langs:
|
|
|
|
pofile = os.path.join(src_sub, l + '.po')
|
|
|
|
subprocess.check_call(['msgmerge', '-q', '-o', pofile, pofile, potfile])
|
|
|
|
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):
|
|
|
|
options = parser.parse_args(args)
|
|
|
|
subcmd = options.command
|
|
|
|
langs = options.langs.split('@@') if options.langs else None
|
|
|
|
extra_args = options.extra_args.split('@@')
|
gettext: Respect the --subdir argument before the MESON_SUBDIR var
In the case of subproject we will properly setup the --subdir argument
but the MESON_SUBDIR is never adapted and will point to an empty string
leading to the following backtrace when building `gst-build`:
msgfmt: error while opening "/home/thiblahute/devel/gstreamer/gst-build/af.po" for reading: No such file or directory
Traceback (most recent call last):
File "/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py", line 37, in <module>
sys.exit(main())
File "/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py", line 34, in main
return mesonmain.run(launcher, sys.argv[1:])
File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/mesonmain.py", line 248, in run
sys.exit(run_script_command(args[1:]))
File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/mesonmain.py", line 236, in run_script_command
return cmdfunc(cmdargs)
File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/scripts/gettext.py", line 111, in run
if gen_gmo(src_sub, bld_sub, langs) != 0:
File "/home/thiblahute/devel/gstreamer/gst-build/meson/mesonbuild/scripts/gettext.py", line 66, in gen_gmo
'-o', os.path.join(bld_sub, l + '.gmo')])
File "/usr/lib/python3.5/subprocess.py", line 581, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['msgfmt', '/home/thiblahute/devel/gstreamer/gst-build/af.po', '-o', '/home/thiblahute/devel/gstreamer/gst-build/build/af.gmo']' returned non-zero exit status 1
Failed to run install script: /usr/bin/python3 /home/thiblahute/devel/gstreamer/gst-build/meson/meson.py --internal gettext install --subdir=subprojects/gstreamer/po --localedir=share/locale --pkgname=gstreamer-1.0 --langs=af@@az@@be@@bg@@ca@@cs@@da@@de@@el@@en_GB@@eo@@es@@eu@@fi@@fr@@gl@@hr@@hu@@id@@it@@ja@@lt@@nb@@nl@@pl@@pt_BR@@ro@@ru@@rw@@sk@@sl@@sq@@sr@@sv@@tr@@uk@@vi@@zh_CN@@zh_TW
FAILED: install
'/usr/bin/python3' '/home/thiblahute/devel/gstreamer/gst-build/meson/meson.py' '--internal' 'install' '/home/thiblahute/devel/gstreamer/gst-build/build/meson-private/install.dat'
8 years ago
|
|
|
subdir = os.environ.get('MESON_SUBDIR', '')
|
|
|
|
if options.subdir:
|
|
|
|
subdir = options.subdir
|
|
|
|
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir)
|
|
|
|
bld_sub = os.path.join(os.environ['MESON_BUILD_ROOT'], subdir)
|
|
|
|
|
|
|
|
if not langs:
|
|
|
|
langs = read_linguas(src_sub)
|
|
|
|
|
|
|
|
if subcmd == 'pot':
|
|
|
|
return run_potgen(src_sub, options.pkgname, options.datadirs, extra_args)
|
|
|
|
elif subcmd == 'gen_gmo':
|
|
|
|
return gen_gmo(src_sub, bld_sub, langs)
|
|
|
|
elif subcmd == 'update_po':
|
|
|
|
if run_potgen(src_sub, options.pkgname, options.datadirs, extra_args) != 0:
|
|
|
|
return 1
|
|
|
|
return update_po(src_sub, options.pkgname, langs)
|
|
|
|
elif subcmd == 'install':
|
|
|
|
destdir = os.environ.get('DESTDIR', '')
|
|
|
|
dest = destdir_join(destdir, os.path.join(os.environ['MESON_INSTALL_PREFIX'],
|
|
|
|
options.localedir))
|
|
|
|
if gen_gmo(src_sub, bld_sub, langs) != 0:
|
|
|
|
return 1
|
|
|
|
do_install(src_sub, bld_sub, dest, options.pkgname, langs)
|
|
|
|
else:
|
|
|
|
print('Unknown subcommand.')
|
|
|
|
return 1
|