aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Seifert <soap@gentoo.org>2018-09-15 13:13:50 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2018-09-16 00:47:32 +0300
commit69ec001b0672094ab92c07f5e561c9c0525aef7b (patch)
treec4ca07ad57cf0eeacd8936599edbaae202e9d42e
parent73b47e00250de335513172f0ed0284cd4ac31599 (diff)
downloadmeson-69ec001b0672094ab92c07f5e561c9c0525aef7b.zip
meson-69ec001b0672094ab92c07f5e561c9c0525aef7b.tar.gz
meson-69ec001b0672094ab92c07f5e561c9c0525aef7b.tar.bz2
Use enum instead of `int` for compiler variants
* Enums are strongly typed and make the whole `gcc_type`/`clang_type`/`icc_type` distinction redundant. * Enums also allow extending via member functions, which makes the code more generalisable.
-rw-r--r--mesonbuild/compilers/__init__.py22
-rw-r--r--mesonbuild/compilers/c.py39
-rw-r--r--mesonbuild/compilers/compilers.py137
-rw-r--r--mesonbuild/compilers/cpp.py24
-rw-r--r--mesonbuild/compilers/d.py7
-rw-r--r--mesonbuild/compilers/fortran.py14
-rw-r--r--mesonbuild/compilers/objc.py16
-rw-r--r--mesonbuild/compilers/objcpp.py16
-rw-r--r--mesonbuild/environment.py53
-rwxr-xr-xrun_unittests.py26
10 files changed, 165 insertions, 189 deletions
diff --git a/mesonbuild/compilers/__init__.py b/mesonbuild/compilers/__init__.py
index bb6c9a9..677301e 100644
--- a/mesonbuild/compilers/__init__.py
+++ b/mesonbuild/compilers/__init__.py
@@ -14,16 +14,7 @@
# Public symbols for compilers sub-package when using 'from . import compilers'
__all__ = [
- 'CLANG_OSX',
- 'CLANG_STANDARD',
- 'CLANG_WIN',
- 'GCC_CYGWIN',
- 'GCC_MINGW',
- 'GCC_OSX',
- 'GCC_STANDARD',
- 'ICC_OSX',
- 'ICC_STANDARD',
- 'ICC_WIN',
+ 'CompilerType',
'all_languages',
'base_options',
@@ -94,16 +85,7 @@ __all__ = [
# Bring symbols from each module into compilers sub-package namespace
from .compilers import (
- GCC_OSX,
- GCC_MINGW,
- GCC_CYGWIN,
- GCC_STANDARD,
- CLANG_OSX,
- CLANG_WIN,
- CLANG_STANDARD,
- ICC_OSX,
- ICC_WIN,
- ICC_STANDARD,
+ CompilerType,
all_languages,
base_options,
clib_langs,
diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py
index 1d531a6..acd3b3d 100644
--- a/mesonbuild/compilers/c.py
+++ b/mesonbuild/compilers/c.py
@@ -30,7 +30,7 @@ from ..mesonlib import (
from .c_function_attributes import C_FUNC_ATTRIBUTES
from .compilers import (
- GCC_MINGW,
+ CompilerType,
get_largefile_args,
gnu_winlibs,
msvc_winlibs,
@@ -121,7 +121,7 @@ class CCompiler(Compiler):
# The default behavior is this, override in MSVC
@functools.lru_cache(maxsize=None)
def build_rpath_args(self, build_dir, from_dir, rpath_paths, build_rpath, install_rpath):
- if self.id == 'clang' and self.clang_type == compilers.CLANG_OSX:
+ if self.id == 'clang' and self.compiler_type == CompilerType.CLANG_OSX:
return self.build_osx_rpath_args(build_dir, rpath_paths, build_rpath)
return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, build_rpath, install_rpath)
@@ -160,15 +160,8 @@ class CCompiler(Compiler):
'''
Get args for allowing undefined symbols when linking to a shared library
'''
- if self.id == 'clang':
- if self.clang_type == compilers.CLANG_OSX:
- # Apple ld
- return ['-Wl,-undefined,dynamic_lookup']
- else:
- # GNU ld and LLVM lld
- return ['-Wl,--allow-shlib-undefined']
- elif self.id == 'gcc':
- if self.gcc_type == compilers.GCC_OSX:
+ if self.id in ('clang', 'gcc'):
+ if self.compiler_type.is_osx_compiler:
# Apple ld
return ['-Wl,-undefined,dynamic_lookup']
else:
@@ -1064,9 +1057,9 @@ class CCompiler(Compiler):
class ClangCCompiler(ClangCompiler, CCompiler):
- def __init__(self, exelist, version, clang_type, is_cross, exe_wrapper=None, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
- ClangCompiler.__init__(self, clang_type)
+ ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
@@ -1092,7 +1085,7 @@ class ClangCCompiler(ClangCompiler, CCompiler):
def get_linker_always_args(self):
basic = super().get_linker_always_args()
- if self.clang_type == compilers.CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
return basic + ['-Wl,-headerpad_max_install_names']
return basic
@@ -1126,9 +1119,9 @@ class ArmclangCCompiler(ArmclangCompiler, CCompiler):
class GnuCCompiler(GnuCompiler, CCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
- GnuCompiler.__init__(self, gcc_type, defines)
+ GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
@@ -1140,7 +1133,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
['none', 'c89', 'c99', 'c11',
'gnu89', 'gnu99', 'gnu11'],
'none')})
- if self.gcc_type == GCC_MINGW:
+ if self.compiler_type == CompilerType.GCC_MINGW:
opts.update({
'c_winlibs': coredata.UserArrayOption('c_winlibs', 'Standard Win libraries to link against',
gnu_winlibs), })
@@ -1154,7 +1147,7 @@ class GnuCCompiler(GnuCompiler, CCompiler):
return args
def get_option_link_args(self, options):
- if self.gcc_type == GCC_MINGW:
+ if self.compiler_type == CompilerType.GCC_MINGW:
return options['c_winlibs'].value[:]
return []
@@ -1166,9 +1159,9 @@ class GnuCCompiler(GnuCompiler, CCompiler):
class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuCCompiler.__init__(self, exelist, version, gcc_type, is_cross, exe_wrapper, defines, **kwargs)
- ElbrusCompiler.__init__(self, gcc_type, defines)
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuCCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ ElbrusCompiler.__init__(self, compiler_type, 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):
@@ -1190,9 +1183,9 @@ class ElbrusCCompiler(GnuCCompiler, ElbrusCompiler):
class IntelCCompiler(IntelCompiler, CCompiler):
- def __init__(self, exelist, version, icc_type, is_cross, exe_wrapper=None, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
CCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
- IntelCompiler.__init__(self, icc_type)
+ IntelCompiler.__init__(self, compiler_type)
self.lang_header = 'c-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark', '-Wpch-messages']
self.warn_args = {'1': default_warn_args,
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 40d6880..bf261a2 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, os.path, re, tempfile, shlex
+import contextlib, enum, os.path, re, tempfile, shlex
import subprocess
from ..linkers import StaticLinker
@@ -1141,19 +1141,35 @@ class Compiler:
raise EnvironmentException(
'Language {} does not support function attributes.'.format(self.get_display_language()))
-GCC_STANDARD = 0
-GCC_OSX = 1
-GCC_MINGW = 2
-GCC_CYGWIN = 3
-CLANG_STANDARD = 0
-CLANG_OSX = 1
-CLANG_WIN = 2
-# Possibly clang-cl?
+@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
+ # Possibly clang-cl?
+
+ ICC_STANDARD = 20
+ ICC_OSX = 21
+ ICC_WIN = 22
+
+ @property
+ def is_standard_compiler(self):
+ return self.name in ('GCC_STANDARD', 'CLANG_STANDARD', 'ICC_STANDARD')
+
+ @property
+ def is_osx_compiler(self):
+ return self.name in ('GCC_OSX', 'CLANG_OSX', 'ICC_OSX')
+
+ @property
+ def is_windows_compiler(self):
+ return self.name in ('GCC_MINGW', 'GCC_CYGWIN', 'CLANG_MINGW', 'ICC_WIN')
-ICC_STANDARD = 0
-ICC_OSX = 1
-ICC_WIN = 2
# GNU ld cannot be installed on macOS
# https://github.com/Homebrew/homebrew-core/issues/17794#issuecomment-328174395
@@ -1169,14 +1185,14 @@ def get_macos_dylib_install_name(prefix, shlib_name, suffix, soversion):
install_name += '.dylib'
return '@rpath/' + install_name
-def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, soversion, darwin_versions, is_shared_module):
- if gcc_type == GCC_STANDARD:
+def get_gcc_soname_args(compiler_type, prefix, shlib_name, suffix, soversion, darwin_versions, is_shared_module):
+ if compiler_type.is_standard_compiler:
sostr = '' if soversion is None else '.' + soversion
return ['-Wl,-soname,%s%s.%s%s' % (prefix, shlib_name, suffix, sostr)]
- elif gcc_type in (GCC_MINGW, GCC_CYGWIN):
+ elif compiler_type.is_windows_compiler:
# For PE/COFF the soname argument has no effect with GNU LD
return []
- elif gcc_type == GCC_OSX:
+ elif compiler_type.is_osx_compiler:
if is_shared_module:
return []
name = get_macos_dylib_install_name(prefix, shlib_name, suffix, soversion)
@@ -1188,20 +1204,21 @@ def get_gcc_soname_args(gcc_type, prefix, shlib_name, suffix, soversion, darwin_
raise RuntimeError('Not implemented yet.')
def get_compiler_is_linuxlike(compiler):
- if (getattr(compiler, 'gcc_type', None) == GCC_STANDARD) or \
- (getattr(compiler, 'clang_type', None) == CLANG_STANDARD) or \
- (getattr(compiler, 'icc_type', None) == ICC_STANDARD):
- return True
- return False
+ compiler_type = getattr(compiler, 'compiler_type', None)
+ return compiler_type and compiler_type.is_standard_compiler
def get_compiler_uses_gnuld(c):
# FIXME: Perhaps we should detect the linker in the environment?
# FIXME: Assumes that *BSD use GNU ld, but they might start using lld soon
- if (getattr(c, 'gcc_type', None) in (GCC_STANDARD, GCC_MINGW, GCC_CYGWIN)) or \
- (getattr(c, 'clang_type', None) in (CLANG_STANDARD, CLANG_WIN)) or \
- (getattr(c, 'icc_type', None) in (ICC_STANDARD, ICC_WIN)):
- return True
- return False
+ compiler_type = getattr(c, 'compiler_type', None)
+ return compiler_type in (
+ CompilerType.GCC_STANDARD,
+ CompilerType.GCC_MINGW,
+ CompilerType.GCC_CYGWIN,
+ CompilerType.CLANG_STANDARD,
+ CompilerType.CLANG_MINGW,
+ CompilerType.ICC_STANDARD,
+ CompilerType.ICC_WIN)
def get_largefile_args(compiler):
'''
@@ -1262,13 +1279,13 @@ def gnulike_default_include_dirs(compiler, lang):
class GnuCompiler:
# Functionality that is common to all GNU family compilers.
- def __init__(self, gcc_type, defines):
+ def __init__(self, compiler_type, defines):
self.id = 'gcc'
- self.gcc_type = gcc_type
+ self.compiler_type = compiler_type
self.defines = defines or {}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_colorout', 'b_ndebug', 'b_staticpic']
- if self.gcc_type == GCC_OSX:
+ if self.compiler_type.is_osx_compiler:
self.base_options.append('b_bitcode')
else:
self.base_options.append('b_lundef')
@@ -1279,7 +1296,7 @@ class GnuCompiler:
# TODO: centralise this policy more globally, instead
# of fragmenting it into GnuCompiler and ClangCompiler
def get_asneeded_args(self):
- if self.gcc_type == GCC_OSX:
+ if self.compiler_type.is_osx_compiler:
return APPLE_LD_AS_NEEDED
else:
return GNU_LD_AS_NEEDED
@@ -1305,7 +1322,7 @@ class GnuCompiler:
return self.defines[define]
def get_pic_args(self):
- if self.gcc_type in (GCC_CYGWIN, GCC_MINGW, GCC_OSX):
+ if self.compiler_type in (CompilerType.GCC_CYGWIN, CompilerType.GCC_MINGW, CompilerType.GCC_OSX):
return [] # On Window and OS X, pic is always on.
return ['-fPIC']
@@ -1319,7 +1336,7 @@ class GnuCompiler:
return clike_debug_args[is_debug]
def get_buildtype_linker_args(self, buildtype):
- if self.gcc_type == GCC_OSX:
+ if self.compiler_type.is_osx_compiler:
return apple_buildtype_linker_args[buildtype]
return gnulike_buildtype_linker_args[buildtype]
@@ -1330,7 +1347,7 @@ class GnuCompiler:
return os.path.dirname(fname), fname
def get_soname_args(self, *args):
- return get_gcc_soname_args(self.gcc_type, *args)
+ return get_gcc_soname_args(self.compiler_type, *args)
def get_std_shared_lib_link_args(self):
return ['-shared']
@@ -1343,13 +1360,13 @@ class GnuCompiler:
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.gcc_type in (GCC_CYGWIN, GCC_MINGW):
+ if self.compiler_type in (CompilerType.GCC_CYGWIN, CompilerType.GCC_MINGW):
return [defsfile]
# For other targets, discard the .def file.
return []
def get_gui_app_args(self, value):
- if self.gcc_type in (GCC_CYGWIN, GCC_MINGW) and value:
+ if self.compiler_type in (CompilerType.GCC_CYGWIN, CompilerType.GCC_MINGW) and value:
return ['-mwindows']
return []
@@ -1368,8 +1385,8 @@ class GnuCompiler:
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, gcc_type, defines):
- GnuCompiler.__init__(self, gcc_type, defines)
+ def __init__(self, compiler_type, defines):
+ GnuCompiler.__init__(self, compiler_type, defines)
self.id = 'lcc'
self.base_options = ['b_pgo', 'b_coverage',
'b_ndebug', 'b_staticpic',
@@ -1404,12 +1421,12 @@ class ElbrusCompiler(GnuCompiler):
return paths
class ClangCompiler:
- def __init__(self, clang_type):
+ def __init__(self, compiler_type):
self.id = 'clang'
- self.clang_type = clang_type
+ self.compiler_type = compiler_type
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_ndebug', 'b_staticpic', 'b_colorout']
- if self.clang_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
self.base_options.append('b_bitcode')
else:
self.base_options.append('b_lundef')
@@ -1420,13 +1437,13 @@ class ClangCompiler:
# TODO: centralise this policy more globally, instead
# of fragmenting it into GnuCompiler and ClangCompiler
def get_asneeded_args(self):
- if self.clang_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
return APPLE_LD_AS_NEEDED
else:
return GNU_LD_AS_NEEDED
def get_pic_args(self):
- if self.clang_type in (CLANG_WIN, CLANG_OSX):
+ if self.compiler_type in (CompilerType.CLANG_MINGW, CompilerType.CLANG_OSX):
return [] # On Window and OS X, pic is always on.
return ['-fPIC']
@@ -1437,7 +1454,7 @@ class ClangCompiler:
return gnulike_buildtype_args[buildtype]
def get_buildtype_linker_args(self, buildtype):
- if self.clang_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
return apple_buildtype_linker_args[buildtype]
return gnulike_buildtype_linker_args[buildtype]
@@ -1457,15 +1474,7 @@ class ClangCompiler:
return ['-include-pch', os.path.join(pch_dir, self.get_pch_name(header))]
def get_soname_args(self, *args):
- if self.clang_type == CLANG_STANDARD:
- gcc_type = GCC_STANDARD
- elif self.clang_type == CLANG_OSX:
- gcc_type = GCC_OSX
- elif self.clang_type == CLANG_WIN:
- gcc_type = GCC_MINGW
- else:
- raise MesonException('Unreachable code when converting clang type to gcc type.')
- return get_gcc_soname_args(gcc_type, *args)
+ return get_gcc_soname_args(self.compiler_type, *args)
def has_multi_arguments(self, args, env):
myargs = ['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument']
@@ -1482,17 +1491,17 @@ class ClangCompiler:
# visibility to obey OS X and iOS minimum version targets with
# -mmacosx-version-min, -miphoneos-version-min, etc.
# https://github.com/Homebrew/homebrew-core/issues/3727
- if self.clang_type == CLANG_OSX and version_compare(self.version, '>=8.0'):
+ if self.compiler_type.is_osx_compiler and version_compare(self.version, '>=8.0'):
extra_args.append('-Wl,-no_weak_imports')
return super().has_function(funcname, prefix, env, extra_args, dependencies)
def get_std_shared_module_link_args(self, options):
- if self.clang_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
return ['-bundle', '-Wl,-undefined,dynamic_lookup']
return ['-shared']
def get_link_whole_for(self, args):
- if self.clang_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
result = []
for a in args:
result += ['-Wl,-force_load', a]
@@ -1593,9 +1602,9 @@ class ArmclangCompiler:
# Tested on linux for ICC 14.0.3, 15.0.6, 16.0.4, 17.0.1
class IntelCompiler:
- def __init__(self, icc_type):
+ def __init__(self, compiler_type):
self.id = 'intel'
- self.icc_type = icc_type
+ self.compiler_type = compiler_type
self.lang_header = 'none'
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage',
'b_colorout', 'b_ndebug', 'b_staticpic', 'b_lundef', 'b_asneeded']
@@ -1625,27 +1634,19 @@ class IntelCompiler:
return os.path.dirname(fname), fname
def get_soname_args(self, *args):
- if self.icc_type == ICC_STANDARD:
- gcc_type = GCC_STANDARD
- elif self.icc_type == ICC_OSX:
- gcc_type = GCC_OSX
- elif self.icc_type == ICC_WIN:
- gcc_type = GCC_MINGW
- else:
- raise MesonException('Unreachable code when converting icc type to gcc type.')
- return get_gcc_soname_args(gcc_type, *args)
+ return get_gcc_soname_args(self.compiler_type, *args)
# TODO: centralise this policy more globally, instead
# of fragmenting it into GnuCompiler and ClangCompiler
def get_asneeded_args(self):
- if self.icc_type == CLANG_OSX:
+ if self.compiler_type.is_osx_compiler:
return APPLE_LD_AS_NEEDED
else:
return GNU_LD_AS_NEEDED
def get_std_shared_lib_link_args(self):
# FIXME: Don't know how icc works on OSX
- # if self.icc_type == ICC_OSX:
+ # if self.compiler_type.is_osx_compiler:
# return ['-bundle']
return ['-shared']
diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py
index 2173655..004f65e 100644
--- a/mesonbuild/compilers/cpp.py
+++ b/mesonbuild/compilers/cpp.py
@@ -21,7 +21,7 @@ from ..mesonlib import MesonException, version_compare
from .c import CCompiler, VisualStudioCCompiler
from .compilers import (
- GCC_MINGW,
+ CompilerType,
gnu_winlibs,
msvc_winlibs,
ClangCompiler,
@@ -126,9 +126,9 @@ class CPPCompiler(CCompiler):
class ClangCPPCompiler(ClangCompiler, CPPCompiler):
- def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
- ClangCompiler.__init__(self, cltype)
+ ClangCompiler.__init__(self, compiler_type)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
@@ -185,9 +185,9 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler):
class GnuCPPCompiler(GnuCompiler, CPPCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrap, defines, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap, defines, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
- GnuCompiler.__init__(self, gcc_type, defines)
+ GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
@@ -202,7 +202,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
'cpp_debugstl': coredata.UserBooleanOption('cpp_debugstl',
'STL debug mode',
False)})
- if self.gcc_type == GCC_MINGW:
+ if self.compiler_type == CompilerType.GCC_MINGW:
opts.update({
'cpp_winlibs': coredata.UserArrayOption('cpp_winlibs', 'Standard Win libraries to link against',
gnu_winlibs), })
@@ -218,7 +218,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
return args
def get_option_link_args(self, options):
- if self.gcc_type == GCC_MINGW:
+ if self.compiler_type == CompilerType.GCC_MINGW:
return options['cpp_winlibs'].value[:]
return []
@@ -230,9 +230,9 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler):
class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuCPPCompiler.__init__(self, exelist, version, gcc_type, is_cross, exe_wrapper, defines, **kwargs)
- ElbrusCompiler.__init__(self, gcc_type, defines)
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuCPPCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ ElbrusCompiler.__init__(self, compiler_type, defines)
# It does not support c++/gnu++ 17 and 1z, but still does support 0x, 1y, and gnu++98.
def get_options(self):
@@ -253,9 +253,9 @@ class ElbrusCPPCompiler(GnuCPPCompiler, ElbrusCompiler):
class IntelCPPCompiler(IntelCompiler, CPPCompiler):
- def __init__(self, exelist, version, icc_type, is_cross, exe_wrap, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrap, **kwargs):
CPPCompiler.__init__(self, exelist, version, is_cross, exe_wrap, **kwargs)
- IntelCompiler.__init__(self, icc_type)
+ IntelCompiler.__init__(self, compiler_type)
self.lang_header = 'c++-header'
default_warn_args = ['-Wall', '-w3', '-diag-disable:remark',
'-Wpch-messages', '-Wnon-virtual-dtor']
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index ee9e0c2..3d46390 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -17,8 +17,7 @@ import os.path, subprocess
from ..mesonlib import EnvironmentException, version_compare, is_windows, is_osx
from .compilers import (
- GCC_STANDARD,
- GCC_OSX,
+ CompilerType,
d_dmd_buildtype_args,
d_gdc_buildtype_args,
d_ldc_buildtype_args,
@@ -152,12 +151,12 @@ class DCompiler(Compiler):
if is_windows():
return []
elif is_osx():
- soname_args = get_gcc_soname_args(GCC_OSX, *args)
+ soname_args = get_gcc_soname_args(CompilerType.GCC_OSX, *args)
if soname_args:
return ['-Wl,' + ','.join(soname_args)]
return []
- return get_gcc_soname_args(GCC_STANDARD, *args)
+ return get_gcc_soname_args(CompilerType.GCC_STANDARD, *args)
def get_feature_args(self, kwargs, build_to_src):
res = []
diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py
index 3c7c2f9..b58c4e0 100644
--- a/mesonbuild/compilers/fortran.py
+++ b/mesonbuild/compilers/fortran.py
@@ -14,7 +14,7 @@
from .c import CCompiler
from .compilers import (
- ICC_STANDARD,
+ CompilerType,
apple_buildtype_linker_args,
gnulike_buildtype_args,
gnulike_buildtype_linker_args,
@@ -257,9 +257,9 @@ end program prog
class GnuFortranCompiler(GnuCompiler, FortranCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwargs)
- GnuCompiler.__init__(self, gcc_type, defines)
+ GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
@@ -279,9 +279,9 @@ class GnuFortranCompiler(GnuCompiler, FortranCompiler):
class ElbrusFortranCompiler(GnuFortranCompiler, ElbrusCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
- GnuFortranCompiler.__init__(self, exelist, version, gcc_type, is_cross, exe_wrapper, defines, **kwargs)
- ElbrusCompiler.__init__(self, gcc_type, defines)
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None, **kwargs):
+ GnuFortranCompiler.__init__(self, exelist, version, compiler_type, is_cross, exe_wrapper, defines, **kwargs)
+ ElbrusCompiler.__init__(self, compiler_type, defines)
class G95FortranCompiler(FortranCompiler):
def __init__(self, exelist, version, is_cross, exe_wrapper=None, **kwags):
@@ -330,7 +330,7 @@ class IntelFortranCompiler(IntelCompiler, FortranCompiler):
FortranCompiler.__init__(self, exelist, version, is_cross, exe_wrapper, **kwags)
# FIXME: Add support for OS X and Windows in detect_fortran_compiler so
# we are sent the type of compiler
- IntelCompiler.__init__(self, ICC_STANDARD)
+ IntelCompiler.__init__(self, CompilerType.ICC_STANDARD)
self.id = 'intel'
default_warn_args = ['-warn', 'general', '-warn', 'truncated_source']
self.warn_args = {'1': default_warn_args,
diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py
index 388e83b..5b2b517 100644
--- a/mesonbuild/compilers/objc.py
+++ b/mesonbuild/compilers/objc.py
@@ -51,17 +51,21 @@ class ObjCCompiler(CCompiler):
class GnuObjCCompiler(GnuCompiler, ObjCCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None):
ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
- GnuCompiler.__init__(self, gcc_type, defines)
+ GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
-class ClangObjCCompiler(ClangCompiler, GnuObjCCompiler):
- def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
- GnuObjCCompiler.__init__(self, exelist, version, cltype, is_cross, exe_wrapper)
- ClangCompiler.__init__(self, cltype)
+class ClangObjCCompiler(ClangCompiler, ObjCCompiler):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None):
+ ObjCCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ ClangCompiler.__init__(self, compiler_type)
+ default_warn_args = ['-Wall', '-Winvalid-pch']
+ self.warn_args = {'1': default_warn_args,
+ '2': default_warn_args + ['-Wextra'],
+ '3': default_warn_args + ['-Wextra', '-Wpedantic']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']
diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py
index c2e4647..e1b7a7d 100644
--- a/mesonbuild/compilers/objcpp.py
+++ b/mesonbuild/compilers/objcpp.py
@@ -52,17 +52,21 @@ class ObjCPPCompiler(CPPCompiler):
class GnuObjCPPCompiler(GnuCompiler, ObjCPPCompiler):
- def __init__(self, exelist, version, gcc_type, is_cross, exe_wrapper=None, defines=None):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None, defines=None):
ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
- GnuCompiler.__init__(self, gcc_type, defines)
+ GnuCompiler.__init__(self, compiler_type, defines)
default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
self.warn_args = {'1': default_warn_args,
'2': default_warn_args + ['-Wextra'],
'3': default_warn_args + ['-Wextra', '-Wpedantic']}
-class ClangObjCPPCompiler(ClangCompiler, GnuObjCPPCompiler):
- def __init__(self, exelist, version, cltype, is_cross, exe_wrapper=None):
- GnuObjCPPCompiler.__init__(self, exelist, version, cltype, is_cross, exe_wrapper)
- ClangCompiler.__init__(self, cltype)
+class ClangObjCPPCompiler(ClangCompiler, ObjCPPCompiler):
+ def __init__(self, exelist, version, compiler_type, is_cross, exe_wrapper=None):
+ ObjCPPCompiler.__init__(self, exelist, version, is_cross, exe_wrapper)
+ ClangCompiler.__init__(self, compiler_type)
+ default_warn_args = ['-Wall', '-Winvalid-pch', '-Wnon-virtual-dtor']
+ self.warn_args = {'1': default_warn_args,
+ '2': default_warn_args + ['-Wextra'],
+ '3': default_warn_args + ['-Wextra', '-Wpedantic']}
self.base_options = ['b_pch', 'b_lto', 'b_pgo', 'b_sanitize', 'b_coverage']
diff --git a/mesonbuild/environment.py b/mesonbuild/environment.py
index 3a1e1e6..35e934a 100644
--- a/mesonbuild/environment.py
+++ b/mesonbuild/environment.py
@@ -22,14 +22,7 @@ from . import mlog
from . import compilers
from .compilers import (
- CLANG_OSX,
- CLANG_STANDARD,
- CLANG_WIN,
- GCC_CYGWIN,
- GCC_MINGW,
- GCC_OSX,
- GCC_STANDARD,
- ICC_STANDARD,
+ CompilerType,
is_assembly,
is_header,
is_library,
@@ -451,12 +444,12 @@ class Environment:
def get_gnu_compiler_type(defines):
# Detect GCC type (Apple, MinGW, Cygwin, Unix)
if '__APPLE__' in defines:
- return GCC_OSX
+ return CompilerType.GCC_OSX
elif '__MINGW32__' in defines or '__MINGW64__' in defines:
- return GCC_MINGW
+ return CompilerType.GCC_MINGW
elif '__CYGWIN__' in defines:
- return GCC_CYGWIN
- return GCC_STANDARD
+ return CompilerType.GCC_CYGWIN
+ return CompilerType.GCC_STANDARD
def warn_about_lang_pointing_to_cross(self, compiler_exe, evar):
evar_str = os.environ.get(evar, 'WHO_WOULD_CALL_THEIR_COMPILER_WITH_THIS_NAME')
@@ -560,14 +553,14 @@ This is probably wrong, it should always point to the native compiler.''' % evar
if not defines:
popen_exceptions[' '.join(compiler)] = 'no pre-processor defines'
continue
- gtype = self.get_gnu_compiler_type(defines)
+ compiler_type = self.get_gnu_compiler_type(defines)
if guess_gcc_or_lcc == 'lcc':
version = self.get_lcc_version_from_defines(defines)
cls = ElbrusCCompiler if lang == 'c' else ElbrusCPPCompiler
else:
version = self.get_gnu_version_from_defines(defines)
cls = GnuCCompiler if lang == 'c' else GnuCPPCompiler
- return cls(ccache + compiler, version, gtype, is_cross, exe_wrap, defines, full_version=full_version)
+ return cls(ccache + compiler, version, compiler_type, is_cross, exe_wrap, defines, full_version=full_version)
if 'armclang' in out:
# The compiler version is not present in the first line of output,
@@ -587,13 +580,13 @@ This is probably wrong, it should always point to the native compiler.''' % evar
return cls(ccache + compiler, version, is_cross, exe_wrap, full_version=full_version)
if 'clang' in out:
if 'Apple' in out or mesonlib.for_darwin(want_cross, self):
- cltype = CLANG_OSX
+ compiler_type = CompilerType.CLANG_OSX
elif 'windows' in out or mesonlib.for_windows(want_cross, self):
- cltype = CLANG_WIN
+ compiler_type = CompilerType.CLANG_MINGW
else:
- cltype = CLANG_STANDARD
+ compiler_type = CompilerType.CLANG_STANDARD
cls = ClangCCompiler if lang == 'c' else ClangCPPCompiler
- return cls(ccache + compiler, version, cltype, is_cross, exe_wrap, full_version=full_version)
+ return cls(ccache + compiler, version, compiler_type, is_cross, exe_wrap, full_version=full_version)
if 'Microsoft' in out or 'Microsoft' in err:
# Latest versions of Visual Studio print version
# number to stderr but earlier ones print version
@@ -610,9 +603,9 @@ This is probably wrong, it should always point to the native compiler.''' % evar
return cls(compiler, version, is_cross, exe_wrap, is_64)
if '(ICC)' in out:
# TODO: add microsoft add check OSX
- inteltype = ICC_STANDARD
+ compiler_type = CompilerType.ICC_STANDARD
cls = IntelCCompiler if lang == 'c' else IntelCPPCompiler
- return cls(ccache + compiler, version, inteltype, is_cross, exe_wrap, full_version=full_version)
+ return cls(ccache + compiler, version, compiler_type, is_cross, exe_wrap, full_version=full_version)
if 'ARM' in out:
cls = ArmCCompiler if lang == 'c' else ArmCPPCompiler
return cls(ccache + compiler, version, is_cross, exe_wrap, full_version=full_version)
@@ -651,14 +644,14 @@ This is probably wrong, it should always point to the native compiler.''' % evar
if not defines:
popen_exceptions[' '.join(compiler)] = 'no pre-processor defines'
continue
- gtype = self.get_gnu_compiler_type(defines)
+ compiler_type = self.get_gnu_compiler_type(defines)
if guess_gcc_or_lcc == 'lcc':
version = self.get_lcc_version_from_defines(defines)
cls = ElbrusFortranCompiler
else:
version = self.get_gnu_version_from_defines(defines)
cls = GnuFortranCompiler
- return cls(compiler, version, gtype, is_cross, exe_wrap, defines, full_version=full_version)
+ return cls(compiler, version, compiler_type, is_cross, exe_wrap, defines, full_version=full_version)
if 'G95' in out:
return G95FortranCompiler(compiler, version, is_cross, exe_wrap, full_version=full_version)
@@ -704,13 +697,13 @@ This is probably wrong, it should always point to the native compiler.''' % evar
if not defines:
popen_exceptions[' '.join(compiler)] = 'no pre-processor defines'
continue
- gtype = self.get_gnu_compiler_type(defines)
+ compiler_type = self.get_gnu_compiler_type(defines)
version = self.get_gnu_version_from_defines(defines)
- return GnuObjCCompiler(ccache + compiler, version, gtype, is_cross, exe_wrap, defines)
+ return GnuObjCCompiler(ccache + compiler, version, compiler_type, is_cross, exe_wrap, defines)
if out.startswith('Apple LLVM'):
- return ClangObjCCompiler(ccache + compiler, version, CLANG_OSX, is_cross, exe_wrap)
+ return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, is_cross, exe_wrap)
if out.startswith('clang'):
- return ClangObjCCompiler(ccache + compiler, version, CLANG_STANDARD, is_cross, exe_wrap)
+ return ClangObjCCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, is_cross, exe_wrap)
self._handle_exceptions(popen_exceptions, compilers)
def detect_objcpp_compiler(self, want_cross):
@@ -731,13 +724,13 @@ This is probably wrong, it should always point to the native compiler.''' % evar
if not defines:
popen_exceptions[' '.join(compiler)] = 'no pre-processor defines'
continue
- gtype = self.get_gnu_compiler_type(defines)
+ compiler_type = self.get_gnu_compiler_type(defines)
version = self.get_gnu_version_from_defines(defines)
- return GnuObjCPPCompiler(ccache + compiler, version, gtype, is_cross, exe_wrap, defines)
+ return GnuObjCPPCompiler(ccache + compiler, version, compiler_type, is_cross, exe_wrap, defines)
if out.startswith('Apple LLVM'):
- return ClangObjCPPCompiler(ccache + compiler, version, CLANG_OSX, is_cross, exe_wrap)
+ return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_OSX, is_cross, exe_wrap)
if out.startswith('clang'):
- return ClangObjCPPCompiler(ccache + compiler, version, CLANG_STANDARD, is_cross, exe_wrap)
+ return ClangObjCPPCompiler(ccache + compiler, version, CompilerType.CLANG_STANDARD, is_cross, exe_wrap)
self._handle_exceptions(popen_exceptions, compilers)
def detect_java_compiler(self):
diff --git a/run_unittests.py b/run_unittests.py
index d9616ea..a355b0f 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -265,7 +265,7 @@ class InternalTests(unittest.TestCase):
def test_compiler_args_class_gnuld(self):
cargsfunc = mesonbuild.compilers.CompilerArgs
## Test --start/end-group
- gcc = mesonbuild.compilers.GnuCCompiler([], 'fake', 0, False)
+ gcc = mesonbuild.compilers.GnuCCompiler([], 'fake', mesonbuild.compilers.CompilerType.GCC_STANDARD, False)
## Test that 'direct' append and extend works
l = cargsfunc(gcc, ['-Lfoodir', '-lfoo'])
self.assertEqual(l.to_native(copy=True), ['-Lfoodir', '-Wl,--start-group', '-lfoo', '-Wl,--end-group'])
@@ -1642,30 +1642,30 @@ class AllPlatformTests(BasePlatformTests):
if isinstance(cc, gnu):
self.assertIsInstance(linker, ar)
if is_osx():
- self.assertEqual(cc.gcc_type, mesonbuild.compilers.GCC_OSX)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.GCC_OSX)
elif is_windows():
- self.assertEqual(cc.gcc_type, mesonbuild.compilers.GCC_MINGW)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.GCC_MINGW)
elif is_cygwin():
- self.assertEqual(cc.gcc_type, mesonbuild.compilers.GCC_CYGWIN)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.GCC_CYGWIN)
else:
- self.assertEqual(cc.gcc_type, mesonbuild.compilers.GCC_STANDARD)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.GCC_STANDARD)
if isinstance(cc, clang):
self.assertIsInstance(linker, ar)
if is_osx():
- self.assertEqual(cc.clang_type, mesonbuild.compilers.CLANG_OSX)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.CLANG_OSX)
elif is_windows():
# Not implemented yet
- self.assertEqual(cc.clang_type, mesonbuild.compilers.CLANG_WIN)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.CLANG_MINGW)
else:
- self.assertEqual(cc.clang_type, mesonbuild.compilers.CLANG_STANDARD)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.CLANG_STANDARD)
if isinstance(cc, intel):
self.assertIsInstance(linker, ar)
if is_osx():
- self.assertEqual(cc.icc_type, mesonbuild.compilers.ICC_OSX)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.ICC_OSX)
elif is_windows():
- self.assertEqual(cc.icc_type, mesonbuild.compilers.ICC_WIN)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.ICC_WIN)
else:
- self.assertEqual(cc.icc_type, mesonbuild.compilers.ICC_STANDARD)
+ self.assertEqual(cc.compiler_type, mesonbuild.compilers.CompilerType.ICC_STANDARD)
if isinstance(cc, msvc):
self.assertTrue(is_windows())
self.assertIsInstance(linker, lib)
@@ -3457,11 +3457,11 @@ class LinuxlikeTests(BasePlatformTests):
for v in compiler.get_options()[lang_std].choices:
if (compiler.get_id() == 'clang' and '17' in v and
(version_compare(compiler.version, '<5.0.0') or
- (compiler.clang_type == mesonbuild.compilers.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
+ (compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
continue
if (compiler.get_id() == 'clang' and '2a' in v and
(version_compare(compiler.version, '<6.0.0') or
- (compiler.clang_type == mesonbuild.compilers.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
+ (compiler.compiler_type == mesonbuild.compilers.CompilerType.CLANG_OSX and version_compare(compiler.version, '<9.1')))):
continue
if (compiler.get_id() == 'gcc' and '2a' in v and version_compare(compiler.version, '<8.0.0')):
continue