Add support for glib-mkenums to gnome module.

pull/718/head
Elliott Sales de Andrade 9 years ago
parent 0a4957627a
commit ab004ab189
  1. 47
      mesonbuild/modules/gnome.py
  2. 1
      test cases/frameworks/7 gnome/installed_files.txt
  3. 2
      test cases/frameworks/7 gnome/meson.build
  4. 41
      test cases/frameworks/7 gnome/mkenums/enums.c.in
  5. 24
      test cases/frameworks/7 gnome/mkenums/enums.h.in
  6. 30
      test cases/frameworks/7 gnome/mkenums/main.c
  7. 18
      test cases/frameworks/7 gnome/mkenums/meson-sample.h
  8. 14
      test cases/frameworks/7 gnome/mkenums/meson.build

@ -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()

@ -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

@ -13,4 +13,4 @@ subdir('resources')
subdir('gir')
subdir('schemas')
subdir('gdbus')
subdir('mkenums')

@ -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 ***/

@ -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 ***/

@ -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;
}

@ -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;

@ -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)
Loading…
Cancel
Save