From 10e269271d9fb6cbb69afa91bcf0cfc03e214bca Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Sat, 3 Feb 2024 17:24:58 +0100 Subject: [PATCH] backends: restore shlex quoting of MESONINTROSPECT The type of quoting was changed in 522392e to one that is suitable for use with cmd.exe on Windows. However, the documentation states that the type of quoting in MESONINTROSPECT is compatible with shlex.split() and elsewhere in the code, the same variable is still quoted with shlex.quote(). As mostly identified in #12148, there are a few choices: 1. Use shlex.quote() consistently and support Python but not cmd.exe. 2. Use join_args and support cmd.exe but not Python. 3. Use join_args and support splitting through the mesonbuild Python library. This commit implements the first option and reverts part of 522392e. Regression testing is implemented in #12115. Fixes #12148 --- mesonbuild/backend/backends.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 5b9479915..01ec422f4 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -14,6 +14,7 @@ import json import os import pickle import re +import shlex import shutil import typing as T import hashlib @@ -26,8 +27,7 @@ from .. import mlog from ..compilers import LANGUAGES_USING_LDFLAGS, detect from ..mesonlib import ( File, MachineChoice, MesonException, OrderedSet, - classify_unity_sources, OptionKey, join_args, - ExecutableSerialisation + ExecutableSerialisation, classify_unity_sources, OptionKey ) if T.TYPE_CHECKING: @@ -1598,22 +1598,23 @@ class Backend: cmd = [i.replace('\\', '/') for i in cmd] return inputs, outputs, cmd + def get_introspect_command(self) -> str: + return ' '.join(shlex.quote(x) for x in self.environment.get_build_command() + ['introspect']) + def get_run_target_env(self, target: build.RunTarget) -> mesonlib.EnvironmentVariables: env = target.env if target.env else mesonlib.EnvironmentVariables() if target.default_env: - introspect_cmd = join_args(self.environment.get_build_command() + ['introspect']) env.set('MESON_SOURCE_ROOT', [self.environment.get_source_dir()]) env.set('MESON_BUILD_ROOT', [self.environment.get_build_dir()]) env.set('MESON_SUBDIR', [target.subdir]) - env.set('MESONINTROSPECT', [introspect_cmd]) + env.set('MESONINTROSPECT', [self.get_introspect_command()]) return env def run_postconf_scripts(self) -> None: from ..scripts.meson_exe import run_exe - introspect_cmd = join_args(self.environment.get_build_command() + ['introspect']) env = {'MESON_SOURCE_ROOT': self.environment.get_source_dir(), 'MESON_BUILD_ROOT': self.environment.get_build_dir(), - 'MESONINTROSPECT': introspect_cmd, + 'MESONINTROSPECT': self.get_introspect_command(), } for s in self.build.postconf_scripts: