From ada6236f76f4fbce4313b48eeaf9d8485516fde8 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Fri, 20 Oct 2023 11:24:11 +0800 Subject: [PATCH] i18n module: Invoke itstool with the full command line Certain envs may not support invoking itstool by itself directly as a script as shebang lines are not supported, such as under cmd.exe shells on Windows, that are normally used for Visual Studio (and the like, such as clang-cl) builds. This will call the corresponding interpreter to invoke itstool when needed, so that itstool can be properly run, even if shebang lines are not supported by the env. This will fix building appstream on Windows using clang-cl, for instance. --- mesonbuild/modules/i18n.py | 6 +++++- mesonbuild/scripts/itstool.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/i18n.py b/mesonbuild/modules/i18n.py index c82e580a2..e375674d9 100644 --- a/mesonbuild/modules/i18n.py +++ b/mesonbuild/modules/i18n.py @@ -14,6 +14,7 @@ from __future__ import annotations from os import path +import shlex import typing as T from . import ExtensionModule, ModuleReturnValue, ModuleInfo @@ -360,11 +361,14 @@ class I18nModule(ExtensionModule): command: T.List[T.Union[str, build.BuildTarget, build.CustomTarget, build.CustomTargetIndex, 'ExternalProgram', mesonlib.File]] = [] command.extend(state.environment.get_build_command()) + + itstool_cmd = self.tools['itstool'].get_command() + # TODO: python 3.8 can use shlex.join() command.extend([ '--internal', 'itstool', 'join', '-i', '@INPUT@', '-o', '@OUTPUT@', - '--itstool=' + self.tools['itstool'].get_path(), + '--itstool=' + ' '.join(shlex.quote(c) for c in itstool_cmd), ]) if its_files: for fname in its_files: diff --git a/mesonbuild/scripts/itstool.py b/mesonbuild/scripts/itstool.py index 0bfcaf9b5..16af1c235 100644 --- a/mesonbuild/scripts/itstool.py +++ b/mesonbuild/scripts/itstool.py @@ -17,6 +17,7 @@ import os import argparse import subprocess import tempfile +import shlex import shutil import typing as T @@ -56,7 +57,7 @@ def run_join(build_dir: str, itstool: str, its_files: T.List[str], mo_files: T.L shutil.copy(mo_file, tmp_mo_fname) locale_mo_files.append(tmp_mo_fname) - cmd = [itstool] + cmd = shlex.split(itstool) if its_files: for fname in its_files: cmd.extend(['-i', fname])