From 320412b3bbe97d8779d715f992f7a88d3a461ace Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 9 Mar 2021 14:04:02 -0800 Subject: compilers/linkers: Add a methhod for getting the rspfile syntax --- mesonbuild/linkers.py | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'mesonbuild/linkers.py') diff --git a/mesonbuild/linkers.py b/mesonbuild/linkers.py index 2807003..acb2c44 100644 --- a/mesonbuild/linkers.py +++ b/mesonbuild/linkers.py @@ -13,6 +13,7 @@ # limitations under the License. import abc +import enum import os import typing as T @@ -25,8 +26,19 @@ if T.TYPE_CHECKING: from .mesonlib import MachineChoice +@enum.unique +class RSPFileSyntax(enum.Enum): + + """Which RSP file syntax the compiler supports.""" + + MSVC = enum.auto() + GCC = enum.auto() + + class StaticLinker: + id: str + def __init__(self, exelist: T.List[str]): self.exelist = exelist @@ -93,6 +105,15 @@ class StaticLinker: def get_linker_always_args(self) -> T.List[str]: return [] + def rsp_file_syntax(self) -> RSPFileSyntax: + """The format of the RSP file that this compiler supports. + + If `self.can_linker_accept_rsp()` returns True, then this needs to + be implemented + """ + assert not self.can_linker_accept_rsp(), f'{self.id} linker accepts RSP, but doesn\' provide a supported format, this is a bug' + raise mesonlib.EnvironmentException(f'{self.id} does no implemnt rsp format, this shouldn\'t be called') + class VisualStudioLikeLinker: always_args = ['/NOLOGO'] @@ -123,6 +144,9 @@ class VisualStudioLikeLinker: from .compilers import VisualStudioCCompiler return VisualStudioCCompiler.native_args_to_unix(args) + def rsp_file_syntax(self) -> RSPFileSyntax: + return RSPFileSyntax.MSVC + class VisualStudioLinker(VisualStudioLikeLinker, StaticLinker): @@ -164,6 +188,9 @@ class ArLinker(StaticLinker): def get_output_args(self, target: str) -> T.List[str]: return [target] + def rsp_file_syntax(self) -> RSPFileSyntax: + return RSPFileSyntax.GCC + class ArmarLinker(ArLinker): # lgtm [py/missing-call-to-init] @@ -178,10 +205,11 @@ class ArmarLinker(ArLinker): # lgtm [py/missing-call-to-init] class DLinker(StaticLinker): - def __init__(self, exelist: T.List[str], arch: str): + def __init__(self, exelist: T.List[str], arch: str, *, rsp_syntax: RSPFileSyntax = RSPFileSyntax.GCC): super().__init__(exelist) self.id = exelist[0] self.arch = arch + self.__rsp_syntax = rsp_syntax def get_std_link_args(self) -> T.List[str]: return ['-lib'] @@ -198,6 +226,9 @@ class DLinker(StaticLinker): return ['-m32'] return [] + def rsp_file_syntax(self) -> RSPFileSyntax: + return self.__rsp_syntax + class CcrxLinker(StaticLinker): @@ -355,6 +386,14 @@ class DynamicLinker(metaclass=abc.ABCMeta): # avoid issues with quoting and max argument length return mesonlib.is_windows() + def rsp_file_syntax(self) -> RSPFileSyntax: + """The format of the RSP file that this compiler supports. + + If `self.can_linker_accept_rsp()` returns True, then this needs to + be implemented + """ + return RSPFileSyntax.GCC + def get_always_args(self) -> T.List[str]: return self.always_args.copy() @@ -1137,6 +1176,9 @@ class VisualStudioLikeLinkerMixin: """The command to generate the import library.""" return self._apply_prefix(['/IMPLIB:' + implibname]) + def rsp_file_syntax(self) -> RSPFileSyntax: + return RSPFileSyntax.MSVC + class MSVCDynamicLinker(VisualStudioLikeLinkerMixin, DynamicLinker): -- cgit v1.1