diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2014-05-10 01:14:52 +0300 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2014-05-10 01:14:52 +0300 |
commit | 9c2364b51564f11815c2c04c08fdd53ae01ef1fa (patch) | |
tree | 3be449d608cbd37dfb07783683dc5673a4fbc607 | |
parent | eeaa5d06840345e869d9f87ffa6988a88e49c8f5 (diff) | |
download | meson-9c2364b51564f11815c2c04c08fdd53ae01ef1fa.zip meson-9c2364b51564f11815c2c04c08fdd53ae01ef1fa.tar.gz meson-9c2364b51564f11815c2c04c08fdd53ae01ef1fa.tar.bz2 |
Started work on Vala compilation.
-rw-r--r-- | build.py | 3 | ||||
-rw-r--r-- | environment.py | 48 | ||||
-rw-r--r-- | interpreter.py | 22 | ||||
-rw-r--r-- | ninjabackend.py | 13 | ||||
-rw-r--r-- | test cases/vala/1 basic/meson.build | 4 | ||||
-rw-r--r-- | test cases/vala/1 basic/prog.vala | 7 |
6 files changed, 91 insertions, 6 deletions
@@ -51,7 +51,8 @@ class Build: return False def add_compiler(self, compiler): - if self.static_linker is None and compiler.get_language() != 'java': + if self.static_linker is None and compiler.get_language() != 'java'\ + and compiler.get_language() != 'vala': self.static_linker = self.environment.detect_static_linker(compiler) if self.has_language(compiler.get_language()): return diff --git a/environment.py b/environment.py index b4c80e4..d484c2b 100644 --- a/environment.py +++ b/environment.py @@ -542,6 +542,37 @@ class JavaCompiler(): def has_function(self, funcname, prefix, env): raise EnvironmentException('Java does not support function checks.') +class ValaCompiler(): + def __init__(self, exelist, version): + if isinstance(exelist, str): + self.exelist = [exelist] + elif type(exelist) == type([]): + self.exelist = exelist + else: + raise TypeError('Unknown argument to JavaCompiler') + self.version = version + self.id = 'unknown' + self.language = 'vala' + + def get_exelist(self): + return self.exelist + + def get_language(self): + return self.language + + def sanity_check(self, work_dir): + src = 'valatest.vala' + obj = 'valatest.c' + source_name = os.path.join(work_dir, src) + ofile = open(source_name, 'w') + ofile.write('''class SanityCheck : Object { +} +''') + ofile.close() + pc = subprocess.Popen(self.exelist + ['-C', '-o', obj, src], cwd=work_dir) + pc.wait() + if pc.returncode != 0: + raise EnvironmentException('Vala compiler %s can not compile programs.' % self.name_string()) class VisualStudioCCompiler(CCompiler): std_warn_flags = ['/W3'] @@ -1265,6 +1296,23 @@ class Environment(): return JavaCompiler(exelist, version) raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') + def detect_vala_compiler(self): + exelist = ['valac'] + try: + p = subprocess.Popen(exelist + ['--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + except OSError: + raise EnvironmentException('Could not execute Vala compiler "%s"' % ' '.join(exelist)) + (out, _) = p.communicate() + out = out.decode() + vmatch = re.search(Environment.version_regex, out) + if vmatch: + version = vmatch.group(0) + else: + version = 'unknown version' + if 'Vala' in out: + return ValaCompiler(exelist, version) + raise EnvironmentException('Unknown compiler "' + ' '.join(exelist) + '"') + def detect_static_linker(self, compiler): if compiler.is_cross: linker = self.cross_info['ar'] diff --git a/interpreter.py b/interpreter.py index f6ae8bb..f9de829 100644 --- a/interpreter.py +++ b/interpreter.py @@ -890,6 +890,13 @@ class Interpreter(): self.build.projects[self.subproject] = args[0] mlog.log('Project name is "', mlog.bold(args[0]), '".', sep='') self.add_languages(node, args[1:]) + langs = self.coredata.compilers.keys() + if 'vala' in langs: + if not 'c' in langs: + raise InterpreterException('Compiling Vala requires a C compiler') + # These are the implicit dependencies of Vala. + self.func_dependency(None, ['glib-2.0'], {}) + self.func_dependency(None, ['gobject-2.0'], {}) def func_message(self, node, args, kwargs): self.validate_arguments(args, 1, [str]) @@ -902,31 +909,36 @@ class Interpreter(): def add_languages(self, node, args): is_cross = self.environment.is_cross_build() for lang in args: + lang = lang.lower() if lang in self.coredata.compilers: comp = self.coredata.compilers[lang] cross_comp = self.coredata.cross_compilers.get(lang, None) else: cross_comp = None - if lang.lower() == 'c': + if lang == 'c': comp = self.environment.detect_c_compiler(False) if is_cross: cross_comp = self.environment.detect_c_compiler(True) - elif lang.lower() == 'cpp': + elif lang == 'cpp': comp = self.environment.detect_cpp_compiler(False) if is_cross: cross_comp = self.environment.detect_cpp_compiler(True) - elif lang.lower() == 'objc': + elif lang == 'objc': comp = self.environment.detect_objc_compiler(False) if is_cross: cross_comp = self.environment.detect_objc_compiler(True) - elif lang.lower() == 'objcpp': + elif lang == 'objcpp': comp = self.environment.detect_objcpp_compiler(False) if is_cross: cross_comp = self.environment.detect_objcpp_compiler(True) - elif lang.lower() == 'java': + elif lang == 'java': comp = self.environment.detect_java_compiler() if is_cross: cross_comp = comp # Java is platform independent. + elif lang == 'vala': + comp = self.environment.detect_vala_compiler() + if is_cross: + cross_comp = comp # Vala is too (I think). else: raise InvalidCode('Tried to use unknown language "%s".' % lang) comp.sanity_check(self.environment.get_scratch_dir()) diff --git a/ninjabackend.py b/ninjabackend.py index 02c849f..cc40d73 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -484,11 +484,24 @@ class NinjaBackend(backends.Backend): outfile.write(description) outfile.write('\n') + def generate_vala_compile_rules(self, compiler, outfile): + rule = 'rule %s_COMPILER\n' % compiler.get_language() + invoc = ' '.join([ninja_quote(i) for i in compiler.get_exelist()]) + command = ' command = %s $FLAGS $in\n' % invoc + description = ' description = Compiling Vala source $in.\n' + outfile.write(rule) + outfile.write(command) + outfile.write(description) + outfile.write('\n') + def generate_compile_rule_for(self, langname, compiler, qstr, is_cross, outfile): if langname == 'java': if not is_cross: self.generate_java_compile_rule(compiler, outfile) return + if langname == 'vala': + if not is_cross: + self.generate_vala_compile_rules(compiler, outfile) if is_cross: crstr = '_CROSS' else: diff --git a/test cases/vala/1 basic/meson.build b/test cases/vala/1 basic/meson.build new file mode 100644 index 0000000..334583d --- /dev/null +++ b/test cases/vala/1 basic/meson.build @@ -0,0 +1,4 @@ +project('valatest', 'vala', 'c') + +e = executable('valaprog', 'prog.vala') +test('valatest', e) diff --git a/test cases/vala/1 basic/prog.vala b/test cases/vala/1 basic/prog.vala new file mode 100644 index 0000000..798def0 --- /dev/null +++ b/test cases/vala/1 basic/prog.vala @@ -0,0 +1,7 @@ +class MainProg : GLib.Object { + + public static int main(strings[] args) { + stdout.printf("Vala is working."); + return 0; + } +} |