compilers/linkers: Add a methhod for getting the rspfile syntax

pull/8532/head
Dylan Baker 4 years ago
parent be86199221
commit 320412b3bb
  1. 10
      mesonbuild/compilers/compilers.py
  2. 7
      mesonbuild/compilers/cs.py
  3. 13
      mesonbuild/compilers/d.py
  4. 44
      mesonbuild/linkers.py

@ -34,7 +34,7 @@ if T.TYPE_CHECKING:
from ..coredata import OptionDictType, KeyedOptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import DynamicLinker # noqa: F401
from ..linkers import DynamicLinker, RSPFileSyntax
from ..dependencies import Dependency
CompilerType = T.TypeVar('CompilerType', bound=Compiler)
@ -1217,6 +1217,14 @@ class Compiler(metaclass=abc.ABCMeta):
def get_prelink_args(self, prelink_name: str, obj_list: T.List[str]) -> T.List[str]:
raise EnvironmentException(f'{self.id} does not know how to do prelinking.')
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 self.linker.rsp_file_syntax()
def get_global_options(lang: str,
comp: T.Type[Compiler],

@ -17,6 +17,7 @@ import textwrap
import typing as T
from ..mesonlib import EnvironmentException
from ..linkers import RSPFileSyntax
from .compilers import Compiler, MachineChoice, mono_buildtype_args
from .mixins.islinker import BasicLinkerIsCompilerMixin
@ -125,6 +126,9 @@ class MonoCompiler(CsCompiler):
super().__init__(exelist, version, for_machine, info, 'mono',
runner='mono')
def rsp_file_syntax(self) -> 'RSPFileSyntax':
return RSPFileSyntax.GCC
class VisualStudioCsCompiler(CsCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
@ -141,3 +145,6 @@ class VisualStudioCsCompiler(CsCompiler):
tmp.append(flag)
res = tmp
return res
def rsp_file_syntax(self) -> 'RSPFileSyntax':
return RSPFileSyntax.MSVC

@ -18,7 +18,7 @@ import subprocess
import typing as T
from ..mesonlib import (
EnvironmentException, MachineChoice, version_compare, OptionKey,
EnvironmentException, MachineChoice, version_compare, OptionKey, is_windows
)
from ..arglist import CompilerArgs
@ -36,7 +36,7 @@ if T.TYPE_CHECKING:
from ..dependencies import Dependency, ExternalProgram
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import DynamicLinker
from ..linkers import DynamicLinker, RSPFileSyntax
else:
CompilerMixinBase = object
@ -780,6 +780,12 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
def get_disable_assert_args(self) -> T.List[str]:
return ['--release']
def rsp_file_syntax(self) -> 'RSPFileSyntax':
# We use `mesonlib.is_windows` here because we want to konw what the
# build machine is, not the host machine. This really means whe whould
# have the Environment not the MachineInfo in the compiler.
return RSPFileSyntax.MSVC if is_windows() else RSPFileSyntax.GCC
class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
@ -860,3 +866,6 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
def get_disable_assert_args(self) -> T.List[str]:
return ['-release']
def rsp_file_syntax(self) -> 'RSPFileSyntax':
return RSPFileSyntax.MSVC

@ -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):

Loading…
Cancel
Save