From ff4a17dbef08a1d8afd075f57dbab0f5c76951ab Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 21 Aug 2019 13:21:49 -0700 Subject: compilers: Add a specific type for AppleClangC This allows us to detect use classes rather than methods to determine what C standards are available. --- mesonbuild/compilers/__init__.py | 4 ++++ mesonbuild/compilers/c.py | 22 ++++++++++++++++++---- mesonbuild/compilers/cpp.py | 5 +++++ 3 files changed, 27 insertions(+), 4 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index c81fe75..c0ad9f6 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -34,6 +34,8 @@ __all__ = [ 'lang_suffixes', 'sort_clink', + 'AppleClangCCompiler', + 'AppleClangCPPCompiler', 'ArmCCompiler', 'ArmCPPCompiler', 'ArmclangCCompiler', @@ -119,6 +121,7 @@ from .compilers import ( ) from .c import ( CCompiler, + AppleClangCCompiler, ArmCCompiler, ArmclangCCompiler, ClangCCompiler, @@ -134,6 +137,7 @@ from .c import ( ) from .cpp import ( CPPCompiler, + AppleClangCPPCompiler, ArmCPPCompiler, ArmclangCPPCompiler, ClangCPPCompiler, diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 1ec9146..7b5d3cc 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -75,6 +75,10 @@ class CCompiler(CLikeCompiler, Compiler): class ClangCCompiler(ClangCompiler, CCompiler): + + _C17_VERSION = '>=10.0.0' + _C18_VERSION = '>=11.0.0' + def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) ClangCompiler.__init__(self, compiler_type) @@ -90,12 +94,10 @@ class ClangCCompiler(ClangCompiler, CCompiler): g_stds = ['gnu89', 'gnu99', 'gnu11'] # https://releases.llvm.org/6.0.0/tools/clang/docs/ReleaseNotes.html # https://en.wikipedia.org/wiki/Xcode#Latest_versions - v = '>=10.0.0' if self.compiler_type is CompilerType.CLANG_OSX else '>=6.0.0' - if version_compare(self.version, v): + if version_compare(self.version, self._C17_VERSION): c_stds += ['c17'] g_stds += ['gnu17'] - v = '>=11.0.0' if self.compiler_type is CompilerType.CLANG_OSX else '>=8.0.0' - if version_compare(self.version, v): + if version_compare(self.version, self._C18_VERSION): c_stds += ['c18'] g_stds += ['gnu18'] opts.update({'c_std': coredata.UserComboOption('C language standard to use', @@ -114,6 +116,18 @@ class ClangCCompiler(ClangCompiler, CCompiler): return [] +class AppleClangCCompiler(ClangCCompiler): + + """Handle the differences between Apple Clang and Vanilla Clang. + + Right now this just handles the differences between the versions that new + C standards were added. + """ + + _C17_VERSION = '>=6.0.0' + _C18_VERSION = '>=8.0.0' + + class EmscriptenCCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, ClangCCompiler): def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): if not is_cross: diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index f93db3e..922a780 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -184,6 +184,11 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler): return ['-lstdc++'] +class AppleClangCPPCompiler(ClangCPPCompiler): + + pass + + class EmscriptenCPPCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, ClangCPPCompiler): def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): if not is_cross: -- cgit v1.1 From 0c22798b1ad4678abb205280060175678a790c4a Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 21 Aug 2019 13:12:30 -0700 Subject: compilers: replace CompilerType with MachineInfo Now that the linkers are split out of the compilers this enum is only used to know what platform we're compiling for. Which is what the MachineInfo class is for --- mesonbuild/compilers/__init__.py | 2 - mesonbuild/compilers/c.py | 106 ++++++++++++++++++++++------------ mesonbuild/compilers/compilers.py | 49 ++-------------- mesonbuild/compilers/cpp.py | 96 +++++++++++++++++++----------- mesonbuild/compilers/cs.py | 22 ++++--- mesonbuild/compilers/cuda.py | 6 +- mesonbuild/compilers/d.py | 26 ++++++--- mesonbuild/compilers/fortran.py | 95 ++++++++++++++++++++---------- mesonbuild/compilers/java.py | 14 +++-- mesonbuild/compilers/mixins/arm.py | 7 +-- mesonbuild/compilers/mixins/ccrx.py | 4 +- mesonbuild/compilers/mixins/clang.py | 17 +++--- mesonbuild/compilers/mixins/elbrus.py | 5 +- mesonbuild/compilers/mixins/gnu.py | 18 +++--- mesonbuild/compilers/mixins/intel.py | 6 +- mesonbuild/compilers/mixins/pgi.py | 8 +-- mesonbuild/compilers/objc.py | 28 ++++++--- mesonbuild/compilers/objcpp.py | 25 +++++--- mesonbuild/compilers/rust.py | 9 ++- mesonbuild/compilers/swift.py | 9 ++- mesonbuild/compilers/vala.py | 9 ++- 21 files changed, 330 insertions(+), 231 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py index c0ad9f6..aebfb32 100644 --- a/mesonbuild/compilers/__init__.py +++ b/mesonbuild/compilers/__init__.py @@ -14,7 +14,6 @@ # Public symbols for compilers sub-package when using 'from . import compilers' __all__ = [ - 'CompilerType', 'Compiler', 'all_languages', @@ -99,7 +98,6 @@ __all__ = [ # Bring symbols from each module into compilers sub-package namespace from .compilers import ( - CompilerType, Compiler, all_languages, base_options, diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index 7b5d3cc..1bf03bd 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -32,9 +32,11 @@ from .compilers import ( gnu_winlibs, msvc_winlibs, Compiler, - CompilerType, ) +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + class CCompiler(CLikeCompiler, Compiler): @@ -46,10 +48,10 @@ class CCompiler(CLikeCompiler, Compiler): raise MesonException('Unknown function attribute "{}"'.format(name)) def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, - exe_wrapper: typing.Optional[str] = None, **kwargs): + info: 'MachineInfo', exe_wrapper: typing.Optional[str] = None, **kwargs): # If a child ObjC or CPP class has already set it, don't set it ourselves self.language = 'c' - Compiler.__init__(self, exelist, version, for_machine, **kwargs) + Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrapper) def get_no_stdinc_args(self): @@ -79,9 +81,10 @@ class ClangCCompiler(ClangCompiler, CCompiler): _C17_VERSION = '>=10.0.0' _C18_VERSION = '>=11.0.0' - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ClangCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs) + ClangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, @@ -119,7 +122,7 @@ class ClangCCompiler(ClangCompiler, CCompiler): class AppleClangCCompiler(ClangCCompiler): """Handle the differences between Apple Clang and Vanilla Clang. - + Right now this just handles the differences between the versions that new C standards were added. """ @@ -129,10 +132,12 @@ class AppleClangCCompiler(ClangCCompiler): class EmscriptenCCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, ClangCCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', is_cross, exe_wrapper=None, **kwargs): if not is_cross: raise MesonException('Emscripten compiler can only be used for cross compilation.') - ClangCCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, **kwargs) + ClangCCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, **kwargs) self.id = 'emscripten' def get_option_link_args(self, options): @@ -142,9 +147,11 @@ class EmscriptenCCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, ClangC raise MesonException('Emscripten does not support shared libraries.') class ArmclangCCompiler(ArmclangCompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ArmclangCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', is_cross, exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + ArmclangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, @@ -171,9 +178,12 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler): class GnuCCompiler(GnuCompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + GnuCompiler.__init__(self, defines) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, @@ -191,7 +201,7 @@ class GnuCCompiler(GnuCompiler, CCompiler): opts.update({'c_std': coredata.UserComboOption('C language standard to use', ['none'] + c_stds + g_stds, 'none')}) - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): opts.update({ 'c_winlibs': coredata.UserArrayOption('Standard Win libraries to link against', gnu_winlibs), }) @@ -205,7 +215,7 @@ class GnuCCompiler(GnuCompiler, CCompiler): return args def get_option_link_args(self, options): - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): return options['c_winlibs'].value[:] return [] @@ -214,15 +224,19 @@ class GnuCCompiler(GnuCompiler, CCompiler): class PGICCompiler(PGICompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - PGICompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + PGICompiler.__init__(self) class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - GnuCCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs) - ElbrusCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, defines=None, **kwargs): + GnuCCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, defines, **kwargs) + ElbrusCompiler.__init__(self, defines) # It does support some various ISO standards and c/gnu 90, 9x, 1x in addition to those which GNU CC supports. def get_options(self): @@ -246,9 +260,11 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler): class IntelCCompiler(IntelGnuLikeCompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - IntelGnuLikeCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + IntelGnuLikeCompiler.__init__(self) self.lang_header = 'c-header' default_warn_args = ['-Wall', '-w3', '-diag-disable:remark'] self.warn_args = {'0': [], @@ -288,16 +304,23 @@ class VisualStudioLikeCCompilerMixin: def get_option_link_args(self, options): return options['c_winlibs'].value[:] + class VisualStudioCCompiler(VisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target: str, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, target: str, + **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) VisualStudioLikeCompiler.__init__(self, target) self.id = 'msvc' + class ClangClCCompiler(VisualStudioLikeCompiler, VisualStudioLikeCCompilerMixin, CCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) VisualStudioLikeCompiler.__init__(self, target) self.id = 'clang-cl' @@ -308,8 +331,10 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM __have_warned = False - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) IntelVisualStudioLikeCompiler.__init__(self, target) def get_options(self): @@ -333,9 +358,11 @@ class IntelClCCompiler(IntelVisualStudioLikeCompiler, VisualStudioLikeCCompilerM class ArmCCompiler(ArmCompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ArmCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + ArmCompiler.__init__(self) def get_options(self): opts = CCompiler.get_options(self) @@ -351,10 +378,13 @@ class ArmCCompiler(ArmCompiler, CCompiler): args.append('--' + std.value) return args + class CcrxCCompiler(CcrxCompiler, CCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - CcrxCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + CcrxCompiler.__init__(self) # Override CCompiler.get_always_args def get_always_args(self): diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py index ac74fc3..8456a99 100644 --- a/mesonbuild/compilers/compilers.py +++ b/mesonbuild/compilers/compilers.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import contextlib, enum, os.path, re, tempfile +import contextlib, os.path, re, tempfile import typing from typing import Optional, Tuple, List @@ -30,6 +30,7 @@ from ..envconfig import ( if typing.TYPE_CHECKING: from ..coredata import OptionDictType + from ..envconfig import MachineInfo from ..environment import Environment from ..linkers import DynamicLinker # noqa: F401 @@ -668,7 +669,7 @@ class Compiler: LINKER_PREFIX = None # type: typing.Union[None, str, typing.List[str]] - def __init__(self, exelist, version, for_machine: MachineChoice, + def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo', linker: typing.Optional['DynamicLinker'] = None, **kwargs): if isinstance(exelist, str): self.exelist = [exelist] @@ -690,6 +691,7 @@ class Compiler: self.for_machine = for_machine self.base_options = [] self.linker = linker + self.info = info def __repr__(self): repr_str = "<{0}: v{1} `{2}`>" @@ -1175,52 +1177,11 @@ class Compiler: return dep.get_link_args() -@enum.unique -class CompilerType(enum.Enum): - GCC_STANDARD = 0 - GCC_OSX = 1 - GCC_MINGW = 2 - GCC_CYGWIN = 3 - - CLANG_STANDARD = 10 - CLANG_OSX = 11 - CLANG_MINGW = 12 - CLANG_EMSCRIPTEN = 13 - # Possibly clang-cl? - - ICC_STANDARD = 20 - ICC_OSX = 21 - ICC_WIN = 22 - - ARM_WIN = 30 - - CCRX_WIN = 40 - - PGI_STANDARD = 50 - PGI_OSX = 51 - PGI_WIN = 52 - - @property - def is_standard_compiler(self): - return self.name in ('GCC_STANDARD', 'CLANG_STANDARD', 'ICC_STANDARD', 'PGI_STANDARD') - - @property - def is_osx_compiler(self): - return self.name in ('GCC_OSX', 'CLANG_OSX', 'ICC_OSX', 'PGI_OSX') - - @property - def is_windows_compiler(self): - return self.name in ('GCC_MINGW', 'GCC_CYGWIN', 'CLANG_MINGW', 'ICC_WIN', 'ARM_WIN', 'CCRX_WIN', 'PGI_WIN') - -def get_compiler_is_linuxlike(compiler): - compiler_type = getattr(compiler, 'compiler_type', None) - return compiler_type and compiler_type.is_standard_compiler - def get_largefile_args(compiler): ''' Enable transparent large-file-support for 32-bit UNIX systems ''' - if get_compiler_is_linuxlike(compiler): + if not (compiler.info.is_windows() or compiler.info.is_darwin()): # Enable large-file support unconditionally on all platforms other # than macOS and Windows. macOS is now 64-bit-only so it doesn't # need anything special, and Windows doesn't have automatic LFS. diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 922a780..2b3b162 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -38,6 +38,9 @@ from .mixins.elbrus import ElbrusCompiler from .mixins.pgi import PGICompiler from .mixins.islinker import BasicLinkerIsCompilerMixin, LinkerEnvVarsMixin +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + def non_msvc_eh_options(eh, args): if eh == 'none': @@ -56,10 +59,10 @@ class CPPCompiler(CLikeCompiler, Compiler): raise MesonException('Unknown function attribute "{}"'.format(name)) def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, - exe_wrap: typing.Optional[str] = None, **kwargs): + info: 'MachineInfo', exe_wrap: typing.Optional[str] = None, **kwargs): # If a child ObjCPP class has already set it, don't set it ourselves self.language = 'cpp' - Compiler.__init__(self, exelist, version, for_machine, **kwargs) + Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) def get_display_language(self): @@ -147,9 +150,11 @@ class CPPCompiler(CLikeCompiler, Compiler): class ClangCPPCompiler(ClangCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ClangCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + ClangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] self.warn_args = {'0': [], '1': default_warn_args, @@ -190,10 +195,12 @@ class AppleClangCPPCompiler(ClangCPPCompiler): class EmscriptenCPPCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, ClangCPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): if not is_cross: raise MesonException('Emscripten compiler can only be used for cross compilation.') - ClangCPPCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, **kwargs) + ClangCPPCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, **kwargs) self.id = 'emscripten' def get_option_compile_args(self, options): @@ -211,9 +218,10 @@ class EmscriptenCPPCompiler(LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, Clan class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ArmclangCompiler.__init__(self, compiler_type) + ArmclangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] self.warn_args = {'0': [], '1': default_warn_args, @@ -246,9 +254,10 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): class GnuCPPCompiler(GnuCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap, defines, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, defines, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrap, **kwargs) + GnuCompiler.__init__(self, defines) default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] self.warn_args = {'0': [], '1': default_warn_args, @@ -266,7 +275,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler): 'none'), 'cpp_debugstl': coredata.UserBooleanOption('STL debug mode', False)}) - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): opts.update({ 'cpp_winlibs': coredata.UserArrayOption('Standard Win libraries to link against', gnu_winlibs), }) @@ -285,7 +294,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler): return args def get_option_link_args(self, options): - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): return options['cpp_winlibs'].value[:] return [] @@ -297,14 +306,20 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler): class PGICPPCompiler(PGICompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - PGICompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs) + PGICompiler.__init__(self) + class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - GnuCPPCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs) - ElbrusCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + GnuCPPCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, defines, + **kwargs) + ElbrusCompiler.__init__(self, defines) # It does not support c++/gnu++ 17 and 1z, but still does support 0x, 1y, and gnu++98. def get_options(self): @@ -332,9 +347,11 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler): class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) - IntelGnuLikeCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) + IntelGnuLikeCompiler.__init__(self) self.lang_header = 'c++-header' default_warn_args = ['-Wall', '-w3', '-diag-disable:remark', '-Wpch-messages', '-Wnon-virtual-dtor'] @@ -467,8 +484,9 @@ class CPP11AsCPP14Mixin: class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, VisualStudioLikeCompiler, CPPCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap, target, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross: bool, info: 'MachineInfo', exe_wrap, target, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrap, **kwargs) VisualStudioLikeCompiler.__init__(self, target) self.base_options = ['b_pch', 'b_vscrt'] # FIXME add lto, pgo and the like self.id = 'msvc' @@ -500,8 +518,10 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi return args class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, VisualStudioLikeCompiler, CPPCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) VisualStudioLikeCompiler.__init__(self, target) self.id = 'clang-cl' @@ -512,8 +532,10 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Vi class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLikeCompiler, CPPCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrap, target, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap, target, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) IntelVisualStudioLikeCompiler.__init__(self, target) def get_options(self): @@ -523,9 +545,11 @@ class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLike class ArmCPPCompiler(ArmCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap=None, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) - ArmCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) + ArmCompiler.__init__(self) def get_options(self): opts = CPPCompiler.get_options(self) @@ -551,9 +575,11 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler): class CcrxCPPCompiler(CcrxCompiler, CPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrap=None, **kwargs): - CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrap, **kwargs) - CcrxCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrap=None, **kwargs): + CPPCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrap, **kwargs) + CcrxCompiler.__init__(self) # Override CCompiler.get_always_args def get_always_args(self): diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index 7c884c9..1dea33a 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -13,6 +13,7 @@ # limitations under the License. import os.path, subprocess +import typing from ..mesonlib import EnvironmentException from ..mesonlib import is_windows @@ -20,6 +21,9 @@ from ..mesonlib import is_windows from .compilers import Compiler, MachineChoice, mono_buildtype_args from .mixins.islinker import BasicLinkerIsCompilerMixin +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + cs_optimization_args = {'0': [], 'g': [], '1': ['-optimize+'], @@ -28,10 +32,12 @@ cs_optimization_args = {'0': [], 's': ['-optimize+'], } + class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, comp_id, runner=None): + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', comp_id, runner=None): self.language = 'cs' - super().__init__(exelist, version, for_machine) + super().__init__(exelist, version, for_machine, info) self.id = comp_id self.is_cross = False self.runner = runner @@ -133,14 +139,16 @@ class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): class MonoCompiler(CsCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice): - super().__init__(exelist, version, for_machine, 'mono', - 'mono') + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo'): + super().__init__(exelist, version, for_machine, info, 'mono', + runner='mono') class VisualStudioCsCompiler(CsCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice): - super().__init__(exelist, version, for_machine, 'csc') + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo'): + super().__init__(exelist, version, for_machine, info, 'csc') def get_buildtype_args(self, buildtype): res = mono_buildtype_args[buildtype] diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index f6f78f1..a484e7f 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -24,6 +24,7 @@ from .compilers import (Compiler, cuda_buildtype_args, cuda_optimization_args, if typing.TYPE_CHECKING: from ..environment import Environment # noqa: F401 + from ..envconfig import MachineInfo class CudaCompiler(Compiler): @@ -32,10 +33,11 @@ class CudaCompiler(Compiler): _universal_flags = {'compiler': ['-I', '-D', '-U', '-E'], 'linker': ['-l', '-L']} - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper, host_compiler, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, exe_wrapper, host_compiler, info: 'MachineInfo', **kwargs): if not hasattr(self, 'language'): self.language = 'cuda' - super().__init__(exelist, version, for_machine, **kwargs) + super().__init__(exelist, version, for_machine, info, **kwargs) self.is_cross = is_cross self.exe_wrapper = exe_wrapper self.host_compiler = host_compiler diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 346f18e..28a4fad 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -20,7 +20,6 @@ from ..mesonlib import ( ) from .compilers import ( - CompilerType, d_dmd_buildtype_args, d_gdc_buildtype_args, d_ldc_buildtype_args, @@ -31,6 +30,9 @@ from .compilers import ( from .mixins.gnu import GnuCompiler from .mixins.islinker import LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + d_feature_args = {'gcc': {'unittest': '-funittest', 'debug': '-fdebug', 'version': '-fversion', @@ -402,9 +404,10 @@ class DCompiler(Compiler): 'mtd': ['-mscrtlib=libcmtd'], } - def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', arch, **kwargs): self.language = 'd' - super().__init__(exelist, version, for_machine, **kwargs) + super().__init__(exelist, version, for_machine, info, **kwargs) self.id = 'unknown' self.arch = arch @@ -590,8 +593,9 @@ class GnuDCompiler(DCompiler, GnuCompiler): # we mostly want DCompiler, but that gives us the Compiler.LINKER_PREFIX instead LINKER_PREFIX = GnuCompiler.LINKER_PREFIX - def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs): - DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', arch, **kwargs): + DCompiler.__init__(self, exelist, version, for_machine, info, arch, **kwargs) self.id = 'gcc' default_warn_args = ['-Wall', '-Wdeprecated'] self.warn_args = {'0': [], @@ -633,8 +637,10 @@ class GnuDCompiler(DCompiler, GnuCompiler): class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, DCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs): - DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs) + + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', arch, **kwargs): + DCompiler.__init__(self, exelist, version, for_machine, info, arch, **kwargs) self.id = 'llvm' self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt'] @@ -671,8 +677,10 @@ class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompi class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompilerMixin, DCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, arch, **kwargs): - DCompiler.__init__(self, exelist, version, for_machine, arch, **kwargs) + + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo', arch, **kwargs): + DCompiler.__init__(self, exelist, version, for_machine, info, arch, **kwargs) self.id = 'dmd' self.base_options = ['b_coverage', 'b_colorout', 'b_vscrt'] diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index fd7b91a..093bbc9 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -18,7 +18,6 @@ import subprocess, os import typing from .compilers import ( - CompilerType, clike_debug_args, Compiler, ) @@ -36,12 +35,16 @@ from mesonbuild.mesonlib import ( EnvironmentException, MachineChoice, is_osx, LibType ) +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + class FortranCompiler(CLikeCompiler, Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): self.language = 'fortran' - Compiler.__init__(self, exelist, version, for_machine, **kwargs) + Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrapper) self.id = 'unknown' @@ -158,9 +161,12 @@ class FortranCompiler(CLikeCompiler, Compiler): class GnuFortranCompiler(GnuCompiler, FortranCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + FortranCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, **kwargs) + GnuCompiler.__init__(self, defines) default_warn_args = ['-Wall'] self.warn_args = {'0': [], '1': default_warn_args, @@ -180,16 +186,22 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler): return ['-lgfortran', '-lm'] class ElbrusFortranCompiler(GnuFortranCompiler, ElbrusCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - GnuFortranCompiler.__init__(self, exelist, version, compiler_type, for_machine, is_cross, exe_wrapper, defines, **kwargs) - ElbrusCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + GnuFortranCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, defines, + **kwargs) + ElbrusCompiler.__init__(self, defines) class G95FortranCompiler(FortranCompiler): LINKER_PREFIX = '-Wl,' - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): + FortranCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, **kwargs) self.id = 'g95' default_warn_args = ['-Wall'] self.warn_args = {'0': [], @@ -209,8 +221,10 @@ class SunFortranCompiler(FortranCompiler): LINKER_PREFIX = '-Wl,' - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs) self.id = 'sun' def get_dependency_gen_args(self, outtarget, outfile): @@ -233,12 +247,15 @@ class SunFortranCompiler(FortranCompiler): class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp') - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + FortranCompiler.__init__(self, exelist, version, for_machine, + is_cross, info, exe_wrapper, **kwargs) # FIXME: Add support for OS X and Windows in detect_fortran_compiler so # we are sent the type of compiler - IntelGnuLikeCompiler.__init__(self, CompilerType.ICC_STANDARD) + IntelGnuLikeCompiler.__init__(self) self.id = 'intel' default_warn_args = ['-warn', 'general', '-warn', 'truncated_source'] self.warn_args = {'0': [], @@ -276,8 +293,11 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler): 'custom': [], } - def __init__(self, exelist, for_machine: MachineChoice, version, is_cross, target: str, exe_wrapper=None, **kwargs): - FortranCompiler.__init__(self, exelist, for_machine, version, is_cross, exe_wrapper, **kwargs) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, target: str, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) IntelVisualStudioLikeCompiler.__init__(self, target) default_warn_args = ['/warn:general', '/warn:truncated_source'] @@ -294,8 +314,11 @@ class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler): class PathScaleFortranCompiler(FortranCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) self.id = 'pathscale' default_warn_args = ['-fullwarn'] self.warn_args = {'0': [], @@ -308,18 +331,24 @@ class PathScaleFortranCompiler(FortranCompiler): class PGIFortranCompiler(PGICompiler, FortranCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) - PGICompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) + PGICompiler.__init__(self) def language_stdlib_only_link_flags(self) -> List[str]: return ['-lpgf90rtl', '-lpgf90', '-lpgf90_rpm1', '-lpgf902', '-lpgf90rtl', '-lpgftnrtl', '-lrt'] class FlangFortranCompiler(ClangCompiler, FortranCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) - ClangCompiler.__init__(self, CompilerType.CLANG_STANDARD) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) + ClangCompiler.__init__(self) self.id = 'flang' default_warn_args = ['-Minform=inform'] self.warn_args = {'0': [], @@ -331,8 +360,11 @@ class FlangFortranCompiler(ClangCompiler, FortranCompiler): return ['-lflang', '-lpgmath'] class Open64FortranCompiler(FortranCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) self.id = 'open64' default_warn_args = ['-fullwarn'] self.warn_args = {'0': [], @@ -345,8 +377,11 @@ class Open64FortranCompiler(FortranCompiler): class NAGFortranCompiler(FortranCompiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwags): - FortranCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwags) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + FortranCompiler.__init__(self, exelist, for_machine, version, + is_cross, info, exe_wrapper, **kwargs) self.id = 'nagfor' def get_warn_args(self, level): diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index fb1a190..cc195ff 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -12,17 +12,23 @@ # See the License for the specific language governing permissions and # limitations under the License. -import os.path, shutil, subprocess +import os.path +import shutil +import subprocess +import typing from ..mesonlib import EnvironmentException, MachineChoice - from .compilers import Compiler, java_buildtype_args from .mixins.islinker import BasicLinkerIsCompilerMixin +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice): + def __init__(self, exelist, version, for_machine: MachineChoice, + info: 'MachineInfo'): self.language = 'java' - super().__init__(exelist, version, for_machine) + super().__init__(exelist, version, for_machine, info) self.id = 'unknown' self.is_cross = False self.javarunner = 'java' diff --git a/mesonbuild/compilers/mixins/arm.py b/mesonbuild/compilers/mixins/arm.py index fca3d66..62e6f48 100644 --- a/mesonbuild/compilers/mixins/arm.py +++ b/mesonbuild/compilers/mixins/arm.py @@ -23,7 +23,6 @@ from ..compilers import clike_debug_args from .clang import clang_color_args if typing.TYPE_CHECKING: - from ..compilers import CompilerType from ...environment import Environment arm_buildtype_args = { @@ -65,11 +64,10 @@ armclang_optimization_args = { class ArmCompiler: # Functionality that is common to all ARM family compilers. - def __init__(self, compiler_type: 'CompilerType'): + def __init__(self): if not self.is_cross: raise mesonlib.EnvironmentException('armcc supports only cross-compilation.') self.id = 'arm' - self.compiler_type = compiler_type default_warn_args = [] # type: typing.List[str] self.warn_args = {'0': [], '1': default_warn_args, @@ -130,7 +128,7 @@ class ArmCompiler: class ArmclangCompiler: - def __init__(self, compiler_type: 'CompilerType'): + def __init__(self): if not self.is_cross: raise mesonlib.EnvironmentException('armclang supports only cross-compilation.') # Check whether 'armlink' is available in path @@ -157,7 +155,6 @@ class ArmclangCompiler: if not mesonlib.version_compare(self.version, '==' + linker_ver): raise mesonlib.EnvironmentException('armlink version does not match with compiler version') self.id = 'armclang' - self.compiler_type = compiler_type self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage', 'b_ndebug', 'b_staticpic', 'b_colorout'] # Assembly diff --git a/mesonbuild/compilers/mixins/ccrx.py b/mesonbuild/compilers/mixins/ccrx.py index 4de06fd..7fbc316 100644 --- a/mesonbuild/compilers/mixins/ccrx.py +++ b/mesonbuild/compilers/mixins/ccrx.py @@ -20,7 +20,6 @@ import typing from ...mesonlib import Popen_safe, EnvironmentException if typing.TYPE_CHECKING: - from ..compilers import CompilerType from ...environment import Environment ccrx_buildtype_args = { @@ -48,11 +47,10 @@ ccrx_debug_args = { class CcrxCompiler: - def __init__(self, compiler_type: 'CompilerType'): + def __init__(self): if not self.is_cross: raise EnvironmentException('ccrx supports only cross-compilation.') self.id = 'ccrx' - self.compiler_type = compiler_type # Assembly self.can_compile_suffixes.update('s') default_warn_args = [] # type: typing.List[str] diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index 06485ab..16f4659 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -17,12 +17,12 @@ import os import typing -from .gnu import GnuLikeCompiler -from ..compilers import clike_optimization_args from ... import mesonlib +from ...linkers import AppleDynamicLinker +from ..compilers import clike_optimization_args +from .gnu import GnuLikeCompiler if typing.TYPE_CHECKING: - from ..compilers import CompilerType from ...environment import Environment from ...dependencies import Dependency # noqa: F401 @@ -34,11 +34,13 @@ clang_color_args = { class ClangCompiler(GnuLikeCompiler): - def __init__(self, compiler_type: 'CompilerType'): - super().__init__(compiler_type) + def __init__(self): + super().__init__() self.id = 'clang' self.base_options.append('b_colorout') - if self.compiler_type.is_osx_compiler: + # TODO: this really should be part of the linker base_options, but + # linkers don't have base_options. + if isinstance(self.linker, AppleDynamicLinker): self.base_options.append('b_bitcode') # All Clang backends can also do LLVM IR self.can_compile_suffixes.add('ll') @@ -75,7 +77,8 @@ class ClangCompiler(GnuLikeCompiler): # visibility to obey OS X/iOS/tvOS minimum version targets with # -mmacosx-version-min, -miphoneos-version-min, -mtvos-version-min etc. # https://github.com/Homebrew/homebrew-core/issues/3727 - if self.compiler_type.is_osx_compiler and mesonlib.version_compare(self.version, '>=8.0'): + # TODO: this really should be communicated by the linker + if isinstance(self.linker, AppleDynamicLinker) and mesonlib.version_compare(self.version, '>=8.0'): extra_args.append('-Wl,-no_weak_imports') return super().has_function(funcname, prefix, env, extra_args=extra_args, dependencies=dependencies) diff --git a/mesonbuild/compilers/mixins/elbrus.py b/mesonbuild/compilers/mixins/elbrus.py index eb7414c..599d92a 100644 --- a/mesonbuild/compilers/mixins/elbrus.py +++ b/mesonbuild/compilers/mixins/elbrus.py @@ -21,15 +21,14 @@ from .gnu import GnuCompiler from ...mesonlib import Popen_safe if typing.TYPE_CHECKING: - from ..compilers import CompilerType from ...environment import Environment class ElbrusCompiler(GnuCompiler): # Elbrus compiler is nearly like GCC, but does not support # PCH, LTO, sanitizers and color output as of version 1.21.x. - def __init__(self, compiler_type: 'CompilerType', defines: typing.Dict[str, str]): - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, defines: typing.Dict[str, str]): + GnuCompiler.__init__(self, defines) self.id = 'lcc' self.base_options = ['b_pgo', 'b_coverage', 'b_ndebug', 'b_staticpic', diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py index f4ce5b9..e4ca14f 100644 --- a/mesonbuild/compilers/mixins/gnu.py +++ b/mesonbuild/compilers/mixins/gnu.py @@ -26,7 +26,6 @@ from ... import mesonlib from ... import mlog if typing.TYPE_CHECKING: - from ..compilers import CompilerType from ...coredata import UserOption # noqa: F401 from ...environment import Environment @@ -130,19 +129,18 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): LINKER_PREFIX = '-Wl,' - def __init__(self, compiler_type: 'CompilerType'): - self.compiler_type = compiler_type + def __init__(self): self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage', 'b_ndebug', 'b_staticpic', 'b_pie'] - if not (self.compiler_type.is_windows_compiler or mesonlib.is_openbsd()): + if not (self.info.is_windows() or self.info.is_cygwin() or self.info.is_openbsd()): self.base_options.append('b_lundef') - if not self.compiler_type.is_windows_compiler: + if not self.info.is_windows() or self.info.is_cygwin(): self.base_options.append('b_asneeded') # All GCC-like backends can do assembly self.can_compile_suffixes.add('s') def get_pic_args(self) -> typing.List[str]: - if self.compiler_type.is_osx_compiler or self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin() or self.info.is_darwin(): return [] # On Window and OS X, pic is always on. return ['-fPIC'] @@ -184,7 +182,7 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): raise RuntimeError('Module definitions file should be str') # On Windows targets, .def files may be specified on the linker command # line like an object file. - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): return [defsfile] # For other targets, discard the .def file. return [] @@ -199,7 +197,7 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta): return ['-fprofile-use', '-fprofile-correction'] def get_gui_app_args(self, value: bool) -> typing.List[str]: - if self.compiler_type.is_windows_compiler: + if self.info.is_windows() or self.info.is_cygwin(): return ['-mwindows' if value else '-mconsole'] return [] @@ -301,8 +299,8 @@ class GnuCompiler(GnuLikeCompiler): Compilers imitating GCC (Clang/Intel) should use the GnuLikeCompiler ABC. """ - def __init__(self, compiler_type: 'CompilerType', defines: typing.Dict[str, str]): - super().__init__(compiler_type) + def __init__(self, defines: typing.Dict[str, str]): + super().__init__() self.id = 'gcc' self.defines = defines or {} self.base_options.append('b_colorout') diff --git a/mesonbuild/compilers/mixins/intel.py b/mesonbuild/compilers/mixins/intel.py index d7e1b21..72c6fdf 100644 --- a/mesonbuild/compilers/mixins/intel.py +++ b/mesonbuild/compilers/mixins/intel.py @@ -22,7 +22,6 @@ import os import typing from ... import mesonlib -from ..compilers import CompilerType from .gnu import GnuLikeCompiler from .visualstudio import VisualStudioLikeCompiler @@ -44,8 +43,8 @@ clike_optimization_args = { # Tested on linux for ICC 14.0.3, 15.0.6, 16.0.4, 17.0.1, 19.0.0 class IntelGnuLikeCompiler(GnuLikeCompiler): - def __init__(self, compiler_type: 'CompilerType'): - super().__init__(compiler_type) + def __init__(self): + super().__init__() # As of 19.0.0 ICC doesn't have sanitizer, color, or lto support. # # It does have IPO, which serves much the same purpose as LOT, but @@ -104,7 +103,6 @@ class IntelVisualStudioLikeCompiler(VisualStudioLikeCompiler): def __init__(self, target: str): super().__init__(target) - self.compiler_type = CompilerType.ICC_WIN self.id = 'intel-cl' def compile(self, code, *, extra_args: typing.Optional[typing.List[str]] = None, **kwargs) -> typing.Iterator['subprocess.Popen']: diff --git a/mesonbuild/compilers/mixins/pgi.py b/mesonbuild/compilers/mixins/pgi.py index 38c7ffd..065c716 100644 --- a/mesonbuild/compilers/mixins/pgi.py +++ b/mesonbuild/compilers/mixins/pgi.py @@ -20,9 +20,6 @@ from pathlib import Path from ..compilers import clike_debug_args, clike_optimization_args -if typing.TYPE_CHECKING: - from ..compilers import CompilerType - pgi_buildtype_args = { 'plain': [], 'debug': [], @@ -34,10 +31,9 @@ pgi_buildtype_args = { class PGICompiler: - def __init__(self, compiler_type: 'CompilerType'): + def __init__(self): self.base_options = ['b_pch'] self.id = 'pgi' - self.compiler_type = compiler_type default_warn_args = ['-Minform=inform'] self.warn_args = {'0': [], @@ -56,7 +52,7 @@ class PGICompiler: def get_pic_args(self) -> typing.List[str]: # PGI -fPIC is Linux only. - if self.compiler_type.is_standard_compiler: + if self.info.is_linux(): return ['-fPIC'] return [] diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index 1004a72..58f3ec5 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -22,10 +22,16 @@ from .mixins.clike import CLikeCompiler from .mixins.gnu import GnuCompiler from .mixins.clang import ClangCompiler +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + + class ObjCCompiler(CLikeCompiler, Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str], **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross: bool, info: 'MachineInfo', + exe_wrap: typing.Optional[str], **kwargs): self.language = 'objc' - Compiler.__init__(self, exelist, version, for_machine, **kwargs) + Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) def get_display_language(self): @@ -57,9 +63,12 @@ class ObjCCompiler(CLikeCompiler, Compiler): class GnuObjCCompiler(GnuCompiler, ObjCCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + GnuCompiler.__init__(self, defines) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, @@ -68,9 +77,12 @@ class GnuObjCCompiler(GnuCompiler, ObjCCompiler): class ClangObjCCompiler(ClangCompiler, ObjCCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ClangCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + ObjCCompiler.__init__(self, exelist, version, for_machine, is_cross, + info, exe_wrapper, **kwargs) + ClangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch'] self.warn_args = {'0': [], '1': default_warn_args, diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index 70a86c5..5dab8b0 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -22,10 +22,15 @@ from .compilers import Compiler from .mixins.gnu import GnuCompiler from .mixins.clang import ClangCompiler +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + class ObjCPPCompiler(CLikeCompiler, Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str], **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross: bool, info: 'MachineInfo', + exe_wrap: typing.Optional[str], **kwargs): self.language = 'objcpp' - Compiler.__init__(self, exelist, version, for_machine, **kwargs) + Compiler.__init__(self, exelist, version, for_machine, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) def get_display_language(self): @@ -58,9 +63,11 @@ class ObjCPPCompiler(CLikeCompiler, Compiler): class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, defines=None, **kwargs): - ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - GnuCompiler.__init__(self, compiler_type, defines) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + defines=None, **kwargs): + ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs) + GnuCompiler.__init__(self, defines) default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] self.warn_args = {'0': [], '1': default_warn_args, @@ -69,9 +76,11 @@ class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler): class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler): - def __init__(self, exelist, version, compiler_type, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): - ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, exe_wrapper, **kwargs) - ClangCompiler.__init__(self, compiler_type) + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, + **kwargs): + ObjCPPCompiler.__init__(self, exelist, version, for_machine, is_cross, info, exe_wrapper, **kwargs) + ClangCompiler.__init__(self) default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor'] self.warn_args = {'0': [], '1': default_warn_args, diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 479c5a7..a17b697 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -19,6 +19,7 @@ from ..mesonlib import EnvironmentException, MachineChoice, Popen_safe from .compilers import Compiler, rust_buildtype_args, clike_debug_args if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo from ..environment import Environment # noqa: F401 rust_optimization_args = {'0': [], @@ -30,9 +31,13 @@ rust_optimization_args = {'0': [], } class RustCompiler(Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, exe_wrapper=None, **kwargs): + + LINKER_PREFIX = '-Wl,' + + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', exe_wrapper=None, **kwargs): self.language = 'rust' - super().__init__(exelist, version, for_machine, **kwargs) + super().__init__(exelist, version, for_machine, info, **kwargs) self.exe_wrapper = exe_wrapper self.id = 'rustc' self.is_cross = is_cross diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py index e429056..c5d3885 100644 --- a/mesonbuild/compilers/swift.py +++ b/mesonbuild/compilers/swift.py @@ -13,11 +13,15 @@ # limitations under the License. import subprocess, os.path +import typing from ..mesonlib import EnvironmentException, MachineChoice from .compilers import Compiler, swift_buildtype_args, clike_debug_args +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + swift_optimization_args = {'0': [], 'g': [], '1': ['-O'], @@ -30,9 +34,10 @@ class SwiftCompiler(Compiler): LINKER_PREFIX = ['-Xlinker'] - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, **kwargs): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo', **kwargs): self.language = 'swift' - super().__init__(exelist, version, for_machine, **kwargs) + super().__init__(exelist, version, for_machine, info, **kwargs) self.version = version self.id = 'llvm' self.is_cross = is_cross diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index d8734fc..528a56d 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -13,16 +13,21 @@ # limitations under the License. import os.path +import typing from .. import mlog from ..mesonlib import EnvironmentException, MachineChoice, version_compare from .compilers import Compiler +if typing.TYPE_CHECKING: + from ..envconfig import MachineInfo + class ValaCompiler(Compiler): - def __init__(self, exelist, version, for_machine: MachineChoice, is_cross): + def __init__(self, exelist, version, for_machine: MachineChoice, + is_cross, info: 'MachineInfo'): self.language = 'vala' - super().__init__(exelist, version, for_machine) + super().__init__(exelist, version, for_machine, info) self.version = version self.is_cross = is_cross self.id = 'valac' -- cgit v1.1 From afbed79baa579a1d3550631168c0810a5d0f522c Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Thu, 22 Aug 2019 11:24:12 -0700 Subject: compilers: replace uses of mesonlib.is_() with self.info.is_() Since these are cross compilation safe, while the former is not. --- mesonbuild/compilers/cs.py | 3 +-- mesonbuild/compilers/d.py | 39 ++++++++++++++++++--------------------- 2 files changed, 19 insertions(+), 23 deletions(-) (limited to 'mesonbuild/compilers') diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index 1dea33a..137acc1 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -16,7 +16,6 @@ import os.path, subprocess import typing from ..mesonlib import EnvironmentException -from ..mesonlib import is_windows from .compilers import Compiler, MachineChoice, mono_buildtype_args from .mixins.islinker import BasicLinkerIsCompilerMixin @@ -152,7 +151,7 @@ class VisualStudioCsCompiler(CsCompiler): def get_buildtype_args(self, buildtype): res = mono_buildtype_args[buildtype] - if not is_windows(): + if not self.info.is_windows(): tmp = [] for flag in res: if flag == '-debug': diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index 28a4fad..f028bd5 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -16,7 +16,7 @@ import os.path, subprocess import typing from ..mesonlib import ( - EnvironmentException, MachineChoice, version_compare, is_windows, is_osx + EnvironmentException, MachineChoice, version_compare, ) from .compilers import ( @@ -119,7 +119,7 @@ class DmdLikeCompilerMixin: return 'deps' def get_pic_args(self): - if is_windows(): + if self.info.is_windows(): return [] return ['-fPIC'] @@ -217,7 +217,7 @@ class DmdLikeCompilerMixin: return ['-Wl,--out-implib=' + implibname] def build_rpath_args(self, env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath): - if is_windows(): + if self.info.is_windows(): return [] # This method is to be used by LDC and DMD. @@ -235,8 +235,7 @@ class DmdLikeCompilerMixin: paths = paths + ':' + padding return ['-Wl,-rpath,{}'.format(paths)] - @classmethod - def translate_args_to_nongnu(cls, args): + def translate_args_to_nongnu(self, args): dcargs = [] # Translate common arguments to flags the LDC/DMD compilers # can understand. @@ -245,10 +244,10 @@ class DmdLikeCompilerMixin: for arg in args: # Translate OS specific arguments first. osargs = [] - if is_windows(): - osargs = cls.translate_arg_to_windows(arg) - elif is_osx(): - osargs = cls.translate_arg_to_osx(arg) + if self.info.is_windows(): + osargs = self.translate_arg_to_windows(arg) + elif self.info.is_darwin(): + osargs = self.translate_arg_to_osx(arg) if osargs: dcargs.extend(osargs) continue @@ -367,7 +366,7 @@ class DmdLikeCompilerMixin: return clike_debug_args[is_debug] + ddebug_args def get_crt_args(self, crt_val, buildtype): - if not is_windows(): + if not self.info.is_windows(): return [] if crt_val in self.mscrt_args: @@ -433,7 +432,7 @@ class DCompiler(Compiler): return 'deps' def get_pic_args(self): - if is_windows(): + if self.info.is_windows(): return [] return ['-fPIC'] @@ -569,7 +568,7 @@ class DCompiler(Compiler): def get_target_arch_args(self): # LDC2 on Windows targets to current OS architecture, but # it should follow the target specified by the MSVC toolchain. - if is_windows(): + if self.info.is_windows(): if self.arch == 'x86_64': return ['-m64'] return ['-m32'] @@ -668,9 +667,8 @@ class LLVMDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompi def get_crt_link_args(self, crt_val, buildtype): return self.get_crt_args(crt_val, buildtype) - @classmethod - def unix_args_to_native(cls, args): - return cls.translate_args_to_nongnu(args) + def unix_args_to_native(self, args): + return self.translate_args_to_nongnu(args) def get_optimization_args(self, optimization_level): return ldc_optimization_args[optimization_level] @@ -695,7 +693,7 @@ class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompil return d_dmd_buildtype_args[buildtype] def get_std_exe_link_args(self): - if is_windows(): + if self.info.is_windows(): # DMD links against D runtime only when main symbol is found, # so these needs to be inserted when linking static D libraries. if self.arch == 'x86_64': @@ -707,7 +705,7 @@ class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompil def get_std_shared_lib_link_args(self): libname = 'libphobos2.so' - if is_windows(): + if self.info.is_windows(): if self.arch == 'x86_64': libname = 'phobos64.lib' elif self.arch == 'x86_mscoff': @@ -720,7 +718,7 @@ class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompil # DMD32 and DMD64 on 64-bit Windows defaults to 32-bit (OMF). # Force the target to 64-bit in order to stay consistent # across the different platforms. - if is_windows(): + if self.info.is_windows(): if self.arch == 'x86_64': return ['-m64'] elif self.arch == 'x86_mscoff': @@ -731,9 +729,8 @@ class DmdDCompiler(DmdLikeCompilerMixin, LinkerEnvVarsMixin, BasicLinkerIsCompil def get_crt_compile_args(self, crt_val, buildtype): return self.get_crt_args(crt_val, buildtype) - @classmethod - def unix_args_to_native(cls, args): - return cls.translate_args_to_nongnu(args) + def unix_args_to_native(self, args): + return self.translate_args_to_nongnu(args) def get_optimization_args(self, optimization_level): return dmd_optimization_args[optimization_level] -- cgit v1.1