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, def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional[str] = None, **kwargs): 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 # 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) Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrapper) CLikeCompiler.__init__(self, exe_wrapper)
def get_no_stdinc_args(self): def get_no_stdinc_args(self):
return ['-nostdinc'] return ['-nostdinc']

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

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

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

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

@ -32,7 +32,6 @@ class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler):
info: 'MachineInfo'): info: 'MachineInfo'):
super().__init__(exelist, version, for_machine, info) super().__init__(exelist, version, for_machine, info)
self.id = 'unknown' self.id = 'unknown'
self.is_cross = False
self.javarunner = 'java' self.javarunner = 'java'
def get_werror_args(self): 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]]] 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 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 # 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') self.can_compile_suffixes.add('h')
# If the exe wrapper was not found, pretend it wasn't set so that the # If the exe wrapper was not found, pretend it wasn't set so that the
# sanity check is skipped and compiler checks use fallbacks. # 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, def __init__(self, exelist, version, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrap: T.Optional[str], **kwargs): exe_wrap: T.Optional[str], **kwargs):
Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) Compiler.__init__(self, exelist, version, for_machine, info, is_cross=is_cross, **kwargs)
CLikeCompiler.__init__(self, is_cross, exe_wrap) CLikeCompiler.__init__(self, exe_wrap)
@staticmethod @staticmethod
def get_display_language(): def get_display_language():

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

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

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

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

@ -1821,7 +1821,8 @@ class Environment:
elif 'gdc' in out: elif 'gdc' in out:
linker = self._guess_nix_linker(exelist, compilers.GnuDCompiler, for_machine) linker = self._guess_nix_linker(exelist, compilers.GnuDCompiler, for_machine)
return compilers.GnuDCompiler( 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) full_version=full_version, linker=linker)
elif 'The D Language Foundation' in out or 'Digital Mars' in out: elif 'The D Language Foundation' in out or 'Digital Mars' in out:
# DMD seems to require a file # DMD seems to require a file

Loading…
Cancel
Save