From d7ca9eee5a5960a63fdf70edea119afb1db962fc Mon Sep 17 00:00:00 2001 From: Igor Gnatenko Date: Thu, 2 Jul 2015 00:23:52 +0300 Subject: [PATCH] vala: add support for --target-glib Signed-off-by: Igor Gnatenko --- dependencies.py | 10 ++--- ninjabackend.py | 2 + .../vala/5 target glib/GLib.Thread.vala | 41 +++++++++++++++++++ test cases/vala/5 target glib/meson.build | 6 +++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 test cases/vala/5 target glib/GLib.Thread.vala create mode 100644 test cases/vala/5 target glib/meson.build diff --git a/dependencies.py b/dependencies.py index 8d4e81288..dc6279ebe 100644 --- a/dependencies.py +++ b/dependencies.py @@ -110,17 +110,17 @@ class PkgConfigDependency(Dependency): self.modversion = out.decode().strip() mlog.log('%s dependency' % self.type_string, mlog.bold(name), 'found:', mlog.green('YES'), self.modversion) - version_requirement = kwargs.get('version', None) - if version_requirement is None: + self.version_requirement = kwargs.get('version', None) + if self.version_requirement is None: self.is_found = True else: - if not isinstance(version_requirement, str): + if not isinstance(self.version_requirement, str): raise DependencyException('Version argument must be string.') - self.is_found = mesonlib.version_compare(self.modversion, version_requirement) + self.is_found = mesonlib.version_compare(self.modversion, self.version_requirement) if not self.is_found and self.required: raise DependencyException( 'Invalid version of a dependency, needed %s %s found %s.' % - (name, version_requirement, self.modversion)) + (name, self.version_requirement, self.modversion)) if not self.is_found: return p = subprocess.Popen([pkgbin, '--cflags', name], stdout=subprocess.PIPE, diff --git a/ninjabackend.py b/ninjabackend.py index 34f6b180f..694b776ce 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -709,6 +709,8 @@ class NinjaBackend(backends.Backend): args += valac.get_werror_args() for d in target.external_deps: if isinstance(d, dependencies.PkgConfigDependency): + if d.name == 'glib-2.0' and d.version_requirement is not None: + args += ['--target-glib', d.version_requirement[2:]] args += ['--pkg', d.name] args += vapi_src generated_c += [relsc] diff --git a/test cases/vala/5 target glib/GLib.Thread.vala b/test cases/vala/5 target glib/GLib.Thread.vala new file mode 100644 index 000000000..27c0fca17 --- /dev/null +++ b/test cases/vala/5 target glib/GLib.Thread.vala @@ -0,0 +1,41 @@ +public class MyThread : Object { + public int x_times { get; private set; } + + public MyThread (int times) { + this.x_times = times; + } + + public int run () { + for (int i = 0; i < this.x_times; i++) { + stdout.printf ("ping! %d/%d\n", i + 1, this.x_times); + Thread.usleep (10000); + } + + // return & exit have the same effect + Thread.exit (42); + return 43; + } +} + +public static int main (string[] args) { + // Check whether threads are supported: + if (Thread.supported () == false) { + stderr.printf ("Threads are not supported!\n"); + return -1; + } + + try { + // Start a thread: + MyThread my_thread = new MyThread (10); + Thread thread = new Thread.try ("My fst. thread", my_thread.run); + + // Wait until thread finishes: + int result = thread.join (); + // Output: `Thread stopped! Return value: 42` + stdout.printf ("Thread stopped! Return value: %d\n", result); + } catch (Error e) { + stdout.printf ("Error: %s\n", e.message); + } + + return 0; +} diff --git a/test cases/vala/5 target glib/meson.build b/test cases/vala/5 target glib/meson.build new file mode 100644 index 000000000..1002abe8c --- /dev/null +++ b/test cases/vala/5 target glib/meson.build @@ -0,0 +1,6 @@ +project('valatest', 'vala', 'c') + +valadeps = [dependency('glib-2.0', version : '>=2.32'), dependency('gobject-2.0')] + +e = executable('valaprog', 'GLib.Thread.vala', dependencies : valadeps) +test('valatest', e)