diff options
author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2016-08-25 01:42:40 -0400 |
---|---|---|
committer | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2016-09-28 18:20:17 -0400 |
commit | ab004ab1895b562af6dd16d396327b2ae2b52dd0 (patch) | |
tree | 14bc24b9f192e2b196a499e83b02150c30e34939 | |
parent | 0a4957627a1e7bc88a74e9398fdf3b6e17cd7b05 (diff) | |
download | meson-ab004ab1895b562af6dd16d396327b2ae2b52dd0.zip meson-ab004ab1895b562af6dd16d396327b2ae2b52dd0.tar.gz meson-ab004ab1895b562af6dd16d396327b2ae2b52dd0.tar.bz2 |
Add support for glib-mkenums to gnome module.
-rw-r--r-- | mesonbuild/modules/gnome.py | 47 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/installed_files.txt | 1 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/meson.build | 2 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums.c.in | 41 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/enums.h.in | 24 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/main.c | 30 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/meson-sample.h | 18 | ||||
-rw-r--r-- | test cases/frameworks/7 gnome/mkenums/meson.build | 14 |
8 files changed, 176 insertions, 1 deletions
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index 11abf88..6a190b7 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -473,6 +473,53 @@ class GnomeModule: } return build.CustomTarget(namebase + '-gdbus', state.subdir, custom_kwargs) + def mkenums(self, state, args, kwargs): + if len(args) != 1: + raise MesonException('Mkenums 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-mkenums'] + known_kwargs = ['comments', 'eprod', 'fhead', 'fprod', 'ftail', + 'identifier-prefix', 'symbol-prefix', 'template', + 'vhead', 'vprod', 'vtail'] + known_custom_target_kwargs = ['install', 'install_dir', 'build_always', + 'depends', 'depend_files'] + add_template = False + for arg, value in kwargs.items(): + if arg == 'template': + add_template = True + sources = [value] + sources + elif arg in known_kwargs: + cmd += ['--' + arg, value] + elif arg not in known_custom_target_kwargs: + raise MesonException( + 'Mkenums does not take a %s keyword argument.' % (arg, )) + if add_template: + cmd += ['--template', '@INPUT@'] + else: + 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/installed_files.txt b/test cases/frameworks/7 gnome/installed_files.txt index 741d9b8..5199a10 100644 --- a/test cases/frameworks/7 gnome/installed_files.txt +++ b/test cases/frameworks/7 gnome/installed_files.txt @@ -1,3 +1,4 @@ +usr/include/enums.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 6afe508..50b9856 100644 --- a/test cases/frameworks/7 gnome/meson.build +++ b/test cases/frameworks/7 gnome/meson.build @@ -13,4 +13,4 @@ subdir('resources') subdir('gir') subdir('schemas') subdir('gdbus') - +subdir('mkenums') diff --git a/test cases/frameworks/7 gnome/mkenums/enums.c.in b/test cases/frameworks/7 gnome/mkenums/enums.c.in new file mode 100644 index 0000000..62e1adc --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums.c.in @@ -0,0 +1,41 @@ +/*** BEGIN file-header ***/ + +#include "enums.h" + +/*** END file-header ***/ +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +#include "@basename@" + +/*** END file-production ***/ + +/*** BEGIN value-header ***/ +GType +@enum_name@_get_type(void) { + static volatile gsize g_define_type_id__volatile = 0; + + if(g_once_init_enter(&g_define_type_id__volatile)) { + static const G@Type@Value values [] = { +/*** END value-header ***/ + +/*** BEGIN value-production ***/ + { @VALUENAME@, "@VALUENAME@", "@valuenick@" }, +/*** END value-production ***/ + +/*** BEGIN value-tail ***/ + { 0, NULL, NULL } + }; + + GType g_define_type_id = + g_@type@_register_static(g_intern_static_string("@EnumName@"), values); + g_once_init_leave(&g_define_type_id__volatile, g_define_type_id); + } + + return g_define_type_id__volatile; +} + +/*** END value-tail ***/ + +/*** BEGIN file-tail ***/ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/enums.h.in b/test cases/frameworks/7 gnome/mkenums/enums.h.in new file mode 100644 index 0000000..479867f --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums.h.in @@ -0,0 +1,24 @@ +/*** BEGIN file-header ***/ +#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include <glib-object.h> + +G_BEGIN_DECLS +/*** END file-header ***/ + +/*** BEGIN file-production ***/ + +/* enumerations from "@basename@" */ +/*** END file-production ***/ +/*** BEGIN value-header ***/ +GType @enum_name@_get_type(void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +/*** END value-header ***/ + +/*** BEGIN file-tail ***/ + +G_END_DECLS + +#endif /* MESON_ENUMS_H */ +/*** END file-tail ***/ diff --git a/test cases/frameworks/7 gnome/mkenums/main.c b/test cases/frameworks/7 gnome/mkenums/main.c new file mode 100644 index 0000000..52e5461 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/main.c @@ -0,0 +1,30 @@ +#include<stdio.h> +#include<string.h> +#include<glib-object.h> +#include"meson-sample.h" +#include"enums.h" + +int main(int argc, char **argv) { + GEnumClass *xenum = g_type_class_ref(MESON_TYPE_THE_XENUM); + GFlagsClass *flags_enum = g_type_class_ref(MESON_TYPE_THE_FLAGS_ENUM); + if (g_enum_get_value_by_name(xenum, "MESON_THE_XVALUE")->value != MESON_THE_XVALUE) { + fprintf(stderr, "Get MESON_THE_XVALUE by name failed.\n"); + return 1; + } + if (g_enum_get_value_by_nick(xenum, "the-xvalue")->value != MESON_THE_XVALUE) { + fprintf(stderr, "Get MESON_THE_XVALUE by nick failed.\n"); + return 2; + } + if (g_flags_get_value_by_name(flags_enum, "MESON_THE_FIRST_VALUE")->value != MESON_THE_FIRST_VALUE) { + fprintf(stderr, "Get MESON_THE_FIRST_VALUE by name failed.\n"); + return 3; + } + if (g_flags_get_value_by_nick(flags_enum, "the-first-value")->value != MESON_THE_FIRST_VALUE) { + fprintf(stderr, "Get MESON_THE_FIRST_VALUE by nick failed.\n"); + return 4; + } + g_type_class_unref(xenum); + g_type_class_unref(flags_enum); + fprintf(stderr, "All ok.\n"); + return 0; +} diff --git a/test cases/frameworks/7 gnome/mkenums/meson-sample.h b/test cases/frameworks/7 gnome/mkenums/meson-sample.h new file mode 100644 index 0000000..51e5421 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/meson-sample.h @@ -0,0 +1,18 @@ +typedef enum +{ + MESON_THE_XVALUE, + MESON_ANOTHER_VALUE +} MesonTheXEnum; + +typedef enum /*< skip >*/ +{ + MESON_FOO +} MesonThisEnumWillBeSkipped; + +typedef enum /*< flags,prefix=MESON >*/ +{ + MESON_THE_ZEROTH_VALUE, /*< skip >*/ + MESON_THE_FIRST_VALUE, + MESON_THE_SECOND_VALUE, + MESON_THE_THIRD_VALUE, /*< nick=the-last-value >*/ +} MesonTheFlagsEnum; diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build new file mode 100644 index 0000000..db2e717 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -0,0 +1,14 @@ +enums_h = gnome.mkenums('enums.h', +sources : 'meson-sample.h', +template : 'enums.h.in', +install : true, +install_dir : get_option('includedir')) + +enums_c = gnome.mkenums('enums.c', +sources : 'meson-sample.h', +template : 'enums.c.in', +depends : enums_h) + +enumexe = executable('enumprog', 'main.c', enums_c, enums_h, +dependencies : gobj) +test('enum test', enumexe) |