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
pull/12115/head
Jouke Witteveen 12 months ago committed by Eli Schwartz
parent 3c7bc8cac3
commit 10e269271d
  1. 13
      mesonbuild/backend/backends.py

@ -14,6 +14,7 @@ import json
import os import os
import pickle import pickle
import re import re
import shlex
import shutil import shutil
import typing as T import typing as T
import hashlib import hashlib
@ -26,8 +27,7 @@ from .. import mlog
from ..compilers import LANGUAGES_USING_LDFLAGS, detect from ..compilers import LANGUAGES_USING_LDFLAGS, detect
from ..mesonlib import ( from ..mesonlib import (
File, MachineChoice, MesonException, OrderedSet, File, MachineChoice, MesonException, OrderedSet,
classify_unity_sources, OptionKey, join_args, ExecutableSerialisation, classify_unity_sources, OptionKey
ExecutableSerialisation
) )
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
@ -1598,22 +1598,23 @@ class Backend:
cmd = [i.replace('\\', '/') for i in cmd] cmd = [i.replace('\\', '/') for i in cmd]
return inputs, outputs, 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: def get_run_target_env(self, target: build.RunTarget) -> mesonlib.EnvironmentVariables:
env = target.env if target.env else mesonlib.EnvironmentVariables() env = target.env if target.env else mesonlib.EnvironmentVariables()
if target.default_env: 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_SOURCE_ROOT', [self.environment.get_source_dir()])
env.set('MESON_BUILD_ROOT', [self.environment.get_build_dir()]) env.set('MESON_BUILD_ROOT', [self.environment.get_build_dir()])
env.set('MESON_SUBDIR', [target.subdir]) env.set('MESON_SUBDIR', [target.subdir])
env.set('MESONINTROSPECT', [introspect_cmd]) env.set('MESONINTROSPECT', [self.get_introspect_command()])
return env return env
def run_postconf_scripts(self) -> None: def run_postconf_scripts(self) -> None:
from ..scripts.meson_exe import run_exe 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(), env = {'MESON_SOURCE_ROOT': self.environment.get_source_dir(),
'MESON_BUILD_ROOT': self.environment.get_build_dir(), 'MESON_BUILD_ROOT': self.environment.get_build_dir(),
'MESONINTROSPECT': introspect_cmd, 'MESONINTROSPECT': self.get_introspect_command(),
} }
for s in self.build.postconf_scripts: for s in self.build.postconf_scripts:

Loading…
Cancel
Save