compilers: make is_cross part of the base Compiler class

Every class needs to set this, so it should be part of the base. For
classes that require is_cross, the positional argument remains in their
signature. For those that don't, they just allow the base class to set
their value to it's default of False.
pull/7786/head
Dylan Baker 4 years ago
parent 1592b7a800
commit 2c0fbe161d
  1. 4
      mesonbuild/compilers/c.py
  2. 3
      mesonbuild/compilers/compilers.py
  3. 4
      mesonbuild/compilers/cpp.py
  4. 1
      mesonbuild/compilers/cs.py
  5. 26
      mesonbuild/compilers/d.py
  6. 6
      mesonbuild/compilers/fortran.py
  7. 1
      mesonbuild/compilers/java.py
  8. 3
      mesonbuild/compilers/mixins/clike.py
  9. 4
      mesonbuild/compilers/objc.py
  10. 4
      mesonbuild/compilers/objcpp.py
  11. 5
      mesonbuild/compilers/rust.py
  12. 5
      mesonbuild/compilers/swift.py
  13. 5
      mesonbuild/compilers/vala.py
  14. 3
      mesonbuild/environment.py

@ -56,8 +56,8 @@ class CCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional[str] = None, **kwargs):
# If a child ObjC or CPP class has already set it, don't set it ourselves
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrapper)
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, exe_wrapper)
def get_no_stdinc_args(self):
return ['-nostdinc']

@ -456,7 +456,7 @@ class Compiler(metaclass=abc.ABCMeta):
def __init__(self, exelist: T.List[str], version: str,
for_machine: MachineChoice, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None):
full_version: T.Optional[str] = None, is_cross: bool = False):
self.exelist = exelist
# In case it's been overridden by a child class already
if not hasattr(self, 'file_suffixes'):
@ -470,6 +470,7 @@ class Compiler(metaclass=abc.ABCMeta):
self.base_options = [] # type: T.List[str]
self.linker = linker
self.info = info
self.is_cross = is_cross
def __repr__(self) -> str:
repr_str = "<{0}: v{1} `{2}`>"

@ -65,8 +65,8 @@ class CPPCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrap: T.Optional[str] = None, **kwargs):
# If a child ObjCPP class has already set it, don't set it ourselves
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, exe_wrap)
@staticmethod
def get_display_language():

@ -40,7 +40,6 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler):
info: 'MachineInfo', comp_id, runner=None):
super().__init__(exelist, version, for_machine, info)
self.id = comp_id
self.is_cross = False
self.runner = runner
@classmethod

@ -30,6 +30,7 @@ from .compilers import (
from .mixins.gnu import GnuCompiler
if T.TYPE_CHECKING:
from ..dependencies import ExternalProgram
from ..envconfig import MachineInfo
d_feature_args = {'gcc': {'unittest': '-funittest',
@ -442,13 +443,13 @@ class DCompiler(Compiler):
language = 'd'
def __init__(self, exelist, version, for_machine: MachineChoice,
info: 'MachineInfo', arch, is_cross, exe_wrapper, **kwargs):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, exe_wrapper: T.Optional['ExternalProgram'] = None,
**kwargs):
super().__init__(exelist, version, for_machine, info, **kwargs)
self.id = 'unknown'
self.arch = arch
self.exe_wrapper = exe_wrapper
self.is_cross = is_cross
def sanity_check(self, work_dir, environment):
source_name = os.path.join(work_dir, 'sanity.d')
@ -639,9 +640,10 @@ class GnuDCompiler(GnuCompiler, DCompiler):
# we mostly want DCompiler, but that gives us the Compiler.LINKER_PREFIX instead
LINKER_PREFIX = GnuCompiler.LINKER_PREFIX
def __init__(self, exelist, version, for_machine: MachineChoice,
info: 'MachineInfo', is_cross, exe_wrapper, arch, **kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, is_cross, exe_wrapper, arch, **kwargs)
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, *, exe_wrapper: T.Optional['ExternalProgram'] = None,
**kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, exe_wrapper=exe_wrapper, **kwargs)
GnuCompiler.__init__(self, {})
self.id = 'gcc'
default_warn_args = ['-Wall', '-Wdeprecated']
@ -695,9 +697,9 @@ class GnuDCompiler(GnuCompiler, DCompiler):
class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
info: 'MachineInfo', arch, **kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, False, None, **kwargs)
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, **kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, **kwargs)
self.id = 'llvm'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']
@ -747,9 +749,9 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
info: 'MachineInfo', arch, **kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, False, None, **kwargs)
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, **kwargs):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, **kwargs)
self.id = 'dmd'
self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']

@ -44,9 +44,9 @@ class FortranCompiler(CLikeCompiler, Compiler):
language = 'fortran'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrapper)
is_cross: bool, info: 'MachineInfo', exe_wrapper=None, **kwargs):
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, exe_wrapper)
self.id = 'unknown'
def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=None):

@ -32,7 +32,6 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler):
info: 'MachineInfo'):
super().__init__(exelist, version, for_machine, info)
self.id = 'unknown'
self.is_cross = False
self.javarunner = 'java'
def get_werror_args(self):

@ -160,9 +160,8 @@ class CLikeCompiler:
find_framework_cache = {} # type: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], bool], T.Optional[T.List[str]]]
internal_libs = arglist.UNIXY_COMPILER_INTERNAL_LIBS
def __init__(self, is_cross: bool, exe_wrapper: T.Optional['ExternalProgram'] = None):
def __init__(self, exe_wrapper: T.Optional['ExternalProgram'] = None):
# If a child ObjC or CPP class has already set it, don't set it ourselves
self.is_cross = is_cross
self.can_compile_suffixes.add('h')
# If the exe wrapper was not found, pretend it wasn't set so that the
# sanity check is skipped and compiler checks use fallbacks.

@ -33,8 +33,8 @@ class ObjCCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrap: T.Optional[str], **kwargs):
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, exe_wrap)
@staticmethod
def get_display_language():

@ -32,8 +32,8 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo',
exe_wrap: T.Optional[str], **kwargs):
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrap)
Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, exe_wrap)
@staticmethod
def get_display_language():

@ -36,11 +36,10 @@ class RustCompiler(Compiler):
language = 'rust'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs):
super().__init__(exelist, version, for_machine, info, **kwargs)
is_cross: bool, info: 'MachineInfo', exe_wrapper=None, **kwargs):
super().__init__(exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
self.exe_wrapper = exe_wrapper
self.id = 'rustc'
self.is_cross = is_cross
def needs_static_linker(self):
return False

@ -36,11 +36,10 @@ class SwiftCompiler(Compiler):
language = 'swift'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo', **kwargs):
super().__init__(exelist, version, for_machine, info, **kwargs)
is_cross: bool, info: 'MachineInfo', **kwargs):
super().__init__(exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
self.version = version
self.id = 'llvm'
self.is_cross = is_cross
def needs_static_linker(self):
return True

@ -28,10 +28,9 @@ class ValaCompiler(Compiler):
language = 'vala'
def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross, info: 'MachineInfo'):
super().__init__(exelist, version, for_machine, info)
is_cross: bool, info: 'MachineInfo'):
super().__init__(exelist, version, for_machine, info, is_cross=is_cross)
self.version = version
self.is_cross = is_cross
self.id = 'valac'
self.base_options = ['b_colorout']

@ -1821,7 +1821,8 @@ class Environment:
elif 'gdc' in out:
linker = self._guess_nix_linker(exelist, compilers.GnuDCompiler, for_machine)
return compilers.GnuDCompiler(
exelist, version, for_machine, info, arch, is_cross, exe_wrap,
exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrap, is_cross=is_cross,
full_version=full_version, linker=linker)
elif 'The D Language Foundation' in out or 'Digital Mars' in out:
# DMD seems to require a file

Loading…
Cancel
Save