From ee6e249f659cd4658ae2f1a425d4aa01585c23aa Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 25 Nov 2019 11:45:17 -0800 Subject: [PATCH] compilers: move language attribute to the class level We know that if a compiler class inherits CCompiler it's language will be C, so doing this at the class level makes more sense. --- mesonbuild/compilers/c.py | 3 ++- mesonbuild/compilers/cpp.py | 3 ++- mesonbuild/compilers/cs.py | 4 +++- mesonbuild/compilers/cuda.py | 3 +-- mesonbuild/compilers/d.py | 3 ++- mesonbuild/compilers/fortran.py | 3 ++- mesonbuild/compilers/java.py | 4 +++- mesonbuild/compilers/objc.py | 4 +++- mesonbuild/compilers/objcpp.py | 4 +++- mesonbuild/compilers/rust.py | 2 +- mesonbuild/compilers/swift.py | 2 +- mesonbuild/compilers/vala.py | 4 +++- 12 files changed, 26 insertions(+), 13 deletions(-) diff --git a/mesonbuild/compilers/c.py b/mesonbuild/compilers/c.py index db7abf038..42948a073 100644 --- a/mesonbuild/compilers/c.py +++ b/mesonbuild/compilers/c.py @@ -48,10 +48,11 @@ class CCompiler(CLikeCompiler, Compiler): except KeyError: raise MesonException('Unknown function attribute "{}"'.format(name)) + language = 'c' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, 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, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrapper) diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index 6d45a842b..0cf77ab46 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -59,10 +59,11 @@ class CPPCompiler(CLikeCompiler, Compiler): except KeyError: raise MesonException('Unknown function attribute "{}"'.format(name)) + language = 'cpp' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross: bool, 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, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) diff --git a/mesonbuild/compilers/cs.py b/mesonbuild/compilers/cs.py index 137acc14e..f2b1442eb 100644 --- a/mesonbuild/compilers/cs.py +++ b/mesonbuild/compilers/cs.py @@ -33,9 +33,11 @@ cs_optimization_args = {'0': [], class CsCompiler(BasicLinkerIsCompilerMixin, Compiler): + + language = 'cs' + def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo', comp_id, runner=None): - self.language = 'cs' super().__init__(exelist, version, for_machine, info) self.id = comp_id self.is_cross = False diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index 91dde0caa..c8ab9ac3b 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -30,13 +30,12 @@ if typing.TYPE_CHECKING: class CudaCompiler(Compiler): LINKER_PREFIX = '-Xlinker=' + language = 'cuda' _universal_flags = {'compiler': ['-I', '-D', '-U', '-E'], 'linker': ['-l', '-L']} 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, info, **kwargs) self.is_cross = is_cross self.exe_wrapper = exe_wrapper diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index e84a18fdb..15770a548 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -412,9 +412,10 @@ class DCompiler(Compiler): 'mtd': ['-mscrtlib=libcmtd'], } + language = 'd' + def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo', arch, is_cross, exe_wrapper, **kwargs): - self.language = 'd' super().__init__(exelist, version, for_machine, info, **kwargs) self.id = 'unknown' self.arch = arch diff --git a/mesonbuild/compilers/fortran.py b/mesonbuild/compilers/fortran.py index f66ff38be..607d7a5f3 100644 --- a/mesonbuild/compilers/fortran.py +++ b/mesonbuild/compilers/fortran.py @@ -41,9 +41,10 @@ if TYPE_CHECKING: class FortranCompiler(CLikeCompiler, Compiler): + language = 'fortran' + 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, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrapper) self.id = 'unknown' diff --git a/mesonbuild/compilers/java.py b/mesonbuild/compilers/java.py index cc195ff58..bb62fb2d7 100644 --- a/mesonbuild/compilers/java.py +++ b/mesonbuild/compilers/java.py @@ -25,9 +25,11 @@ if typing.TYPE_CHECKING: from ..envconfig import MachineInfo class JavaCompiler(BasicLinkerIsCompilerMixin, Compiler): + + language = 'java' + def __init__(self, exelist, version, for_machine: MachineChoice, info: 'MachineInfo'): - self.language = 'java' super().__init__(exelist, version, for_machine, info) self.id = 'unknown' self.is_cross = False diff --git a/mesonbuild/compilers/objc.py b/mesonbuild/compilers/objc.py index f69c57ccc..9f8bda801 100644 --- a/mesonbuild/compilers/objc.py +++ b/mesonbuild/compilers/objc.py @@ -27,10 +27,12 @@ if typing.TYPE_CHECKING: class ObjCCompiler(CLikeCompiler, Compiler): + + language = 'objc' + 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, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) diff --git a/mesonbuild/compilers/objcpp.py b/mesonbuild/compilers/objcpp.py index 76cda7bd0..ea35a3634 100644 --- a/mesonbuild/compilers/objcpp.py +++ b/mesonbuild/compilers/objcpp.py @@ -26,10 +26,12 @@ if typing.TYPE_CHECKING: from ..envconfig import MachineInfo class ObjCPPCompiler(CLikeCompiler, Compiler): + + language = 'objcpp' + 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, info, **kwargs) CLikeCompiler.__init__(self, is_cross, exe_wrap) diff --git a/mesonbuild/compilers/rust.py b/mesonbuild/compilers/rust.py index 405afea3b..613414d96 100644 --- a/mesonbuild/compilers/rust.py +++ b/mesonbuild/compilers/rust.py @@ -33,10 +33,10 @@ rust_optimization_args = {'0': [], class RustCompiler(Compiler): # rustc doesn't invoke the compiler itself, it doesn't need a LINKER_PREFIX + language = 'rust' 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, info, **kwargs) self.exe_wrapper = exe_wrapper self.id = 'rustc' diff --git a/mesonbuild/compilers/swift.py b/mesonbuild/compilers/swift.py index c5d388559..0909d2027 100644 --- a/mesonbuild/compilers/swift.py +++ b/mesonbuild/compilers/swift.py @@ -33,10 +33,10 @@ swift_optimization_args = {'0': [], class SwiftCompiler(Compiler): LINKER_PREFIX = ['-Xlinker'] + language = 'swift' def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, info: 'MachineInfo', **kwargs): - self.language = 'swift' super().__init__(exelist, version, for_machine, info, **kwargs) self.version = version self.id = 'llvm' diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index 528a56de0..3f4e5fa92 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -24,9 +24,11 @@ if typing.TYPE_CHECKING: from ..envconfig import MachineInfo class ValaCompiler(Compiler): + + language = 'vala' + def __init__(self, exelist, version, for_machine: MachineChoice, is_cross, info: 'MachineInfo'): - self.language = 'vala' super().__init__(exelist, version, for_machine, info) self.version = version self.is_cross = is_cross