From cdee05082b017b3f7d2e20c7ea0019778e670174 Mon Sep 17 00:00:00 2001 From: Jussi Pakkanen Date: Sat, 10 May 2014 20:34:23 +0300 Subject: [PATCH] Can parallel compile a Vala target with multiple files. --- ninjabackend.py | 31 ++++++++++++++++++++ test cases/vala/2 multiple files/class1.vala | 7 +++++ test cases/vala/2 multiple files/class2.vala | 6 ++++ test cases/vala/2 multiple files/main.vala | 8 +++++ test cases/vala/2 multiple files/meson.build | 8 +++++ 5 files changed, 60 insertions(+) create mode 100644 test cases/vala/2 multiple files/class1.vala create mode 100644 test cases/vala/2 multiple files/class2.vala create mode 100644 test cases/vala/2 multiple files/main.vala create mode 100644 test cases/vala/2 multiple files/meson.build diff --git a/ninjabackend.py b/ninjabackend.py index ad8737741..6aff044ec 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -419,9 +419,25 @@ class NinjaBackend(backends.Backend): outfile.write(description) outfile.write('\n') + def generate_fastvapi_compile(self, target, valac, outfile): + fastvapis = {} + for s in target.get_sources(): + if not s.endswith('.vala'): + continue + vapibase = os.path.basename(s)[:-4] + 'vapi' + rel_vapi = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', vapibase) + flags = ['--fast-vapi=' + rel_vapi] + rel_s = os.path.join(self.build_to_src, s) + element = NinjaBuildElement(rel_vapi, valac.get_language() + '_COMPILER', rel_s) + element.add_item('FLAGS', flags) + element.write(outfile) + fastvapis[s] = (vapibase, rel_vapi) + return fastvapis + def generate_vala_compile(self, target, outfile): """Vala is compiled into C. Set up all necessary build steps here.""" valac = self.environment.coredata.compilers['vala'] + fast_vapis = self.generate_fastvapi_compile(target, valac, outfile) generated_c = [] for s in target.get_sources(): if not s.endswith('.vala'): @@ -429,11 +445,20 @@ class NinjaBackend(backends.Backend): flags = ['-d', self.get_target_private_dir(target)] sc = os.path.basename(s)[:-4] + 'c' flags += ['-C', '-o', sc] + vapi_order_deps = [] + for (sourcefile, vapi_info) in fast_vapis.items(): + if sourcefile == s: + continue + (vapibase, rel_vapi) = vapi_info + flags += ['--use-fast-vapi=' + rel_vapi] + vapi_order_deps.append(rel_vapi) relsc = os.path.join(self.get_target_dir(target), target.get_basename() + '.dir', sc) rel_s = os.path.join(self.build_to_src, s) + flags += ['--deps', relsc + '.d'] generated_c += [relsc] element = NinjaBuildElement(relsc, valac.get_language() + '_COMPILER', rel_s) element.add_item('FLAGS', flags) + element.add_orderdep(vapi_order_deps) element.write(outfile) return generated_c @@ -507,9 +532,15 @@ class NinjaBackend(backends.Backend): 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' + restat = ' restat = 1\n' # ValaC does this always to take advantage of it. + depfile = ' depfile = $out.d\n' + depstyle = ' deps = gcc\n' outfile.write(rule) outfile.write(command) outfile.write(description) + outfile.write(restat) + outfile.write(depfile) + outfile.write(depstyle) outfile.write('\n') def generate_compile_rule_for(self, langname, compiler, qstr, is_cross, outfile): diff --git a/test cases/vala/2 multiple files/class1.vala b/test cases/vala/2 multiple files/class1.vala new file mode 100644 index 000000000..7072101d5 --- /dev/null +++ b/test cases/vala/2 multiple files/class1.vala @@ -0,0 +1,7 @@ +class Class1 : GLib.Object { + + public void hello() { + var c2 = new Class2(); + c2.hello(); + } +} diff --git a/test cases/vala/2 multiple files/class2.vala b/test cases/vala/2 multiple files/class2.vala new file mode 100644 index 000000000..ad76cc159 --- /dev/null +++ b/test cases/vala/2 multiple files/class2.vala @@ -0,0 +1,6 @@ +class Class2 : GLib.Object { + + public void hello() { + stdout.printf("Multiple file Vala project is working.\n"); + } +} diff --git a/test cases/vala/2 multiple files/main.vala b/test cases/vala/2 multiple files/main.vala new file mode 100644 index 000000000..6de0fa391 --- /dev/null +++ b/test cases/vala/2 multiple files/main.vala @@ -0,0 +1,8 @@ +class MainProg : GLib.Object { + + public static int main(string[] args) { + var c1 = new Class1(); + c1.hello(); + return 0; + } +} diff --git a/test cases/vala/2 multiple files/meson.build b/test cases/vala/2 multiple files/meson.build new file mode 100644 index 000000000..70d8df852 --- /dev/null +++ b/test cases/vala/2 multiple files/meson.build @@ -0,0 +1,8 @@ +project('multiple files', 'vala', 'c') + +glib = dependency('glib-2.0') +gobject = dependency('gobject-2.0') + +e = executable('prog', 'main.vala', 'class1.vala', 'class2.vala', +deps : [glib, gobject]) +test('multiple file test', e)