compilers: No need to pass exe_wrapper everywhere

Places where compiler needs it already have access to Environment object
and can use it directly.

This fixes mypy complaining that not all compilers have self.exe_wrapper
in run() method that got moved to base class.
pull/12983/head
Xavier Claessens 1 year ago committed by Xavier Claessens
parent 6b569527bc
commit c1076241af
  1. 7
      mesonbuild/backend/backends.py
  2. 67
      mesonbuild/compilers/c.py
  3. 4
      mesonbuild/compilers/compilers.py
  4. 64
      mesonbuild/compilers/cpp.py
  5. 12
      mesonbuild/compilers/cuda.py
  6. 18
      mesonbuild/compilers/d.py
  7. 107
      mesonbuild/compilers/detect.py
  8. 48
      mesonbuild/compilers/fortran.py
  9. 17
      mesonbuild/compilers/mixins/clike.py
  10. 10
      mesonbuild/compilers/objc.py
  11. 10
      mesonbuild/compilers/objcpp.py
  12. 9
      mesonbuild/compilers/rust.py
  13. 3
      mesonbuild/environment.py

@ -568,13 +568,12 @@ class Backend:
else: else:
extra_paths = [] extra_paths = []
is_cross_built = not self.environment.machines.matches_build_machine(exe_for_machine) if self.environment.need_exe_wrapper(exe_for_machine):
if is_cross_built and self.environment.need_exe_wrapper(): if not self.environment.has_exe_wrapper():
exe_wrapper = self.environment.get_exe_wrapper()
if not exe_wrapper or not exe_wrapper.found():
msg = 'An exe_wrapper is needed but was not found. Please define one ' \ msg = 'An exe_wrapper is needed but was not found. Please define one ' \
'in cross file and check the command and/or add it to PATH.' 'in cross file and check the command and/or add it to PATH.'
raise MesonException(msg) raise MesonException(msg)
exe_wrapper = self.environment.get_exe_wrapper()
else: else:
if exe_cmd[0].endswith('.jar'): if exe_cmd[0].endswith('.jar'):
exe_cmd = ['java', '-jar'] + exe_cmd exe_cmd = ['java', '-jar'] + exe_cmd

@ -39,7 +39,6 @@ if T.TYPE_CHECKING:
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice from ..mesonlib import MachineChoice
from ..programs import ExternalProgram
from .compilers import CompileCheckMode from .compilers import CompileCheckMode
CompilerMixinBase = Compiler CompilerMixinBase = Compiler
@ -61,13 +60,13 @@ class CCompiler(CLikeCompiler, Compiler):
language = 'c' language = 'c'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = 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
Compiler.__init__(self, ccache, exelist, version, for_machine, info, Compiler.__init__(self, ccache, exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, linker=linker) is_cross=is_cross, full_version=full_version, linker=linker)
CLikeCompiler.__init__(self, exe_wrapper) CLikeCompiler.__init__(self)
def get_no_stdinc_args(self) -> T.List[str]: def get_no_stdinc_args(self) -> T.List[str]:
return ['-nostdinc'] return ['-nostdinc']
@ -137,11 +136,11 @@ class _ClangCStds(CompilerMixinBase):
class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler): class ClangCCompiler(_ClangCStds, ClangCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version) CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines) ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -202,7 +201,7 @@ class EmscriptenCCompiler(EmscriptenMixin, ClangCCompiler):
id = 'emscripten' id = 'emscripten'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
@ -211,7 +210,7 @@ class EmscriptenCCompiler(EmscriptenMixin, ClangCCompiler):
if not version_compare(version, '>=1.39.19'): if not version_compare(version, '>=1.39.19'):
raise MesonException('Meson requires Emscripten >= 1.39.19') raise MesonException('Meson requires Emscripten >= 1.39.19')
ClangCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ClangCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper=exe_wrapper, linker=linker, info, linker=linker,
defines=defines, full_version=full_version) defines=defines, full_version=full_version)
@ -221,11 +220,11 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
''' '''
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ArmclangCompiler.__init__(self) ArmclangCompiler.__init__(self)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -260,11 +259,11 @@ class GnuCCompiler(GnuCompiler, CCompiler):
_INVALID_PCH_VERSION = ">=3.4.0" _INVALID_PCH_VERSION = ">=3.4.0"
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, exe_wrapper, linker=linker, full_version=full_version) CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, info, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines) GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall'] default_warn_args = ['-Wall']
if version_compare(self.version, self._INVALID_PCH_VERSION): if version_compare(self.version, self._INVALID_PCH_VERSION):
@ -322,11 +321,11 @@ class GnuCCompiler(GnuCompiler, CCompiler):
class PGICCompiler(PGICompiler, CCompiler): class PGICCompiler(PGICompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
@ -335,22 +334,22 @@ class NvidiaHPC_CCompiler(PGICompiler, CCompiler):
id = 'nvidia_hpc' id = 'nvidia_hpc'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
class ElbrusCCompiler(ElbrusCompiler, CCompiler): class ElbrusCCompiler(ElbrusCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self) ElbrusCompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -385,11 +384,11 @@ class ElbrusCCompiler(ElbrusCompiler, CCompiler):
class IntelCCompiler(IntelGnuLikeCompiler, CCompiler): class IntelCCompiler(IntelGnuLikeCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
IntelGnuLikeCompiler.__init__(self) IntelGnuLikeCompiler.__init__(self)
self.lang_header = 'c-header' self.lang_header = 'c-header'
default_warn_args = ['-Wall', '-w3'] default_warn_args = ['-Wall', '-w3']
@ -453,11 +452,10 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, info, linker=linker,
full_version=full_version) full_version=full_version)
MSVCCompiler.__init__(self, target) MSVCCompiler.__init__(self, target)
@ -487,11 +485,10 @@ class VisualStudioCCompiler(MSVCCompiler, VisualStudioLikeCCompilerMixin, CCompi
class ClangClCCompiler(_ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler): class ClangClCCompiler(_ClangCStds, ClangClCompiler, VisualStudioLikeCCompilerMixin, CCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, [], exelist, version, for_machine, is_cross, CCompiler.__init__(self, [], exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, info, linker=linker,
full_version=full_version) full_version=full_version)
ClangClCompiler.__init__(self, target) ClangClCompiler.__init__(self, target)
@ -509,11 +506,10 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, [], exelist, version, for_machine, is_cross, CCompiler.__init__(self, [], exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, info, linker=linker,
full_version=full_version) full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target) IntelVisualStudioLikeCompiler.__init__(self, target)
@ -543,11 +539,10 @@ class IntelLLVMClCCompiler(IntelClCCompiler):
class ArmCCompiler(ArmCompiler, CCompiler): class ArmCCompiler(ArmCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, info, linker=linker,
full_version=full_version) full_version=full_version)
ArmCompiler.__init__(self) ArmCompiler.__init__(self)
@ -570,11 +565,10 @@ class ArmCCompiler(ArmCompiler, CCompiler):
class CcrxCCompiler(CcrxCompiler, CCompiler): class CcrxCCompiler(CcrxCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
CcrxCompiler.__init__(self) CcrxCompiler.__init__(self)
# Override CCompiler.get_always_args # Override CCompiler.get_always_args
@ -622,11 +616,10 @@ class CcrxCCompiler(CcrxCompiler, CCompiler):
class Xc16CCompiler(Xc16Compiler, CCompiler): class Xc16CCompiler(Xc16Compiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
Xc16Compiler.__init__(self) Xc16Compiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -668,11 +661,10 @@ class Xc16CCompiler(Xc16Compiler, CCompiler):
class CompCertCCompiler(CompCertCompiler, CCompiler): class CompCertCCompiler(CompCertCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
CompCertCompiler.__init__(self) CompCertCompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -702,11 +694,10 @@ class CompCertCCompiler(CompCertCompiler, CCompiler):
class TICCompiler(TICompiler, CCompiler): class TICCompiler(TICompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
TICompiler.__init__(self) TICompiler.__init__(self)
# Override CCompiler.get_always_args # Override CCompiler.get_always_args
@ -743,11 +734,10 @@ class MetrowerksCCompilerARM(MetrowerksCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
MetrowerksCompiler.__init__(self) MetrowerksCompiler.__init__(self)
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
@ -772,11 +762,10 @@ class MetrowerksCCompilerEmbeddedPowerPC(MetrowerksCompiler, CCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
MetrowerksCompiler.__init__(self) MetrowerksCompiler.__init__(self)
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:

@ -629,14 +629,14 @@ class Compiler(HoldableObject, metaclass=abc.ABCMeta):
run_env: T.Optional[T.Dict[str, str]] = None, run_env: T.Optional[T.Dict[str, str]] = None,
run_cwd: T.Optional[str] = None) -> RunResult: run_cwd: T.Optional[str] = None) -> RunResult:
need_exe_wrapper = env.need_exe_wrapper(self.for_machine) need_exe_wrapper = env.need_exe_wrapper(self.for_machine)
if need_exe_wrapper and self.exe_wrapper is None: if need_exe_wrapper and not env.has_exe_wrapper():
raise CrossNoRunException('Can not run test applications in this cross environment.') raise CrossNoRunException('Can not run test applications in this cross environment.')
with self._build_wrapper(code, env, extra_args, dependencies, mode=CompileCheckMode.LINK, want_output=True) as p: with self._build_wrapper(code, env, extra_args, dependencies, mode=CompileCheckMode.LINK, want_output=True) as p:
if p.returncode != 0: if p.returncode != 0:
mlog.debug(f'Could not compile test file {p.input_name}: {p.returncode}\n') mlog.debug(f'Could not compile test file {p.input_name}: {p.returncode}\n')
return RunResult(False) return RunResult(False)
if need_exe_wrapper: if need_exe_wrapper:
cmdlist = self.exe_wrapper.get_command() + [p.output_name] cmdlist = env.exe_wrapper.get_command() + [p.output_name]
else: else:
cmdlist = [p.output_name] cmdlist = [p.output_name]
try: try:

@ -40,7 +40,6 @@ if T.TYPE_CHECKING:
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice from ..mesonlib import MachineChoice
from ..programs import ExternalProgram
CompilerMixinBase = CLikeCompiler CompilerMixinBase = CLikeCompiler
else: else:
CompilerMixinBase = object CompilerMixinBase = object
@ -67,14 +66,14 @@ class CPPCompiler(CLikeCompiler, Compiler):
language = 'cpp' language = 'cpp'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
# 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, ccache, exelist, version, for_machine, info, Compiler.__init__(self, ccache, exelist, version, for_machine, info,
is_cross=is_cross, linker=linker, is_cross=is_cross, linker=linker,
full_version=full_version) full_version=full_version)
CLikeCompiler.__init__(self, exe_wrapper) CLikeCompiler.__init__(self)
@classmethod @classmethod
def get_display_language(cls) -> str: def get_display_language(cls) -> str:
@ -221,12 +220,12 @@ class ClangCPPCompiler(_StdCPPLibMixin, ClangCompiler, CPPCompiler):
_CPP26_VERSION = '>=17.0.0' _CPP26_VERSION = '>=17.0.0'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines) ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -336,7 +335,7 @@ class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
id = 'emscripten' id = 'emscripten'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
@ -345,7 +344,7 @@ class EmscriptenCPPCompiler(EmscriptenMixin, ClangCPPCompiler):
if not version_compare(version, '>=1.39.19'): if not version_compare(version, '>=1.39.19'):
raise MesonException('Meson requires Emscripten >= 1.39.19') raise MesonException('Meson requires Emscripten >= 1.39.19')
ClangCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ClangCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper=exe_wrapper, linker=linker, info, linker=linker,
defines=defines, full_version=full_version) defines=defines, full_version=full_version)
def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]: def get_option_compile_args(self, options: 'KeyedOptionDictType') -> T.List[str]:
@ -363,11 +362,11 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
''' '''
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ArmclangCompiler.__init__(self) ArmclangCompiler.__init__(self)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -408,12 +407,12 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler): class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines) GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -500,11 +499,11 @@ class GnuCPPCompiler(_StdCPPLibMixin, GnuCompiler, CPPCompiler):
class PGICPPCompiler(PGICompiler, CPPCompiler): class PGICPPCompiler(PGICompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
@ -513,22 +512,22 @@ class NvidiaHPC_CPPCompiler(PGICompiler, CPPCompiler):
id = 'nvidia_hpc' id = 'nvidia_hpc'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self) ElbrusCompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -596,11 +595,11 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler):
class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
IntelGnuLikeCompiler.__init__(self) IntelGnuLikeCompiler.__init__(self)
self.lang_header = 'c++-header' self.lang_header = 'c++-header'
default_warn_args = ['-Wall', '-w3', '-Wpch-messages'] default_warn_args = ['-Wall', '-w3', '-Wpch-messages']
@ -776,11 +775,10 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
MSVCCompiler.__init__(self, target) MSVCCompiler.__init__(self, target)
# By default, MSVC has a broken __cplusplus define that pretends to be c++98: # By default, MSVC has a broken __cplusplus define that pretends to be c++98:
@ -824,11 +822,10 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Cl
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, [], exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, [], exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ClangClCompiler.__init__(self, target) ClangClCompiler.__init__(self, target)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -840,11 +837,10 @@ class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLike
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, [], exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, [], exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target) IntelVisualStudioLikeCompiler.__init__(self, target)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -864,11 +860,11 @@ class IntelLLVMClCPPCompiler(IntelClCPPCompiler):
class ArmCPPCompiler(ArmCompiler, CPPCompiler): class ArmCPPCompiler(ArmCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ArmCompiler.__init__(self) ArmCompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -897,11 +893,11 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler):
class CcrxCPPCompiler(CcrxCompiler, CPPCompiler): class CcrxCPPCompiler(CcrxCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
CcrxCompiler.__init__(self) CcrxCompiler.__init__(self)
# Override CCompiler.get_always_args # Override CCompiler.get_always_args
@ -925,11 +921,11 @@ class CcrxCPPCompiler(CcrxCompiler, CPPCompiler):
class TICPPCompiler(TICompiler, CPPCompiler): class TICPPCompiler(TICompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
TICompiler.__init__(self) TICompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -965,11 +961,10 @@ class MetrowerksCPPCompilerARM(MetrowerksCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
MetrowerksCompiler.__init__(self) MetrowerksCompiler.__init__(self)
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:
@ -994,11 +989,10 @@ class MetrowerksCPPCompilerEmbeddedPowerPC(MetrowerksCompiler, CPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, CPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
MetrowerksCompiler.__init__(self) MetrowerksCompiler.__init__(self)
def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]: def get_instruction_set_args(self, instruction_set: str) -> T.Optional[T.List[str]]:

@ -25,7 +25,6 @@ if T.TYPE_CHECKING:
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice from ..mesonlib import MachineChoice
from ..programs import ExternalProgram
cuda_optimization_args: T.Dict[str, T.List[str]] = { cuda_optimization_args: T.Dict[str, T.List[str]] = {
@ -184,12 +183,11 @@ class CudaCompiler(Compiler):
id = 'nvcc' id = 'nvcc'
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, exe_wrapper: T.Optional['ExternalProgram'], is_cross: bool,
host_compiler: Compiler, info: 'MachineInfo', host_compiler: Compiler, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
super().__init__(ccache, exelist, version, for_machine, info, linker=linker, full_version=full_version, is_cross=is_cross) super().__init__(ccache, exelist, version, for_machine, info, linker=linker, full_version=full_version, is_cross=is_cross)
self.exe_wrapper = exe_wrapper
self.host_compiler = host_compiler self.host_compiler = host_compiler
self.base_options = host_compiler.base_options self.base_options = host_compiler.base_options
# -Wpedantic generates useless churn due to nvcc's dual compilation model producing # -Wpedantic generates useless churn due to nvcc's dual compilation model producing
@ -550,7 +548,7 @@ class CudaCompiler(Compiler):
flags += self.get_ccbin_args(env.coredata.options) flags += self.get_ccbin_args(env.coredata.options)
# If cross-compiling, we can't run the sanity check, only compile it. # If cross-compiling, we can't run the sanity check, only compile it.
if self.is_cross and self.exe_wrapper is None: if env.need_exe_wrapper(self.for_machine) and not env.has_exe_wrapper():
# Linking cross built apps is painful. You can't really # Linking cross built apps is painful. You can't really
# tell if you should use -nostdlib or not and for example # tell if you should use -nostdlib or not and for example
# on OSX the compiler binary is the same but you need # on OSX the compiler binary is the same but you need
@ -572,11 +570,11 @@ class CudaCompiler(Compiler):
raise EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.') raise EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
# Run sanity check (if possible) # Run sanity check (if possible)
if self.is_cross: if env.need_exe_wrapper(self.for_machine):
if self.exe_wrapper is None: if not env.has_exe_wrapper():
return return
else: else:
cmdlist = self.exe_wrapper.get_command() + [binary_name] cmdlist = env.exe_wrapper.get_command() + [binary_name]
else: else:
cmdlist = self.exelist + ['--run', '"' + binary_name + '"'] cmdlist = self.exelist + ['--run', '"' + binary_name + '"']
mlog.debug('Sanity check run command line: ', ' '.join(cmdlist)) mlog.debug('Sanity check run command line: ', ' '.join(cmdlist))

@ -27,7 +27,6 @@ from .mixins.gnu import gnu_common_warning_args
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..build import DFeatures from ..build import DFeatures
from ..dependencies import Dependency from ..dependencies import Dependency
from ..programs import ExternalProgram
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
@ -432,14 +431,12 @@ class DCompiler(Compiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, *, info: 'MachineInfo', arch: str, *,
exe_wrapper: T.Optional['ExternalProgram'] = None,
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): is_cross: bool = False):
super().__init__([], exelist, version, for_machine, info, linker=linker, super().__init__([], exelist, version, for_machine, info, linker=linker,
full_version=full_version, is_cross=is_cross) full_version=full_version, is_cross=is_cross)
self.arch = arch self.arch = arch
self.exe_wrapper = exe_wrapper
def sanity_check(self, work_dir: str, environment: 'Environment') -> None: def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
source_name = os.path.join(work_dir, 'sanity.d') source_name = os.path.join(work_dir, 'sanity.d')
@ -450,11 +447,11 @@ class DCompiler(Compiler):
pc.wait() pc.wait()
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string()) raise EnvironmentException('D compiler %s cannot compile programs.' % self.name_string())
if self.is_cross: if environment.need_exe_wrapper(self.for_machine):
if self.exe_wrapper is None: if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do # Can't check if the binaries run so we have to assume they do
return return
cmdlist = self.exe_wrapper.get_command() + [output_name] cmdlist = environment.exe_wrapper.get_command() + [output_name]
else: else:
cmdlist = [output_name] cmdlist = [output_name]
if subprocess.call(cmdlist) != 0: if subprocess.call(cmdlist) != 0:
@ -641,12 +638,11 @@ class GnuDCompiler(GnuCompiler, DCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, *, info: 'MachineInfo', arch: str, *,
exe_wrapper: T.Optional['ExternalProgram'] = None,
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): is_cross: bool = False):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, DCompiler.__init__(self, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrapper, linker=linker, linker=linker,
full_version=full_version, is_cross=is_cross) full_version=full_version, is_cross=is_cross)
GnuCompiler.__init__(self, {}) GnuCompiler.__init__(self, {})
default_warn_args = ['-Wall', '-Wdeprecated'] default_warn_args = ['-Wall', '-Wdeprecated']
@ -725,12 +721,11 @@ class LLVMDCompiler(DmdLikeCompilerMixin, DCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, *, info: 'MachineInfo', arch: str, *,
exe_wrapper: T.Optional['ExternalProgram'] = None,
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, version_output: T.Optional[str] = None): is_cross: bool = False, version_output: T.Optional[str] = None):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, DCompiler.__init__(self, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrapper, linker=linker, linker=linker,
full_version=full_version, is_cross=is_cross) full_version=full_version, is_cross=is_cross)
DmdLikeCompilerMixin.__init__(self, dmd_frontend_version=find_ldc_dmd_frontend_version(version_output)) DmdLikeCompilerMixin.__init__(self, dmd_frontend_version=find_ldc_dmd_frontend_version(version_output))
self.base_options = {OptionKey(o) for o in ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']} self.base_options = {OptionKey(o) for o in ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']}
@ -789,12 +784,11 @@ class DmdDCompiler(DmdLikeCompilerMixin, DCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
info: 'MachineInfo', arch: str, *, info: 'MachineInfo', arch: str, *,
exe_wrapper: T.Optional['ExternalProgram'] = None,
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): is_cross: bool = False):
DCompiler.__init__(self, exelist, version, for_machine, info, arch, DCompiler.__init__(self, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrapper, linker=linker, linker=linker,
full_version=full_version, is_cross=is_cross) full_version=full_version, is_cross=is_cross)
DmdLikeCompilerMixin.__init__(self, version) DmdLikeCompilerMixin.__init__(self, version)
self.base_options = {OptionKey(o) for o in ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']} self.base_options = {OptionKey(o) for o in ['b_coverage', 'b_colorout', 'b_vscrt', 'b_ndebug']}

@ -28,7 +28,6 @@ if T.TYPE_CHECKING:
from .rust import RustCompiler from .rust import RustCompiler
from ..linkers.linkers import StaticLinker, DynamicLinker from ..linkers.linkers import StaticLinker, DynamicLinker
from ..environment import Environment from ..environment import Environment
from ..programs import ExternalProgram
# Default compilers and linkers # Default compilers and linkers
@ -116,7 +115,7 @@ def detect_compiler_for(env: 'Environment', lang: str, for_machine: MachineChoic
# Helpers # Helpers
# ======= # =======
def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Tuple[T.List[T.List[str]], T.List[str], T.Optional['ExternalProgram']]: def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) -> T.Tuple[T.List[T.List[str]], T.List[str]]:
''' '''
The list of compilers is detected in the exact same way for The list of compilers is detected in the exact same way for
C, C++, ObjC, ObjC++, Fortran, CS so consolidate it here. C, C++, ObjC, ObjC++, Fortran, CS so consolidate it here.
@ -132,12 +131,7 @@ def _get_compilers(env: 'Environment', lang: str, for_machine: MachineChoice) ->
compilers = [[x] for x in defaults[lang]] compilers = [[x] for x in defaults[lang]]
ccache = BinaryTable.detect_compiler_cache() ccache = BinaryTable.detect_compiler_cache()
if env.machines.matches_build_machine(for_machine): return compilers, ccache
exe_wrap: T.Optional[ExternalProgram] = None
else:
exe_wrap = env.get_exe_wrapper()
return compilers, ccache, exe_wrap
def _handle_exceptions( def _handle_exceptions(
exceptions: T.Mapping[str, T.Union[Exception, str]], exceptions: T.Mapping[str, T.Union[Exception, str]],
@ -269,7 +263,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
from . import c, cpp from . import c, cpp
from ..linkers import linkers from ..linkers import linkers
popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {} popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {}
compilers, ccache, exe_wrap = _get_compilers(env, lang, for_machine) compilers, ccache = _get_compilers(env, lang, for_machine)
if override_compiler is not None: if override_compiler is not None:
compilers = [override_compiler] compilers = [override_compiler]
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
@ -361,7 +355,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, ccache, compiler, version, for_machine, is_cross,
info, exe_wrap, defines=defines, full_version=full_version, info, defines=defines, full_version=full_version,
linker=linker) linker=linker)
if 'Emscripten' in out: if 'Emscripten' in out:
@ -380,7 +374,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
[], version=search_version(o)) [], version=search_version(o))
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, linker=linker, full_version=full_version) linker=linker, full_version=full_version)
if 'Arm C/C++/Fortran Compiler' in out: if 'Arm C/C++/Fortran Compiler' in out:
arm_ver_match = re.search(r'version (\d+)\.(\d+)\.?(\d+)? \(build number (\d+)\)', out) arm_ver_match = re.search(r'version (\d+)\.(\d+)\.?(\d+)? \(build number (\d+)\)', out)
@ -393,7 +387,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, linker=linker) linker=linker)
if 'armclang' in out: if 'armclang' in out:
# The compiler version is not present in the first line of output, # The compiler version is not present in the first line of output,
# instead it is present in second line, startswith 'Component:'. # instead it is present in second line, startswith 'Component:'.
@ -413,7 +407,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'CL.EXE COMPATIBILITY' in out: if 'CL.EXE COMPATIBILITY' in out:
# if this is clang-cl masquerading as cl, detect it as cl, not # if this is clang-cl masquerading as cl, detect it as cl, not
# clang # clang
@ -432,7 +426,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = guess_win_linker(env, ['lld-link'], cls, version, for_machine) linker = guess_win_linker(env, ['lld-link'], cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, target, compiler, version, for_machine, is_cross, info, target,
exe_wrap, linker=linker) linker=linker)
# must be detected here before clang because TI compilers contain 'clang' in their output and so that they can be detected as 'clang' # must be detected here before clang because TI compilers contain 'clang' in their output and so that they can be detected as 'clang'
ti_compilers = { ti_compilers = {
@ -449,7 +443,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = lnk(compiler, for_machine, version=version) linker = lnk(compiler, for_machine, version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'clang' in out or 'Clang' in out: if 'clang' in out or 'Clang' in out:
linker = None linker = None
@ -476,7 +470,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, defines=defines, full_version=full_version, linker=linker) defines=defines, full_version=full_version, linker=linker)
if 'Intel(R) C++ Intel(R)' in err: if 'Intel(R) C++ Intel(R)' in err:
version = search_version(err) version = search_version(err)
@ -486,7 +480,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = linkers.XilinkDynamicLinker(for_machine, [], version=version) linker = linkers.XilinkDynamicLinker(for_machine, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, target, compiler, version, for_machine, is_cross, info, target,
exe_wrap, linker=linker) linker=linker)
if 'Intel(R) oneAPI DPC++/C++ Compiler for applications' in err: if 'Intel(R) oneAPI DPC++/C++ Compiler for applications' in err:
version = search_version(err) version = search_version(err)
target = 'x86' if 'IA-32' in err else 'x86_64' target = 'x86' if 'IA-32' in err else 'x86_64'
@ -495,7 +489,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = linkers.XilinkDynamicLinker(for_machine, [], version=version) linker = linkers.XilinkDynamicLinker(for_machine, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, target, compiler, version, for_machine, is_cross, info, target,
exe_wrap, linker=linker) linker=linker)
if 'Microsoft' in out or 'Microsoft' in err: if 'Microsoft' in out or 'Microsoft' in err:
# Latest versions of Visual Studio print version # Latest versions of Visual Studio print version
# number to stderr but earlier ones print version # number to stderr but earlier ones print version
@ -521,47 +515,47 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
ccache = [] ccache = []
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, target, ccache, compiler, version, for_machine, is_cross, info, target,
exe_wrap, full_version=cl_signature, linker=linker) full_version=cl_signature, linker=linker)
if 'PGI Compilers' in out: if 'PGI Compilers' in out:
cls = c.PGICCompiler if lang == 'c' else cpp.PGICPPCompiler cls = c.PGICCompiler if lang == 'c' else cpp.PGICPPCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
linker = linkers.PGIDynamicLinker(compiler, for_machine, cls.LINKER_PREFIX, [], version=version) linker = linkers.PGIDynamicLinker(compiler, for_machine, cls.LINKER_PREFIX, [], version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, ccache, compiler, version, for_machine, is_cross,
info, exe_wrap, linker=linker) info, linker=linker)
if 'NVIDIA Compilers and Tools' in out: if 'NVIDIA Compilers and Tools' in out:
cls = c.NvidiaHPC_CCompiler if lang == 'c' else cpp.NvidiaHPC_CPPCompiler cls = c.NvidiaHPC_CCompiler if lang == 'c' else cpp.NvidiaHPC_CPPCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
linker = linkers.NvidiaHPC_DynamicLinker(compiler, for_machine, cls.LINKER_PREFIX, [], version=version) linker = linkers.NvidiaHPC_DynamicLinker(compiler, for_machine, cls.LINKER_PREFIX, [], version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, ccache, compiler, version, for_machine, is_cross,
info, exe_wrap, linker=linker) info, linker=linker)
if '(ICC)' in out: if '(ICC)' in out:
cls = c.IntelCCompiler if lang == 'c' else cpp.IntelCPPCompiler cls = c.IntelCCompiler if lang == 'c' else cpp.IntelCPPCompiler
l = guess_nix_linker(env, compiler, cls, version, for_machine) l = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=l) full_version=full_version, linker=l)
if 'Intel(R) oneAPI' in out: if 'Intel(R) oneAPI' in out:
cls = c.IntelLLVMCCompiler if lang == 'c' else cpp.IntelLLVMCPPCompiler cls = c.IntelLLVMCCompiler if lang == 'c' else cpp.IntelLLVMCPPCompiler
l = guess_nix_linker(env, compiler, cls, version, for_machine) l = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=l) full_version=full_version, linker=l)
if 'ARM' in out and not ('Metrowerks' in out or 'Freescale' in out): if 'ARM' in out and not ('Metrowerks' in out or 'Freescale' in out):
cls = c.ArmCCompiler if lang == 'c' else cpp.ArmCPPCompiler cls = c.ArmCCompiler if lang == 'c' else cpp.ArmCPPCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
linker = linkers.ArmDynamicLinker(for_machine, version=version) linker = linkers.ArmDynamicLinker(for_machine, version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, ccache, compiler, version, for_machine, is_cross,
info, exe_wrap, full_version=full_version, linker=linker) info, full_version=full_version, linker=linker)
if 'RX Family' in out: if 'RX Family' in out:
cls = c.CcrxCCompiler if lang == 'c' else cpp.CcrxCPPCompiler cls = c.CcrxCCompiler if lang == 'c' else cpp.CcrxCPPCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
linker = linkers.CcrxDynamicLinker(for_machine, version=version) linker = linkers.CcrxDynamicLinker(for_machine, version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'Microchip Technology' in out: if 'Microchip Technology' in out:
cls = c.Xc16CCompiler cls = c.Xc16CCompiler
@ -569,7 +563,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = linkers.Xc16DynamicLinker(for_machine, version=version) linker = linkers.Xc16DynamicLinker(for_machine, version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'CompCert' in out: if 'CompCert' in out:
cls = c.CompCertCCompiler cls = c.CompCertCCompiler
@ -577,7 +571,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
linker = linkers.CompCertDynamicLinker(for_machine, version=version) linker = linkers.CompCertDynamicLinker(for_machine, version=version)
return cls( return cls(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'Metrowerks C/C++' in out or 'Freescale C/C++' in out: if 'Metrowerks C/C++' in out or 'Freescale C/C++' in out:
if 'ARM' in out: if 'ARM' in out:
@ -607,7 +601,7 @@ def _detect_c_or_cpp_compiler(env: 'Environment', lang: str, for_machine: Machin
return cls( return cls(
ccache, compiler, compiler_version, for_machine, is_cross, info, ccache, compiler, compiler_version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
_handle_exceptions(popen_exceptions, compilers) _handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException(f'Unknown compiler {compilers}') raise EnvironmentException(f'Unknown compiler {compilers}')
@ -623,7 +617,7 @@ def detect_cuda_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
from ..linkers.linkers import CudaLinker from ..linkers.linkers import CudaLinker
popen_exceptions = {} popen_exceptions = {}
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
compilers, ccache, exe_wrap = _get_compilers(env, 'cuda', for_machine) compilers, ccache = _get_compilers(env, 'cuda', for_machine)
info = env.machines[for_machine] info = env.machines[for_machine]
for compiler in compilers: for compiler in compilers:
arg = '--version' arg = '--version'
@ -652,14 +646,14 @@ def detect_cuda_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
cls = CudaCompiler cls = CudaCompiler
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
linker = CudaLinker(compiler, for_machine, CudaCompiler.LINKER_PREFIX, [], version=CudaLinker.parse_version()) linker = CudaLinker(compiler, for_machine, CudaCompiler.LINKER_PREFIX, [], version=CudaLinker.parse_version())
return cls(ccache, compiler, version, for_machine, is_cross, exe_wrap, host_compiler=cpp_compiler, info=info, linker=linker) return cls(ccache, compiler, version, for_machine, is_cross, host_compiler=cpp_compiler, info=info, linker=linker)
raise EnvironmentException(f'Could not find suitable CUDA compiler: "{"; ".join([" ".join(c) for c in compilers])}"') raise EnvironmentException(f'Could not find suitable CUDA compiler: "{"; ".join([" ".join(c) for c in compilers])}"')
def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler: def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
from . import fortran from . import fortran
from ..linkers import linkers from ..linkers import linkers
popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {} popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {}
compilers, ccache, exe_wrap = _get_compilers(env, 'fortran', for_machine) compilers, ccache = _get_compilers(env, 'fortran', for_machine)
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
info = env.machines[for_machine] info = env.machines[for_machine]
cls: T.Type[FortranCompiler] cls: T.Type[FortranCompiler]
@ -691,14 +685,14 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, defines, full_version=full_version, linker=linker) defines, full_version=full_version, linker=linker)
else: else:
version = _get_gnu_version_from_defines(defines) version = _get_gnu_version_from_defines(defines)
cls = fortran.GnuFortranCompiler cls = fortran.GnuFortranCompiler
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, defines, full_version=full_version, linker=linker) defines, full_version=full_version, linker=linker)
if 'Arm C/C++/Fortran Compiler' in out: if 'Arm C/C++/Fortran Compiler' in out:
cls = fortran.ArmLtdFlangFortranCompiler cls = fortran.ArmLtdFlangFortranCompiler
@ -708,13 +702,13 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, linker=linker) linker=linker)
if 'G95' in out: if 'G95' in out:
cls = fortran.G95FortranCompiler cls = fortran.G95FortranCompiler
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'Sun Fortran' in err: if 'Sun Fortran' in err:
version = search_version(err) version = search_version(err)
@ -722,7 +716,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'Intel(R) Fortran Compiler for applications' in err: if 'Intel(R) Fortran Compiler for applications' in err:
version = search_version(err) version = search_version(err)
@ -732,7 +726,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = linkers.XilinkDynamicLinker(for_machine, [], version=version) linker = linkers.XilinkDynamicLinker(for_machine, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
target, exe_wrap, linker=linker) target, linker=linker)
if 'Intel(R) Visual Fortran' in err or 'Intel(R) Fortran' in err: if 'Intel(R) Visual Fortran' in err or 'Intel(R) Fortran' in err:
version = search_version(err) version = search_version(err)
@ -742,26 +736,26 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = linkers.XilinkDynamicLinker(for_machine, [], version=version) linker = linkers.XilinkDynamicLinker(for_machine, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
target, exe_wrap, linker=linker) target, linker=linker)
if 'ifort (IFORT)' in out: if 'ifort (IFORT)' in out:
cls = fortran.IntelFortranCompiler cls = fortran.IntelFortranCompiler
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'ifx (IFORT)' in out or 'ifx (IFX)' in out: if 'ifx (IFORT)' in out or 'ifx (IFX)' in out:
cls = fortran.IntelLLVMFortranCompiler cls = fortran.IntelLLVMFortranCompiler
linker = guess_nix_linker(env, compiler, cls, version, for_machine) linker = guess_nix_linker(env, compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'PathScale EKOPath(tm)' in err: if 'PathScale EKOPath(tm)' in err:
return fortran.PathScaleFortranCompiler( return fortran.PathScaleFortranCompiler(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version) full_version=full_version)
if 'PGI Compilers' in out: if 'PGI Compilers' in out:
cls = fortran.PGIFortranCompiler cls = fortran.PGIFortranCompiler
@ -769,7 +763,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = linkers.PGIDynamicLinker(compiler, for_machine, linker = linkers.PGIDynamicLinker(compiler, for_machine,
cls.LINKER_PREFIX, [], version=version) cls.LINKER_PREFIX, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, exe_wrap, compiler, version, for_machine, is_cross, info,
full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'NVIDIA Compilers and Tools' in out: if 'NVIDIA Compilers and Tools' in out:
@ -778,7 +772,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
linker = linkers.PGIDynamicLinker(compiler, for_machine, linker = linkers.PGIDynamicLinker(compiler, for_machine,
cls.LINKER_PREFIX, [], version=version) cls.LINKER_PREFIX, [], version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, exe_wrap, compiler, version, for_machine, is_cross, info,
full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'flang' in out or 'clang' in out: if 'flang' in out or 'clang' in out:
@ -800,7 +794,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
version, for_machine) version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'Open64 Compiler Suite' in err: if 'Open64 Compiler Suite' in err:
cls = fortran.Open64FortranCompiler cls = fortran.Open64FortranCompiler
@ -808,7 +802,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
compiler, cls, version, for_machine) compiler, cls, version, for_machine)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
if 'NAG Fortran' in err: if 'NAG Fortran' in err:
full_version = err.split('\n', 1)[0] full_version = err.split('\n', 1)[0]
@ -820,7 +814,7 @@ def detect_fortran_compiler(env: 'Environment', for_machine: MachineChoice) -> C
version=version) version=version)
return cls( return cls(
compiler, version, for_machine, is_cross, info, compiler, version, for_machine, is_cross, info,
exe_wrap, full_version=full_version, linker=linker) full_version=full_version, linker=linker)
_handle_exceptions(popen_exceptions, compilers) _handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException('Unreachable code (exception to make mypy happy)') raise EnvironmentException('Unreachable code (exception to make mypy happy)')
@ -834,7 +828,7 @@ def detect_objcpp_compiler(env: 'Environment', for_machine: MachineChoice) -> 'C
def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine: MachineChoice) -> 'Compiler': def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine: MachineChoice) -> 'Compiler':
from . import objc, objcpp from . import objc, objcpp
popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {} popen_exceptions: T.Dict[str, T.Union[Exception, str]] = {}
compilers, ccache, exe_wrap = _get_compilers(env, lang, for_machine) compilers, ccache = _get_compilers(env, lang, for_machine)
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
info = env.machines[for_machine] info = env.machines[for_machine]
comp: T.Union[T.Type[objc.ObjCCompiler], T.Type[objcpp.ObjCPPCompiler]] comp: T.Union[T.Type[objc.ObjCCompiler], T.Type[objcpp.ObjCPPCompiler]]
@ -857,7 +851,7 @@ def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine:
linker = guess_nix_linker(env, compiler, comp, version, for_machine) linker = guess_nix_linker(env, compiler, comp, version, for_machine)
return comp( return comp(
ccache, compiler, version, for_machine, is_cross, info, ccache, compiler, version, for_machine, is_cross, info,
exe_wrap, defines, linker=linker) defines, linker=linker)
if 'clang' in out: if 'clang' in out:
linker = None linker = None
defines = _get_clang_compiler_defines(compiler) defines = _get_clang_compiler_defines(compiler)
@ -879,7 +873,7 @@ def _detect_objc_or_objcpp_compiler(env: 'Environment', lang: str, for_machine:
linker = guess_nix_linker(env, compiler, comp, version, for_machine) linker = guess_nix_linker(env, compiler, comp, version, for_machine)
return comp( return comp(
ccache, compiler, version, for_machine, ccache, compiler, version, for_machine,
is_cross, info, exe_wrap, linker=linker, defines=defines) is_cross, info, linker=linker, defines=defines)
_handle_exceptions(popen_exceptions, compilers) _handle_exceptions(popen_exceptions, compilers)
raise EnvironmentException('Unreachable code (exception to make mypy happy)') raise EnvironmentException('Unreachable code (exception to make mypy happy)')
@ -908,7 +902,7 @@ def detect_java_compiler(env: 'Environment', for_machine: MachineChoice) -> Comp
def detect_cs_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler: def detect_cs_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
from . import cs from . import cs
compilers, ccache, exe_wrap = _get_compilers(env, 'cs', for_machine) compilers, ccache = _get_compilers(env, 'cs', for_machine)
popen_exceptions = {} popen_exceptions = {}
info = env.machines[for_machine] info = env.machines[for_machine]
for comp in compilers: for comp in compilers:
@ -935,7 +929,7 @@ def detect_cs_compiler(env: 'Environment', for_machine: MachineChoice) -> Compil
def detect_cython_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler: def detect_cython_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
"""Search for a cython compiler.""" """Search for a cython compiler."""
from .cython import CythonCompiler from .cython import CythonCompiler
compilers, _, _ = _get_compilers(env, 'cython', MachineChoice.BUILD) compilers, _ = _get_compilers(env, 'cython', MachineChoice.BUILD)
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
info = env.machines[for_machine] info = env.machines[for_machine]
@ -985,7 +979,7 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust
from . import rust from . import rust
from ..linkers import linkers from ..linkers import linkers
popen_exceptions: T.Dict[str, Exception] = {} popen_exceptions: T.Dict[str, Exception] = {}
compilers, _, exe_wrap = _get_compilers(env, 'rust', for_machine) compilers, _ = _get_compilers(env, 'rust', for_machine)
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
info = env.machines[for_machine] info = env.machines[for_machine]
@ -1092,7 +1086,7 @@ def detect_rust_compiler(env: 'Environment', for_machine: MachineChoice) -> Rust
env.coredata.add_lang_args(cls.language, cls, for_machine, env) env.coredata.add_lang_args(cls.language, cls, for_machine, env)
return cls( return cls(
compiler, version, for_machine, is_cross, info, exe_wrap, compiler, version, for_machine, is_cross, info,
linker=linker) linker=linker)
_handle_exceptions(popen_exceptions, compilers) _handle_exceptions(popen_exceptions, compilers)
@ -1117,7 +1111,7 @@ def detect_d_compiler(env: 'Environment', for_machine: MachineChoice) -> Compile
popen_exceptions = {} popen_exceptions = {}
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
compilers, ccache, exe_wrap = _get_compilers(env, 'd', for_machine) compilers, ccache = _get_compilers(env, 'd', for_machine)
cls: T.Type[d.DCompiler] cls: T.Type[d.DCompiler]
for exelist in compilers: for exelist in compilers:
# Search for a D compiler. # Search for a D compiler.
@ -1172,8 +1166,7 @@ def detect_d_compiler(env: 'Environment', for_machine: MachineChoice) -> Compile
linker = guess_nix_linker(env, exelist, cls, version, for_machine) linker = guess_nix_linker(env, exelist, cls, version, for_machine)
return cls( return cls(
exelist, version, for_machine, info, arch, exelist, version, for_machine, info, arch,
exe_wrapper=exe_wrap, is_cross=is_cross, 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:
cls = d.DmdDCompiler cls = d.DmdDCompiler
# DMD seems to require a file # DMD seems to require a file
@ -1237,7 +1230,7 @@ def detect_swift_compiler(env: 'Environment', for_machine: MachineChoice) -> Com
def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler: def detect_nasm_compiler(env: 'Environment', for_machine: MachineChoice) -> Compiler:
from .asm import NasmCompiler, YasmCompiler, MetrowerksAsmCompilerARM, MetrowerksAsmCompilerEmbeddedPowerPC from .asm import NasmCompiler, YasmCompiler, MetrowerksAsmCompilerARM, MetrowerksAsmCompilerEmbeddedPowerPC
compilers, _, _ = _get_compilers(env, 'nasm', for_machine) compilers, _ = _get_compilers(env, 'nasm', for_machine)
is_cross = env.is_cross_build(for_machine) is_cross = env.is_cross_build(for_machine)
# We need a C compiler to properly detect the machine info and linker # We need a C compiler to properly detect the machine info and linker

@ -31,7 +31,6 @@ if T.TYPE_CHECKING:
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice from ..mesonlib import MachineChoice
from ..programs import ExternalProgram
class FortranCompiler(CLikeCompiler, Compiler): class FortranCompiler(CLikeCompiler, Compiler):
@ -39,12 +38,12 @@ class FortranCompiler(CLikeCompiler, Compiler):
language = 'fortran' language = 'fortran'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
Compiler.__init__(self, [], exelist, version, for_machine, info, Compiler.__init__(self, [], exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, linker=linker) is_cross=is_cross, full_version=full_version, linker=linker)
CLikeCompiler.__init__(self, exe_wrapper) CLikeCompiler.__init__(self)
def has_function(self, funcname: str, prefix: str, env: 'Environment', *, def has_function(self, funcname: str, prefix: str, env: 'Environment', *,
extra_args: T.Optional[T.List[str]] = None, extra_args: T.Optional[T.List[str]] = None,
@ -128,12 +127,12 @@ class FortranCompiler(CLikeCompiler, Compiler):
class GnuFortranCompiler(GnuCompiler, FortranCompiler): class GnuFortranCompiler(GnuCompiler, FortranCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
GnuCompiler.__init__(self, defines) GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall'] default_warn_args = ['-Wall']
@ -197,12 +196,12 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
class ElbrusFortranCompiler(ElbrusCompiler, FortranCompiler): class ElbrusFortranCompiler(ElbrusCompiler, FortranCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, FortranCompiler.__init__(self, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ElbrusCompiler.__init__(self) ElbrusCompiler.__init__(self)
def get_options(self) -> 'MutableKeyedOptionDictType': def get_options(self) -> 'MutableKeyedOptionDictType':
@ -222,11 +221,11 @@ class G95FortranCompiler(FortranCompiler):
id = 'g95' id = 'g95'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
default_warn_args = ['-Wall'] default_warn_args = ['-Wall']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -269,11 +268,11 @@ class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):
id = 'intel' id = 'intel'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
# FIXME: Add support for OS X and Windows in detect_fortran_compiler so # FIXME: Add support for OS X and Windows in detect_fortran_compiler so
# we are sent the type of compiler # we are sent the type of compiler
@ -323,11 +322,10 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', target: str, is_cross: bool, info: 'MachineInfo', target: str,
exe_wrapper: T.Optional['ExternalProgram'] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target) IntelVisualStudioLikeCompiler.__init__(self, target)
@ -366,11 +364,11 @@ class PathScaleFortranCompiler(FortranCompiler):
id = 'pathscale' id = 'pathscale'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
default_warn_args = ['-fullwarn'] default_warn_args = ['-fullwarn']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -386,11 +384,11 @@ class PathScaleFortranCompiler(FortranCompiler):
class PGIFortranCompiler(PGICompiler, FortranCompiler): class PGIFortranCompiler(PGICompiler, FortranCompiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
@ -412,11 +410,11 @@ class NvidiaHPC_FortranCompiler(PGICompiler, FortranCompiler):
id = 'nvidia_hpc' id = 'nvidia_hpc'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
PGICompiler.__init__(self) PGICompiler.__init__(self)
@ -433,11 +431,11 @@ class FlangFortranCompiler(ClangCompiler, FortranCompiler):
id = 'flang' id = 'flang'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
ClangCompiler.__init__(self, {}) ClangCompiler.__init__(self, {})
default_warn_args = ['-Minform=inform'] default_warn_args = ['-Minform=inform']
@ -467,11 +465,11 @@ class Open64FortranCompiler(FortranCompiler):
id = 'open64' id = 'open64'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
default_warn_args = ['-fullwarn'] default_warn_args = ['-fullwarn']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -489,11 +487,11 @@ class NAGFortranCompiler(FortranCompiler):
id = 'nagfor' id = 'nagfor'
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
info: 'MachineInfo', exe_wrapper: T.Optional['ExternalProgram'] = None, info: 'MachineInfo',
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
FortranCompiler.__init__(self, exelist, version, for_machine, FortranCompiler.__init__(self, exelist, version, for_machine,
is_cross, info, exe_wrapper, linker=linker, is_cross, info, linker=linker,
full_version=full_version) full_version=full_version)
# Warnings are on by default; -w disables (by category): # Warnings are on by default; -w disables (by category):
self.warn_args = { self.warn_args = {

@ -36,7 +36,6 @@ if T.TYPE_CHECKING:
from ..._typing import ImmutableListProtocol from ..._typing import ImmutableListProtocol
from ...environment import Environment from ...environment import Environment
from ...compilers.compilers import Compiler from ...compilers.compilers import Compiler
from ...programs import ExternalProgram
else: else:
# This is a bit clever, for mypy we pretend that these mixins descend from # This is a bit clever, for mypy we pretend that these mixins descend from
# Compiler, so we get all of the methods and attributes defined for us, but # Compiler, so we get all of the methods and attributes defined for us, but
@ -133,15 +132,9 @@ class CLikeCompiler(Compiler):
find_framework_cache: T.Dict[T.Tuple[T.Tuple[str, ...], str, T.Tuple[str, ...], bool], T.Optional[T.List[str]]] = {} find_framework_cache: 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, exe_wrapper: T.Optional['ExternalProgram'] = None): def __init__(self) -> 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.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
# sanity check is skipped and compiler checks use fallbacks.
if not exe_wrapper or not exe_wrapper.found() or not exe_wrapper.get_command():
self.exe_wrapper = None
else:
self.exe_wrapper = exe_wrapper
# Lazy initialized in get_preprocessor() # Lazy initialized in get_preprocessor()
self.preprocessor: T.Optional[Compiler] = None self.preprocessor: T.Optional[Compiler] = None
@ -285,7 +278,7 @@ class CLikeCompiler(Compiler):
mode = CompileCheckMode.LINK mode = CompileCheckMode.LINK
if self.is_cross: if self.is_cross:
binname += '_cross' binname += '_cross'
if self.exe_wrapper is None: if environment.need_exe_wrapper(self.for_machine) and not environment.has_exe_wrapper():
# Linking cross built C/C++ apps is painful. You can't really # Linking cross built C/C++ apps is painful. You can't really
# tell if you should use -nostdlib or not and for example # tell if you should use -nostdlib or not and for example
# on OSX the compiler binary is the same but you need # on OSX the compiler binary is the same but you need
@ -315,11 +308,11 @@ class CLikeCompiler(Compiler):
if pc.returncode != 0: if pc.returncode != 0:
raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.') raise mesonlib.EnvironmentException(f'Compiler {self.name_string()} cannot compile programs.')
# Run sanity check # Run sanity check
if self.is_cross: if environment.need_exe_wrapper(self.for_machine):
if self.exe_wrapper is None: if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do # Can't check if the binaries run so we have to assume they do
return return
cmdlist = self.exe_wrapper.get_command() + [binary_name] cmdlist = environment.exe_wrapper.get_command() + [binary_name]
else: else:
cmdlist = [binary_name] cmdlist = [binary_name]
mlog.debug('Running test binary command: ', mesonlib.join_args(cmdlist)) mlog.debug('Running test binary command: ', mesonlib.join_args(cmdlist))

@ -14,7 +14,6 @@ from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_a
from .mixins.clang import ClangCompiler from .mixins.clang import ClangCompiler
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..programs import ExternalProgram
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
@ -27,13 +26,12 @@ class ObjCCompiler(CLikeCompiler, Compiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrap: T.Optional['ExternalProgram'],
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
Compiler.__init__(self, ccache, exelist, version, for_machine, info, Compiler.__init__(self, ccache, exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, is_cross=is_cross, full_version=full_version,
linker=linker) linker=linker)
CLikeCompiler.__init__(self, exe_wrap) CLikeCompiler.__init__(self)
@staticmethod @staticmethod
def get_display_language() -> str: def get_display_language() -> str:
@ -47,12 +45,11 @@ class ObjCCompiler(CLikeCompiler, Compiler):
class GnuObjCCompiler(GnuCompiler, ObjCCompiler): class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
ObjCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ObjCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines) GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -67,12 +64,11 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
class ClangObjCCompiler(ClangCompiler, ObjCCompiler): class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
ObjCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ObjCCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines) ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],

@ -14,7 +14,6 @@ from .mixins.gnu import GnuCompiler, gnu_common_warning_args, gnu_objc_warning_a
from .mixins.clang import ClangCompiler from .mixins.clang import ClangCompiler
if T.TYPE_CHECKING: if T.TYPE_CHECKING:
from ..programs import ExternalProgram
from ..envconfig import MachineInfo from ..envconfig import MachineInfo
from ..environment import Environment from ..environment import Environment
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
@ -26,13 +25,12 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrap: T.Optional['ExternalProgram'],
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
Compiler.__init__(self, ccache, exelist, version, for_machine, info, Compiler.__init__(self, ccache, exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, is_cross=is_cross, full_version=full_version,
linker=linker) linker=linker)
CLikeCompiler.__init__(self, exe_wrap) CLikeCompiler.__init__(self)
@staticmethod @staticmethod
def get_display_language() -> str: def get_display_language() -> str:
@ -46,12 +44,11 @@ class ObjCPPCompiler(CLikeCompiler, Compiler):
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
GnuCompiler.__init__(self, defines) GnuCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],
@ -67,12 +64,11 @@ class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
defines: T.Optional[T.Dict[str, str]] = None, defines: T.Optional[T.Dict[str, str]] = None,
linker: T.Optional['DynamicLinker'] = None, linker: T.Optional['DynamicLinker'] = None,
full_version: T.Optional[str] = None): full_version: T.Optional[str] = None):
ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross, ObjCPPCompiler.__init__(self, ccache, exelist, version, for_machine, is_cross,
info, exe_wrapper, linker=linker, full_version=full_version) info, linker=linker, full_version=full_version)
ClangCompiler.__init__(self, defines) ClangCompiler.__init__(self, defines)
default_warn_args = ['-Wall', '-Winvalid-pch'] default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'0': [], self.warn_args = {'0': [],

@ -19,7 +19,6 @@ if T.TYPE_CHECKING:
from ..environment import Environment # noqa: F401 from ..environment import Environment # noqa: F401
from ..linkers.linkers import DynamicLinker from ..linkers.linkers import DynamicLinker
from ..mesonlib import MachineChoice from ..mesonlib import MachineChoice
from ..programs import ExternalProgram
from ..dependencies import Dependency from ..dependencies import Dependency
@ -59,13 +58,11 @@ class RustCompiler(Compiler):
def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
is_cross: bool, info: 'MachineInfo', is_cross: bool, info: 'MachineInfo',
exe_wrapper: T.Optional['ExternalProgram'] = None,
full_version: T.Optional[str] = None, full_version: T.Optional[str] = None,
linker: T.Optional['DynamicLinker'] = None): linker: T.Optional['DynamicLinker'] = None):
super().__init__([], exelist, version, for_machine, info, super().__init__([], exelist, version, for_machine, info,
is_cross=is_cross, full_version=full_version, is_cross=is_cross, full_version=full_version,
linker=linker) linker=linker)
self.exe_wrapper = exe_wrapper
self.base_options.update({OptionKey(o) for o in ['b_colorout', 'b_ndebug']}) self.base_options.update({OptionKey(o) for o in ['b_colorout', 'b_ndebug']})
if 'link' in self.linker.id: if 'link' in self.linker.id:
self.base_options.add(OptionKey('b_vscrt')) self.base_options.add(OptionKey('b_vscrt'))
@ -87,11 +84,11 @@ class RustCompiler(Compiler):
pc, stdo, stde = Popen_safe_logged(cmdlist, cwd=work_dir) pc, stdo, stde = Popen_safe_logged(cmdlist, cwd=work_dir)
if pc.returncode != 0: if pc.returncode != 0:
raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.') raise EnvironmentException(f'Rust compiler {self.name_string()} cannot compile programs.')
if self.is_cross: if environment.need_exe_wrapper(self.for_machine):
if self.exe_wrapper is None: if not environment.has_exe_wrapper():
# Can't check if the binaries run so we have to assume they do # Can't check if the binaries run so we have to assume they do
return return
cmdlist = self.exe_wrapper.get_command() + [output_name] cmdlist = environment.exe_wrapper.get_command() + [output_name]
else: else:
cmdlist = [output_name] cmdlist = [output_name]
pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) pe = subprocess.Popen(cmdlist, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)

@ -957,3 +957,6 @@ class Environment:
if not self.need_exe_wrapper(): if not self.need_exe_wrapper():
return None return None
return self.exe_wrapper return self.exe_wrapper
def has_exe_wrapper(self) -> bool:
return self.exe_wrapper and self.exe_wrapper.found()

Loading…
Cancel
Save