Skip to content

Commit

Permalink
Merge pull request mesonbuild#5833 from dcbaker/remove-compiler-type
Browse files Browse the repository at this point in the history
Remove compiler type
  • Loading branch information
jpakkane authored Oct 9, 2019
2 parents f64d9b4 + afbed79 commit b6af3f3
Show file tree
Hide file tree
Showing 27 changed files with 544 additions and 376 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.mypy_cache/
.pytest_cache/
/.project
/.pydevproject
/.settings
Expand Down
6 changes: 4 additions & 2 deletions mesonbuild/compilers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# Public symbols for compilers sub-package when using 'from . import compilers'
__all__ = [
'CompilerType',
'Compiler',

'all_languages',
Expand All @@ -34,6 +33,8 @@
'lang_suffixes',
'sort_clink',

'AppleClangCCompiler',
'AppleClangCPPCompiler',
'ArmCCompiler',
'ArmCPPCompiler',
'ArmclangCCompiler',
Expand Down Expand Up @@ -97,7 +98,6 @@

# Bring symbols from each module into compilers sub-package namespace
from .compilers import (
CompilerType,
Compiler,
all_languages,
base_options,
Expand All @@ -119,6 +119,7 @@
)
from .c import (
CCompiler,
AppleClangCCompiler,
ArmCCompiler,
ArmclangCCompiler,
ClangCCompiler,
Expand All @@ -134,6 +135,7 @@
)
from .cpp import (
CPPCompiler,
AppleClangCPPCompiler,
ArmCPPCompiler,
ArmclangCPPCompiler,
ClangCPPCompiler,
Expand Down
126 changes: 85 additions & 41 deletions mesonbuild/compilers/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
gnu_winlibs,
msvc_winlibs,
Compiler,
CompilerType,
)

if typing.TYPE_CHECKING:
from ..envconfig import MachineInfo


class CCompiler(CLikeCompiler, Compiler):

Expand All @@ -46,10 +48,10 @@ def attribute_check_func(name):
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):
Expand All @@ -75,9 +77,14 @@ def has_header_symbol(self, hname, symbol, prefix, env, *, extra_args=None, depe


class ClangCCompiler(ClangCompiler, 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)
ClangCompiler.__init__(self, compiler_type)

_C17_VERSION = '>=10.0.0'
_C18_VERSION = '>=11.0.0'

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,
Expand All @@ -90,12 +97,10 @@ def get_options(self):
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',
Expand All @@ -114,11 +119,25 @@ def get_option_link_args(self, options):
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):
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):
Expand All @@ -128,9 +147,11 @@ def get_soname_args(self, *args, **kwargs):
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,
Expand All @@ -157,9 +178,12 @@ def get_option_link_args(self, options):


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,
Expand All @@ -177,7 +201,7 @@ def get_options(self):
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), })
Expand All @@ -191,7 +215,7 @@ def get_option_compile_args(self, options):
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 []

Expand All @@ -200,15 +224,19 @@ def get_pch_use_args(self, pch_dir, header):


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):
Expand All @@ -232,9 +260,11 @@ def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=N


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': [],
Expand Down Expand Up @@ -274,16 +304,23 @@ def get_options(self):
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'

Expand All @@ -294,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):
Expand All @@ -319,9 +358,11 @@ def get_option_compile_args(self, options):


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)
Expand All @@ -337,10 +378,13 @@ def get_option_compile_args(self, options):
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):
Expand Down
49 changes: 5 additions & 44 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -30,6 +30,7 @@

if typing.TYPE_CHECKING:
from ..coredata import OptionDictType
from ..envconfig import MachineInfo
from ..environment import Environment
from ..linkers import DynamicLinker # noqa: F401

Expand Down Expand Up @@ -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]
Expand All @@ -690,6 +691,7 @@ def __init__(self, exelist, version, for_machine: MachineChoice,
self.for_machine = for_machine
self.base_options = []
self.linker = linker
self.info = info

def __repr__(self):
repr_str = "<{0}: v{1} `{2}`>"
Expand Down Expand Up @@ -1175,52 +1177,11 @@ def get_dependency_link_args(self, dep):
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.
Expand Down
Loading

0 comments on commit b6af3f3

Please sign in to comment.