From 43b80e02ce0e87dfcf069111e62ad8eff4435d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Sat, 22 Apr 2023 00:09:13 +0200 Subject: [PATCH] linkers: Fix RSP syntax for linkers invoked with clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #8981 Fixes: 2be074b1d445fcd30535bcf7518f8ce0738bcbf3 Signed-off-by: Kacper Michajłow --- mesonbuild/linkers/detect.py | 15 ++++++++++++--- mesonbuild/linkers/linkers.py | 16 ++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/mesonbuild/linkers/detect.py b/mesonbuild/linkers/detect.py index cd3c7b2efd0f..0dce5ad501b1 100644 --- a/mesonbuild/linkers/detect.py +++ b/mesonbuild/linkers/detect.py @@ -3,6 +3,7 @@ from __future__ import annotations +from .base import RSPFileSyntax from .. import mlog from ..mesonlib import ( EnvironmentException, @@ -40,6 +41,11 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty from . import linkers env.coredata.add_lang_args(comp_class.language, comp_class, for_machine, env) + if invoked_directly or comp_class.get_argument_syntax() == 'msvc': + rsp_syntax = RSPFileSyntax.MSVC + else: + rsp_syntax = RSPFileSyntax.GCC + # Explicitly pass logo here so that we can get the version of link.exe if not use_linker_prefix or comp_class.LINKER_PREFIX is None: check_args = ['/logo', '--version'] @@ -71,7 +77,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty elif not invoked_directly: return linkers.ClangClDynamicLinker( for_machine, override, exelist=compiler, prefix=comp_class.LINKER_PREFIX, - version=search_version(o), direct=False, machine=None) + version=search_version(o), direct=False, machine=None, + rsp_syntax=rsp_syntax) if value is not None and invoked_directly: compiler = value @@ -82,7 +89,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty return linkers.ClangClDynamicLinker( for_machine, [], prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [], - exelist=compiler, version=search_version(o), direct=invoked_directly) + exelist=compiler, version=search_version(o), direct=invoked_directly, + rsp_syntax=rsp_syntax) elif 'OPTLINK' in o: # Optlink's stdout *may* begin with a \r character. return linkers.OptlinkDynamicLinker(compiler, for_machine, version=search_version(o)) @@ -97,7 +105,8 @@ def guess_win_linker(env: 'Environment', compiler: T.List[str], comp_class: T.Ty return linkers.MSVCDynamicLinker( for_machine, [], machine=target, exelist=compiler, prefix=comp_class.LINKER_PREFIX if use_linker_prefix else [], - version=search_version(out), direct=invoked_directly) + version=search_version(out), direct=invoked_directly, + rsp_syntax=rsp_syntax) elif 'GNU coreutils' in o: import shutil fullpath = shutil.which(compiler[0]) diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index c3750ccc372f..18157a36be63 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -1274,11 +1274,13 @@ def _apply_prefix(self, arg: T.Union[str, T.List[str]]) -> T.List[str]: ... def __init__(self, exelist: T.List[str], for_machine: mesonlib.MachineChoice, prefix_arg: T.Union[str, T.List[str]], always_args: T.List[str], *, - version: str = 'unknown version', direct: bool = True, machine: str = 'x86'): + version: str = 'unknown version', direct: bool = True, machine: str = 'x86', + rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): # There's no way I can find to make mypy understand what's going on here super().__init__(exelist, for_machine, prefix_arg, always_args, version=version) self.machine = machine self.direct = direct + self.rsp_syntax = rsp_syntax def invoked_by_compiler(self) -> bool: return not self.direct @@ -1322,7 +1324,7 @@ def import_library_args(self, implibname: str) -> T.List[str]: return self._apply_prefix(['/IMPLIB:' + implibname]) def rsp_file_syntax(self) -> RSPFileSyntax: - return RSPFileSyntax.MSVC + return self.rsp_syntax class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): @@ -1335,9 +1337,10 @@ def __init__(self, for_machine: mesonlib.MachineChoice, always_args: T.List[str] exelist: T.Optional[T.List[str]] = None, prefix: T.Union[str, T.List[str]] = '', machine: str = 'x86', version: str = 'unknown version', - direct: bool = True): + direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): super().__init__(exelist or ['link.exe'], for_machine, - prefix, always_args, machine=machine, version=version, direct=direct) + prefix, always_args, machine=machine, version=version, direct=direct, + rsp_syntax=rsp_syntax) def get_always_args(self) -> T.List[str]: return self._apply_prefix(['/release']) + super().get_always_args() @@ -1359,9 +1362,10 @@ def __init__(self, for_machine: mesonlib.MachineChoice, always_args: T.List[str] exelist: T.Optional[T.List[str]] = None, prefix: T.Union[str, T.List[str]] = '', machine: str = 'x86', version: str = 'unknown version', - direct: bool = True): + direct: bool = True, rsp_syntax: RSPFileSyntax = RSPFileSyntax.MSVC): super().__init__(exelist or ['lld-link.exe'], for_machine, - prefix, always_args, machine=machine, version=version, direct=direct) + prefix, always_args, machine=machine, version=version, direct=direct, + rsp_syntax=rsp_syntax) def get_output_args(self, outputname: str) -> T.List[str]: # If we're being driven indirectly by clang just skip /MACHINE