gettext: explicitly pass source root / subdir as cli args

Because this is a wrapper script and we could/should do this, we even
have half the infra for it.
pull/10365/head
Eli Schwartz 3 years ago
parent 6757e4f07c
commit 34da721ec2
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 6
      mesonbuild/modules/i18n.py
  2. 15
      mesonbuild/scripts/gettext.py

@ -251,6 +251,9 @@ class I18nModule(ExtensionModule):
extra_arg = '--extra-args=' + '@@'.join(extra_args) if extra_args else None
potargs = state.environment.get_build_command() + ['--internal', 'gettext', 'pot', pkg_arg]
potargs.append(f'--source-root={state.source_root}')
if state.subdir:
potargs.append(f'--subdir={state.subdir}')
if datadirs:
potargs.append(datadirs)
if extra_arg:
@ -292,6 +295,9 @@ class I18nModule(ExtensionModule):
targets.append(allgmotarget)
updatepoargs = state.environment.get_build_command() + ['--internal', 'gettext', 'update_po', pkg_arg]
updatepoargs.append(f'--source-root={state.source_root}')
if state.subdir:
updatepoargs.append(f'--subdir={state.subdir}')
if lang_arg:
updatepoargs.append(lang_arg)
if datadirs:

@ -23,6 +23,7 @@ parser.add_argument('--pkgname', default='')
parser.add_argument('--datadirs', default='')
parser.add_argument('--langs', default='')
parser.add_argument('--localedir', default='')
parser.add_argument('--source-root', default='')
parser.add_argument('--subdir', default='')
parser.add_argument('--xgettext', default='xgettext')
parser.add_argument('--msgmerge', default='msgmerge')
@ -45,7 +46,7 @@ def read_linguas(src_sub: str) -> T.List[str]:
print(f'Could not find file LINGUAS in {src_sub}')
return []
def run_potgen(src_sub: str, xgettext: str, pkgname: str, datadirs: str, args: T.List[str]) -> int:
def run_potgen(src_sub: str, xgettext: str, pkgname: str, datadirs: str, args: T.List[str], source_root: str) -> int:
listfile = os.path.join(src_sub, 'POTFILES.in')
if not os.path.exists(listfile):
listfile = os.path.join(src_sub, 'POTFILES')
@ -59,7 +60,7 @@ def run_potgen(src_sub: str, xgettext: str, pkgname: str, datadirs: str, args: T
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,
'-D', source_root, '-k_', '-o', ofile] + args,
env=child_env)
def update_po(src_sub: str, msgmerge: str, msginit: str, pkgname: str, langs: T.List[str]) -> int:
@ -77,18 +78,16 @@ def run(args: T.List[str]) -> int:
subcmd = options.command
langs = options.langs.split('@@') if options.langs else None
extra_args = options.extra_args.split('@@') if options.extra_args else []
subdir = os.environ.get('MESON_SUBDIR', '')
if options.subdir:
subdir = options.subdir
src_sub = os.path.join(os.environ['MESON_SOURCE_ROOT'], subdir)
subdir = options.subdir
src_sub = os.path.join(options.source_root, subdir)
if not langs:
langs = read_linguas(src_sub)
if subcmd == 'pot':
return run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args)
return run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args, options.source_root)
elif subcmd == 'update_po':
if run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args) != 0:
if run_potgen(src_sub, options.xgettext, options.pkgname, options.datadirs, extra_args, options.source_root) != 0:
return 1
return update_po(src_sub, options.msgmerge, options.msginit, options.pkgname, langs)
else:

Loading…
Cancel
Save