Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some hasattr checks from Compilers #13736

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions mesonbuild/compilers/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
# Mapping of language to suffixes of files that should always be in that language
# This means we can't include .h headers here since they could be C, C++, ObjC, etc.
# First suffix is the language's default.
lang_suffixes = {
lang_suffixes: T.Mapping[str, T.Tuple[str, ...]] = {
'c': ('c',),
'cpp': ('cpp', 'cppm', 'cc', 'cxx', 'c++', 'hh', 'hpp', 'ipp', 'hxx', 'ino', 'ixx', 'C', 'H'),
'cuda': ('cu',),
Expand Down Expand Up @@ -451,11 +451,8 @@ def __init__(self, ccache: T.List[str], exelist: T.List[str], version: str,
full_version: T.Optional[str] = None, is_cross: bool = False):
self.exelist = ccache + exelist
self.exelist_no_ccache = exelist
# In case it's been overridden by a child class already
if not hasattr(self, 'file_suffixes'):
self.file_suffixes = lang_suffixes[self.language]
if not hasattr(self, 'can_compile_suffixes'):
self.can_compile_suffixes: T.Set[str] = set(self.file_suffixes)
self.file_suffixes = lang_suffixes[self.language]
self.can_compile_suffixes = set(self.file_suffixes)
self.default_suffix = self.file_suffixes[0]
self.version = version
self.full_version = full_version
Expand Down
4 changes: 2 additions & 2 deletions mesonbuild/compilers/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def openmp_flags(self, env: Environment) -> T.List[str]:

class IntelFortranCompiler(IntelGnuLikeCompiler, FortranCompiler):

file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', )
id = 'intel'

def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice, is_cross: bool,
Expand All @@ -275,6 +274,7 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic
# FIXME: Add support for OS X and Windows in detect_fortran_compiler so
# we are sent the type of compiler
IntelGnuLikeCompiler.__init__(self)
self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', )
default_warn_args = ['-warn', 'general', '-warn', 'truncated_source']
self.warn_args = {'0': [],
'1': default_warn_args,
Expand Down Expand Up @@ -318,7 +318,6 @@ class IntelLLVMFortranCompiler(IntelFortranCompiler):

class IntelClFortranCompiler(IntelVisualStudioLikeCompiler, FortranCompiler):

file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', )
always_args = ['/nologo']

def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoice,
Expand All @@ -329,6 +328,7 @@ def __init__(self, exelist: T.List[str], version: str, for_machine: MachineChoic
is_cross, info, linker=linker,
full_version=full_version)
IntelVisualStudioLikeCompiler.__init__(self, target)
self.file_suffixes = ('f90', 'f', 'for', 'ftn', 'fpp', )

default_warn_args = ['/warn:general', '/warn:truncated_source']
self.warn_args = {'0': [],
Expand Down
1 change: 0 additions & 1 deletion mesonbuild/compilers/mixins/ccrx.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class CcrxCompiler(Compiler):

if T.TYPE_CHECKING:
is_cross = True
can_compile_suffixes: T.Set[str] = set()

id = 'ccrx'

Expand Down
Loading