From bf6293771115f129d661e8a84d533ff270e1daf6 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Mon, 22 Apr 2013 00:51:25 +0300 Subject: [PATCH] Can extract compiler ID string. --- environment.py | 17 +++++++++++++++++ interpreter.py | 10 ++++++++-- test cases/common/34 compiler id/meson.build | 7 +++++++ 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 test cases/common/34 compiler id/meson.build diff --git a/environment.py b/environment.py index 255784ee5..23b6919bb 100755 --- a/environment.py +++ b/environment.py @@ -35,6 +35,10 @@ class CCompiler(): raise TypeError('Unknown argument to CCompiler') self.language = 'c' self.default_suffix = 'c' + self.id = 'unknown' + + def get_id(self): + return self.id def get_dependency_gen_flags(self, outtarget, outfile): return ['-MMD', '-MT', outtarget, '-MF', outfile] @@ -201,6 +205,7 @@ class VisualStudioCCompiler(CCompiler): def __init__(self, exelist): CCompiler.__init__(self, exelist) + self.id = 'msvc' def get_std_warn_flags(self): return VisualStudioCCompiler.std_warn_flags @@ -287,6 +292,7 @@ class GnuCCompiler(CCompiler): def __init__(self, exelist): CCompiler.__init__(self, exelist) + self.id = 'gcc' def get_std_warn_flags(self): return GnuCCompiler.std_warn_flags @@ -300,6 +306,10 @@ class GnuCCompiler(CCompiler): class GnuObjCCompiler(ObjCCompiler): std_warn_flags = ['-Wall', '-Winvalid-pch'] std_opt_flags = ['-O2'] + + def __init__(self, exelist): + ObjCCompiler.__init__(self, exelist) + self.id = 'gcc' def get_std_warn_flags(self): return GnuObjCCompiler.std_warn_flags @@ -314,6 +324,10 @@ class GnuObjCXXCompiler(ObjCXXCompiler): std_warn_flags = ['-Wall', '-Winvalid-pch'] std_opt_flags = ['-O2'] + def __init__(self, exelist): + ObjCCompiler.__init__(self, exelist) + self.id = 'gcc' + def get_std_warn_flags(self): return GnuObjCXXCompiler.std_warn_flags @@ -329,6 +343,7 @@ class ClangCCompiler(CCompiler): def __init__(self, exelist): CCompiler.__init__(self, exelist) + self.id = 'clang' def get_std_warn_flags(self): return ClangCCompiler.std_warn_flags @@ -345,6 +360,7 @@ class GnuCXXCompiler(CXXCompiler): def __init__(self, exelist): CXXCompiler.__init__(self, exelist) + self.id = 'gcc' def get_std_warn_flags(self): return GnuCXXCompiler.std_warn_flags @@ -361,6 +377,7 @@ class ClangCXXCompiler(CXXCompiler): def __init__(self, exelist): CXXCompiler.__init__(self, exelist) + self.id = 'clang' def get_std_warn_flags(self): return ClangCXXCompiler.std_warn_flags diff --git a/interpreter.py b/interpreter.py index e788c98f3..49fcf8229 100755 --- a/interpreter.py +++ b/interpreter.py @@ -500,7 +500,12 @@ class CompilerHolder(InterpreterObject): def __init__(self, compiler): InterpreterObject.__init__(self) self.compiler = compiler - self.methods.update({'compiles': self.compiles_method}) + self.methods.update({'compiles': self.compiles_method, + 'get_id': self.get_id_method, + }) + + def get_id_method(self, args, kwargs): + return self.compiler.get_id() def compiles_method(self, args, kwargs): if len(args) != 1: @@ -665,7 +670,7 @@ class Interpreter(): print('Project name is "%s".' % self.build.project) self.add_languages(node, args[1:]) - def func_message(self, node, args): + def func_message(self, node, args, kwargs): self.validate_arguments(args, 1, [str]) print('Message: %s' % args[0]) @@ -874,6 +879,7 @@ class Interpreter(): if isinstance(value, InterpreterObject) or \ isinstance(value, dependencies.Dependency) or\ isinstance(value, nodes.StringStatement) or\ + isinstance(value, str) or\ isinstance(value, nodes.BoolStatement) or\ isinstance(value, nodes.IntStatement) or\ isinstance(value, list): diff --git a/test cases/common/34 compiler id/meson.build b/test cases/common/34 compiler id/meson.build new file mode 100644 index 000000000..2b5c44530 --- /dev/null +++ b/test cases/common/34 compiler id/meson.build @@ -0,0 +1,7 @@ +project('compiler id', 'c') + +comp = meson.get_compiler('c') +str = comp.get_id() + +message('Compiler name is:') +message(str)