Started work on Vala compilation.
This commit is contained in:
parent
eeaa5d0684
commit
9c2364b515
3
build.py
3
build.py
|
@ -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
|
||||
|
|
|
@ -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']
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
project('valatest', 'vala', 'c')
|
||||
|
||||
e = executable('valaprog', 'prog.vala')
|
||||
test('valatest', e)
|
|
@ -0,0 +1,7 @@
|
|||
class MainProg : GLib.Object {
|
||||
|
||||
public static int main(strings[] args) {
|
||||
stdout.printf("Vala is working.");
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue