mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-25 22:52:01 +00:00
fix: escape paths with spaces in pybind11-config (#4874)
* fix: Escape paths with spaces in include list from --includes * fix: --includes should not use shlex on Windows platforms * Apply suggestions from code review * fix: use custom impl Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> * Support trailing backslashes Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com> --------- Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com> Co-authored-by: Markus Bauer <markus.bauer@cispa.saarland> Co-authored-by: Henry Schreiner <HenrySchreinerIII@gmail.com>
This commit is contained in:
parent
75c11769bc
commit
973a16e9a0
@ -2,12 +2,35 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
import sysconfig
|
||||||
|
|
||||||
from ._version import __version__
|
from ._version import __version__
|
||||||
from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
|
from .commands import get_cmake_dir, get_include, get_pkgconfig_dir
|
||||||
|
|
||||||
|
# This is the conditional used for os.path being posixpath
|
||||||
|
if "posix" in sys.builtin_module_names:
|
||||||
|
from shlex import quote
|
||||||
|
elif "nt" in sys.builtin_module_names:
|
||||||
|
# See https://github.com/mesonbuild/meson/blob/db22551ed9d2dd7889abea01cc1c7bba02bf1c75/mesonbuild/utils/universal.py#L1092-L1121
|
||||||
|
# and the original documents:
|
||||||
|
# https://docs.microsoft.com/en-us/cpp/c-language/parsing-c-command-line-arguments and
|
||||||
|
# https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/
|
||||||
|
UNSAFE = re.compile("[ \t\n\r]")
|
||||||
|
|
||||||
|
def quote(s: str) -> str:
|
||||||
|
if s and not UNSAFE.search(s):
|
||||||
|
return s
|
||||||
|
|
||||||
|
# Paths cannot contain a '"' on Windows, so we don't need to worry
|
||||||
|
# about nuanced counting here.
|
||||||
|
return f'"{s}\\"' if s.endswith("\\") else f'"{s}"'
|
||||||
|
else:
|
||||||
|
|
||||||
|
def quote(s: str) -> str:
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
def print_includes() -> None:
|
def print_includes() -> None:
|
||||||
dirs = [
|
dirs = [
|
||||||
@ -22,7 +45,7 @@ def print_includes() -> None:
|
|||||||
if d and d not in unique_dirs:
|
if d and d not in unique_dirs:
|
||||||
unique_dirs.append(d)
|
unique_dirs.append(d)
|
||||||
|
|
||||||
print(" ".join("-I" + d for d in unique_dirs))
|
print(" ".join(quote(f"-I{d}") for d in unique_dirs))
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
@ -54,9 +77,9 @@ def main() -> None:
|
|||||||
if args.includes:
|
if args.includes:
|
||||||
print_includes()
|
print_includes()
|
||||||
if args.cmakedir:
|
if args.cmakedir:
|
||||||
print(get_cmake_dir())
|
print(quote(get_cmake_dir()))
|
||||||
if args.pkgconfigdir:
|
if args.pkgconfigdir:
|
||||||
print(get_pkgconfig_dir())
|
print(quote(get_pkgconfig_dir()))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user