python/build/meson.py: put ccache prefix in array instead of stripping it

Turns out Meson disables ccache auto-detection when a cross-file is
used.  To use ccache, the ccache prefix must be expressed in an array
instead of a single string with spaces.
This commit is contained in:
Max Kellermann 2023-12-22 14:56:42 +01:00
parent c3ba52a1fc
commit a19f3a4f9f
1 changed files with 12 additions and 10 deletions

View File

@ -4,10 +4,12 @@ import platform
from .toolchain import AnyToolchain from .toolchain import AnyToolchain
def __no_ccache(cmd: str) -> str: def format_meson_cross_file_command(command: str) -> str:
if cmd.startswith('ccache '): splitted = command.split()
cmd = cmd[7:] if len(splitted) == 1:
return cmd return repr(command)
return repr(splitted)
def make_cross_file(toolchain: AnyToolchain) -> str: def make_cross_file(toolchain: AnyToolchain) -> str:
if toolchain.is_windows: if toolchain.is_windows:
@ -43,15 +45,15 @@ def make_cross_file(toolchain: AnyToolchain) -> str:
with open(path, 'w') as f: with open(path, 'w') as f:
f.write(f""" f.write(f"""
[binaries] [binaries]
c = '{__no_ccache(toolchain.cc)}' c = {format_meson_cross_file_command(toolchain.cc)}
cpp = '{__no_ccache(toolchain.cxx)}' cpp = {format_meson_cross_file_command(toolchain.cxx)}
ar = '{toolchain.ar}' ar = {format_meson_cross_file_command(toolchain.ar)}
strip = '{toolchain.strip}' strip = {format_meson_cross_file_command(toolchain.strip)}
pkgconfig = '{toolchain.pkg_config}' pkgconfig = {format_meson_cross_file_command(toolchain.pkg_config)}
""") """)
if toolchain.is_windows and platform.system() != 'Windows': if toolchain.is_windows and platform.system() != 'Windows':
f.write(f"windres = '{toolchain.windres}'\n") f.write(f"windres = {format_meson_cross_file_command(toolchain.windres)}\n")
# Run unit tests with WINE when cross-building for Windows # Run unit tests with WINE when cross-building for Windows
print("exe_wrapper = 'wine'", file=f) print("exe_wrapper = 'wine'", file=f)