Skip to content

Commit

Permalink
backends: restore shlex quoting of MESONINTROSPECT
Browse files Browse the repository at this point in the history
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
  • Loading branch information
joukewitteveen committed Feb 3, 2024
1 parent cb54f0d commit 59b3e82
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import os
import pickle
import re
import shlex
import shutil
import typing as T
import hashlib
Expand All @@ -26,8 +27,7 @@
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:
Expand Down Expand Up @@ -1598,22 +1598,23 @@ def eval_custom_target_command(
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:
Expand Down

0 comments on commit 59b3e82

Please sign in to comment.