summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Sales de Andrade <quantum.analyst@gmail.com>2016-08-25 04:20:46 -0400
committerElliott Sales de Andrade <quantum.analyst@gmail.com>2016-09-28 18:20:18 -0400
commit2a8a0727fcf84fa0bb8d4b4eb095594976b30ef9 (patch)
tree2912ab3522b5882b682fabed7d0ba699fd42dc42
parentab004ab1895b562af6dd16d396327b2ae2b52dd0 (diff)
downloadmeson-2a8a0727fcf84fa0bb8d4b4eb095594976b30ef9.tar.gz
Add support for glib-genmarshal to gnome module.
-rw-r--r--mesonbuild/modules/gnome.py42
-rw-r--r--test cases/frameworks/7 gnome/genmarshal/main.c102
-rw-r--r--test cases/frameworks/7 gnome/genmarshal/marshaller.list3
-rw-r--r--test cases/frameworks/7 gnome/genmarshal/meson.build13
-rw-r--r--test cases/frameworks/7 gnome/installed_files.txt1
-rw-r--r--test cases/frameworks/7 gnome/meson.build1
6 files changed, 162 insertions, 0 deletions
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 6a190b765..5f0f737e0 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -519,6 +519,48 @@ class GnomeModule:
custom_kwargs[arg] = kwargs[arg]
return build.CustomTarget(output, state.subdir, custom_kwargs)
+ def genmarshal(self, state, args, kwargs):
+ if len(args) != 1:
+ raise MesonException(
+ 'Genmarshal requires one positional argument.')
+ output = args[0]
+
+ if 'sources' not in kwargs:
+ raise MesonException('Missing keyword argument "sources".')
+ sources = kwargs.pop('sources')
+ if isinstance(sources, str):
+ sources = [sources]
+ elif not isinstance(sources, list):
+ raise MesonException(
+ 'Sources keyword argument must be a string or array.')
+
+ cmd = ['glib-genmarshal']
+ known_kwargs = ['body', 'header', 'internal', 'nostdinc',
+ 'skip-source', 'stdinc', 'valist-marshallers']
+ known_custom_target_kwargs = ['install', 'install_dir', 'build_always',
+ 'depends', 'depend_files']
+ for arg, value in kwargs.items():
+ if arg == 'prefix':
+ cmd += ['--prefix', value]
+ elif arg in known_kwargs and value:
+ cmd += ['--' + arg]
+ elif arg not in known_custom_target_kwargs:
+ raise MesonException(
+ 'Genmarshal does not take a %s keyword argument.' % (
+ arg, ))
+ cmd += ['@INPUT@']
+
+ custom_kwargs = {
+ 'input': sources,
+ 'output': output,
+ 'capture': True,
+ 'command': cmd
+ }
+ for arg in known_custom_target_kwargs:
+ if arg in kwargs:
+ custom_kwargs[arg] = kwargs[arg]
+ return build.CustomTarget(output, state.subdir, custom_kwargs)
+
def initialize():
return GnomeModule()
diff --git a/test cases/frameworks/7 gnome/genmarshal/main.c b/test cases/frameworks/7 gnome/genmarshal/main.c
new file mode 100644
index 000000000..83b08af17
--- /dev/null
+++ b/test cases/frameworks/7 gnome/genmarshal/main.c
@@ -0,0 +1,102 @@
+#include<stdio.h>
+#include<stdlib.h>
+#include<glib-object.h>
+#include"marshaller.h"
+
+static int singleton = 42;
+
+void foo(gpointer user_data, gpointer data) {
+ if (user_data != &singleton) {
+ fprintf(stderr, "Invoked foo function was passed incorrect user data.\n");
+ exit(1);
+ }
+}
+
+void bar(gpointer user_data, gint param1, gpointer data) {
+ if (param1 != singleton) {
+ fprintf(stderr, "Invoked bar function was passed incorrect param1, but %d.\n", param1);
+ exit(2);
+ }
+ if (user_data != &singleton) {
+ fprintf(stderr, "Invoked bar function was passed incorrect user data.\n");
+ exit(3);
+ }
+}
+
+gfloat baz(gpointer user_data, gboolean param1, guchar param2, gpointer data) {
+ if (param1 != TRUE) {
+ fprintf(stderr, "Invoked baz function was passed incorrect param1.\n");
+ exit(4);
+ }
+ if (param2 != singleton) {
+ fprintf(stderr, "Invoked baz function was passed incorrect param2.\n");
+ exit(5);
+ }
+ if (user_data != &singleton) {
+ fprintf(stderr, "Invoked baz function was passed incorrect user data.\n");
+ exit(6);
+ }
+ return (gfloat)param2;
+}
+
+int main(int argc, char **argv) {
+ GClosure *cc_foo, *cc_bar, *cc_baz;
+ GValue return_value = G_VALUE_INIT;
+ GValue param_values[3] = {G_VALUE_INIT, G_VALUE_INIT, G_VALUE_INIT};
+
+ fprintf(stderr, "Invoking foo function.\n");
+ cc_foo = g_cclosure_new(G_CALLBACK(foo), NULL, NULL);
+ g_closure_set_marshal(cc_foo, g_cclosure_user_marshal_VOID__VOID);
+ g_value_init(&param_values[0], G_TYPE_POINTER);
+ g_value_set_pointer(&param_values[0], &singleton);
+ g_closure_invoke(cc_foo, &return_value, 1, param_values, NULL);
+ if (G_VALUE_TYPE(&return_value) != G_TYPE_INVALID) {
+ fprintf(stderr, "Invoked foo function did not return empty value, but %s.\n",
+ G_VALUE_TYPE_NAME(&return_value));
+ return 7;
+ }
+ g_value_unset(&param_values[0]);
+ g_value_unset(&return_value);
+ g_closure_unref(cc_foo);
+
+ fprintf(stderr, "Invoking bar function.\n");
+ cc_bar = g_cclosure_new(G_CALLBACK(bar), NULL, NULL);
+ g_closure_set_marshal(cc_bar, g_cclosure_user_marshal_VOID__INT);
+ g_value_init(&param_values[0], G_TYPE_POINTER);
+ g_value_set_pointer(&param_values[0], &singleton);
+ g_value_init(&param_values[1], G_TYPE_INT);
+ g_value_set_int(&param_values[1], 42);
+ g_closure_invoke(cc_bar, &return_value, 2, param_values, NULL);
+ if (G_VALUE_TYPE(&return_value) != G_TYPE_INVALID) {
+ fprintf(stderr, "Invoked bar function did not return empty value.\n");
+ return 8;
+ }
+ g_value_unset(&param_values[0]);
+ g_value_unset(&param_values[1]);
+ g_value_unset(&return_value);
+ g_closure_unref(cc_bar);
+
+ fprintf(stderr, "Invoking baz function.\n");
+ cc_baz = g_cclosure_new(G_CALLBACK(baz), NULL, NULL);
+ g_closure_set_marshal(cc_baz, g_cclosure_user_marshal_FLOAT__BOOLEAN_UCHAR);
+ g_value_init(&param_values[0], G_TYPE_POINTER);
+ g_value_set_pointer(&param_values[0], &singleton);
+ g_value_init(&param_values[1], G_TYPE_BOOLEAN);
+ g_value_set_boolean(&param_values[1], TRUE);
+ g_value_init(&param_values[2], G_TYPE_UCHAR);
+ g_value_set_uchar(&param_values[2], 42);
+ g_value_init(&return_value, G_TYPE_FLOAT);
+ g_closure_invoke(cc_baz, &return_value, 3, param_values, NULL);
+ if (g_value_get_float(&return_value) != 42.0f) {
+ fprintf(stderr, "Invoked baz function did not return expected value.\n");
+ return 9;
+ }
+ g_value_unset(&param_values[0]);
+ g_value_unset(&param_values[1]);
+ g_value_unset(&param_values[2]);
+ g_value_unset(&return_value);
+ g_closure_unref(cc_baz);
+
+ fprintf(stderr, "All ok.\n");
+ return 0;
+}
diff --git a/test cases/frameworks/7 gnome/genmarshal/marshaller.list b/test cases/frameworks/7 gnome/genmarshal/marshaller.list
new file mode 100644
index 000000000..a29f6c9de
--- /dev/null
+++ b/test cases/frameworks/7 gnome/genmarshal/marshaller.list
@@ -0,0 +1,3 @@
+VOID:VOID
+VOID:INT
+FLOAT:BOOLEAN,UCHAR
diff --git a/test cases/frameworks/7 gnome/genmarshal/meson.build b/test cases/frameworks/7 gnome/genmarshal/meson.build
new file mode 100644
index 000000000..8cebb8500
--- /dev/null
+++ b/test cases/frameworks/7 gnome/genmarshal/meson.build
@@ -0,0 +1,13 @@
+marshaller_h = gnome.genmarshal('marshaller.h',
+sources : 'marshaller.list',
+header : true,
+install : true,
+install_dir : get_option('includedir'))
+
+marshaller_c = gnome.genmarshal('marshaller.c',
+sources : 'marshaller.list',
+body : true)
+
+genmarshalexe = executable('genmarshalprog', 'main.c', marshaller_c, marshaller_h,
+dependencies : gobj)
+test('genmarshal test', genmarshalexe)
diff --git a/test cases/frameworks/7 gnome/installed_files.txt b/test cases/frameworks/7 gnome/installed_files.txt
index 5199a102e..ad802a0c8 100644
--- a/test cases/frameworks/7 gnome/installed_files.txt
+++ b/test cases/frameworks/7 gnome/installed_files.txt
@@ -1,4 +1,5 @@
usr/include/enums.h
+usr/include/marshaller.h
usr/lib/girepository-1.0/Meson-1.0.typelib
usr/lib/libgirlib.so
usr/share/gir-1.0/Meson-1.0.gir
diff --git a/test cases/frameworks/7 gnome/meson.build b/test cases/frameworks/7 gnome/meson.build
index 50b98563c..2c2e953d9 100644
--- a/test cases/frameworks/7 gnome/meson.build
+++ b/test cases/frameworks/7 gnome/meson.build
@@ -14,3 +14,4 @@ subdir('gir')
subdir('schemas')
subdir('gdbus')
subdir('mkenums')
+subdir('genmarshal')