compilers: Put clang mixin in a module

pull/5661/head
Dylan Baker 5 years ago
parent 51b04204c9
commit bc4438b34f
  1. 2
      mesonbuild/compilers/__init__.py
  2. 2
      mesonbuild/compilers/c.py
  3. 62
      mesonbuild/compilers/compilers.py
  4. 2
      mesonbuild/compilers/cpp.py
  5. 2
      mesonbuild/compilers/fortran.py
  6. 3
      mesonbuild/compilers/mixins/arm.py
  7. 81
      mesonbuild/compilers/mixins/clang.py
  8. 3
      mesonbuild/compilers/objc.py
  9. 3
      mesonbuild/compilers/objcpp.py

@ -118,7 +118,6 @@ from .compilers import (
lang_suffixes,
sanitizer_compile_args,
sort_clink,
ClangCompiler,
CompilerArgs,
)
from .c import (
@ -188,3 +187,4 @@ from .vala import ValaCompiler
from .mixins.visualstudio import VisualStudioLikeCompiler
from .mixins.gnu import GnuCompiler, get_macos_dylib_install_name
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
from .mixins.clang import ClangCompiler

@ -24,10 +24,10 @@ from .mixins.arm import ArmCompiler, ArmclangCompiler
from .mixins.visualstudio import VisualStudioLikeCompiler
from .mixins.gnu import GnuCompiler
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
from .mixins.clang import ClangCompiler
from .compilers import (
gnu_winlibs,
msvc_winlibs,
ClangCompiler,
Compiler,
CompilerType,
ElbrusCompiler,

@ -27,7 +27,7 @@ from ..mesonlib import (
from ..envconfig import (
Properties,
)
from .mixins.gnu import GnuCompiler, GnuLikeCompiler
from .mixins.gnu import GnuCompiler
"""This file contains the data files of all compilers Meson knows
about. To support a new compiler, add its information below.
@ -223,11 +223,6 @@ msvc_winlibs = ['kernel32.lib', 'user32.lib', 'gdi32.lib',
'winspool.lib', 'shell32.lib', 'ole32.lib', 'oleaut32.lib',
'uuid.lib', 'comdlg32.lib', 'advapi32.lib']
clang_color_args = {'auto': ['-Xclang', '-fcolor-diagnostics'],
'always': ['-Xclang', '-fcolor-diagnostics'],
'never': ['-Xclang', '-fno-color-diagnostics'],
}
clike_optimization_args = {'0': [],
'g': [],
'1': ['-O1'],
@ -1386,58 +1381,3 @@ class ElbrusCompiler(GnuCompiler):
paths = (os.path.realpath(p) for p in libstr.split(':'))
break
return paths
class ClangCompiler(GnuLikeCompiler):
def __init__(self, compiler_type):
super().__init__(compiler_type)
self.id = 'clang'
self.base_options.append('b_colorout')
if self.compiler_type.is_osx_compiler:
self.base_options.append('b_bitcode')
# All Clang backends can also do LLVM IR
self.can_compile_suffixes.add('ll')
def get_colorout_args(self, colortype):
return clang_color_args[colortype][:]
def get_optimization_args(self, optimization_level):
return clike_optimization_args[optimization_level]
def get_pch_suffix(self):
return 'pch'
def get_pch_use_args(self, pch_dir, header):
# Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136
# This flag is internal to Clang (or at least not documented on the man page)
# so it might change semantics at any time.
return ['-include-pch', os.path.join(pch_dir, self.get_pch_name(header))]
def has_multi_arguments(self, args, env):
myargs = ['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument']
if mesonlib.version_compare(self.version, '>=3.6.0'):
myargs.append('-Werror=ignored-optimization-argument')
return super().has_multi_arguments(
myargs + args,
env)
def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=None):
if extra_args is None:
extra_args = []
# Starting with XCode 8, we need to pass this to force linker
# 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 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)
def openmp_flags(self):
if version_compare(self.version, '>=3.8.0'):
return ['-fopenmp']
elif version_compare(self.version, '>=3.7.0'):
return ['-fopenmp=libomp']
else:
# Shouldn't work, but it'll be checked explicitly in the OpenMP dependency.
return []

@ -24,7 +24,6 @@ from ..mesonlib import MesonException, MachineChoice, version_compare
from .compilers import (
gnu_winlibs,
msvc_winlibs,
ClangCompiler,
ElbrusCompiler,
PGICompiler,
Compiler,
@ -36,6 +35,7 @@ from .mixins.arm import ArmCompiler, ArmclangCompiler
from .mixins.visualstudio import VisualStudioLikeCompiler
from .mixins.gnu import GnuCompiler
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
from .mixins.clang import ClangCompiler
def non_msvc_eh_options(eh, args):

@ -19,7 +19,6 @@ from .compilers import (
CompilerType,
clike_debug_args,
Compiler,
ClangCompiler,
ElbrusCompiler,
PGICompiler,
)
@ -29,6 +28,7 @@ from .mixins.gnu import (
gnulike_buildtype_linker_args, gnu_optimization_args,
)
from .mixins.intel import IntelGnuLikeCompiler, IntelVisualStudioLikeCompiler
from .mixins.clang import ClangCompiler
from .. import mlog
from mesonbuild.mesonlib import (

@ -19,7 +19,8 @@ import re
import typing
from ... import mesonlib
from ..compilers import clike_debug_args, clang_color_args
from ..compilers import clike_debug_args
from .clang import clang_color_args
if typing.TYPE_CHECKING:
from ..compilers import CompilerType

@ -0,0 +1,81 @@
# Copyright 2019 The meson development team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Abstractions for the LLVM/Clang compiler family."""
import os
from .gnu import GnuLikeCompiler
from ..compilers import clike_optimization_args
from ... import mesonlib
clang_color_args = {'auto': ['-Xclang', '-fcolor-diagnostics'],
'always': ['-Xclang', '-fcolor-diagnostics'],
'never': ['-Xclang', '-fno-color-diagnostics'],
}
class ClangCompiler(GnuLikeCompiler):
def __init__(self, compiler_type):
super().__init__(compiler_type)
self.id = 'clang'
self.base_options.append('b_colorout')
if self.compiler_type.is_osx_compiler:
self.base_options.append('b_bitcode')
# All Clang backends can also do LLVM IR
self.can_compile_suffixes.add('ll')
def get_colorout_args(self, colortype):
return clang_color_args[colortype][:]
def get_optimization_args(self, optimization_level):
return clike_optimization_args[optimization_level]
def get_pch_suffix(self):
return 'pch'
def get_pch_use_args(self, pch_dir, header):
# Workaround for Clang bug http://llvm.org/bugs/show_bug.cgi?id=15136
# This flag is internal to Clang (or at least not documented on the man page)
# so it might change semantics at any time.
return ['-include-pch', os.path.join(pch_dir, self.get_pch_name(header))]
def has_multi_arguments(self, args, env):
myargs = ['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument']
if mesonlib.version_compare(self.version, '>=3.6.0'):
myargs.append('-Werror=ignored-optimization-argument')
return super().has_multi_arguments(
myargs + args,
env)
def has_function(self, funcname, prefix, env, *, extra_args=None, dependencies=None):
if extra_args is None:
extra_args = []
# Starting with XCode 8, we need to pass this to force linker
# 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'):
extra_args.append('-Wl,-no_weak_imports')
return super().has_function(funcname, prefix, env, extra_args=extra_args,
dependencies=dependencies)
def openmp_flags(self):
if mesonlib.version_compare(self.version, '>=3.8.0'):
return ['-fopenmp']
elif mesonlib.version_compare(self.version, '>=3.7.0'):
return ['-fopenmp=libomp']
else:
# Shouldn't work, but it'll be checked explicitly in the OpenMP dependency.
return []

@ -17,9 +17,10 @@ import typing
from ..mesonlib import EnvironmentException, MachineChoice
from .compilers import Compiler, ClangCompiler
from .compilers import Compiler
from .mixins.clike import CLikeCompiler
from .mixins.gnu import GnuCompiler
from .mixins.clang import ClangCompiler
class ObjCCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str]):

@ -18,8 +18,9 @@ import typing
from ..mesonlib import EnvironmentException, MachineChoice
from .mixins.clike import CLikeCompiler
from .compilers import Compiler, ClangCompiler
from .compilers import Compiler
from .mixins.gnu import GnuCompiler
from .mixins.clang import ClangCompiler
class ObjCPPCompiler(CLikeCompiler, Compiler):
def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, exe_wrap: typing.Optional[str]):

Loading…
Cancel
Save