From 8f024c06970dcaec1564516c4583ae8543713ea8 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 28 Sep 2016 18:18:00 -0400 Subject: [PATCH] Allow running mkenums without templates. --- mesonbuild/modules/gnome.py | 67 ++++++---- .../frameworks/7 gnome/installed_files.txt | 2 + .../frameworks/7 gnome/mkenums/enums2.c.in | 41 +++++++ .../frameworks/7 gnome/mkenums/enums2.h.in | 24 ++++ test cases/frameworks/7 gnome/mkenums/main.c | 2 +- .../frameworks/7 gnome/mkenums/meson.build | 115 +++++++++++++++++- 6 files changed, 224 insertions(+), 27 deletions(-) create mode 100644 test cases/frameworks/7 gnome/mkenums/enums2.c.in create mode 100644 test cases/frameworks/7 gnome/mkenums/enums2.h.in diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index e2333a8dd..f3baeca21 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -477,8 +477,6 @@ class GnomeModule: if len(args) != 1: raise MesonException('Mkenums requires one positional argument.') basename = args[0] - c_target_name = basename + '_c' - h_target_hame = basename + '_h' if 'sources' not in kwargs: raise MesonException('Missing keyword argument "sources".') @@ -511,30 +509,57 @@ class GnomeModule: elif arg not in known_custom_target_kwargs: raise MesonException( 'Mkenums does not take a %s keyword argument.' % (arg, )) - if c_template is None or h_template is None: - raise MesonException('Must specify both a C and H template.') - # We always set template as the first element in the source array so - # --template consumes it. - cmd = ['glib-mkenums', '--template', '@INPUT@'] + cmd + cmd = ['glib-mkenums'] + cmd custom_kwargs = {} for arg in known_custom_target_kwargs: if arg in kwargs: custom_kwargs[arg] = kwargs[arg] - c_output = os.path.splitext(c_template)[0] - h_output = os.path.splitext(h_template)[0] - - c_sources = [c_template] + sources - h_sources = [h_template] + sources - - custom_kwargs['install'] = install_header - if 'install_dir' not in custom_kwargs: - custom_kwargs['install_dir'] = state.environment.coredata.get_builtin_option('includedir') - h_target = self.make_mkenum_custom_target(state, h_sources, h_output, cmd, custom_kwargs) - custom_kwargs['install'] = False # Never install the C file. Complain on bug tracker if you need this. - custom_kwargs['depends'] = h_target - c_target = self.make_mkenum_custom_target(state, c_sources, c_output, cmd, custom_kwargs) - return [c_target, h_target] + targets = [] + + if h_template is not None: + h_output = os.path.splitext(h_template)[0] + # We always set template as the first element in the source array + # so --template consumes it. + h_cmd = cmd + ['--template', '@INPUT@'] + h_sources = [h_template] + sources + custom_kwargs['install'] = install_header + if 'install_dir' not in custom_kwargs: + custom_kwargs['install_dir'] = \ + state.environment.coredata.get_builtin_option('includedir') + h_target = self.make_mkenum_custom_target(state, h_sources, + h_output, h_cmd, + custom_kwargs) + targets.append(h_target) + + if c_template is not None: + c_output = os.path.splitext(c_template)[0] + # We always set template as the first element in the source array + # so --template consumes it. + c_cmd = cmd + ['--template', '@INPUT@'] + c_sources = [c_template] + sources + # Never install the C file. Complain on bug tracker if you need it. + custom_kwargs['install'] = False + if h_template is not None: + custom_kwargs['depends'] = h_target + c_target = self.make_mkenum_custom_target(state, c_sources, + c_output, c_cmd, + custom_kwargs) + targets.insert(0, c_target) + + if c_template is None and h_template is None: + generic_cmd = cmd + ['@INPUT@'] + custom_kwargs['install'] = install_header + if 'install_dir' not in custom_kwargs: + custom_kwargs['install_dir'] = \ + state.environment.coredata.get_builtin_option('includedir') + target = self.make_mkenum_custom_target(state, sources, basename, + generic_cmd, custom_kwargs) + return target + elif len(targets) == 1: + return targets[0] + else: + return targets def make_mkenum_custom_target(self, state, sources, output, cmd, kwargs): custom_kwargs = { diff --git a/test cases/frameworks/7 gnome/installed_files.txt b/test cases/frameworks/7 gnome/installed_files.txt index ad802a0c8..c922f8baf 100644 --- a/test cases/frameworks/7 gnome/installed_files.txt +++ b/test cases/frameworks/7 gnome/installed_files.txt @@ -1,4 +1,6 @@ usr/include/enums.h +usr/include/enums2.h +usr/include/enums3.h usr/include/marshaller.h usr/lib/girepository-1.0/Meson-1.0.typelib usr/lib/libgirlib.so diff --git a/test cases/frameworks/7 gnome/mkenums/enums2.c.in b/test cases/frameworks/7 gnome/mkenums/enums2.c.in new file mode 100644 index 000000000..62e1adcb4 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums2.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/enums2.h.in b/test cases/frameworks/7 gnome/mkenums/enums2.h.in new file mode 100644 index 000000000..479867fd1 --- /dev/null +++ b/test cases/frameworks/7 gnome/mkenums/enums2.h.in @@ -0,0 +1,24 @@ +/*** BEGIN file-header ***/ +#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include + +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 index 52e546175..d257185dd 100644 --- a/test cases/frameworks/7 gnome/mkenums/main.c +++ b/test cases/frameworks/7 gnome/mkenums/main.c @@ -2,7 +2,7 @@ #include #include #include"meson-sample.h" -#include"enums.h" +#include"@ENUM_FILE@" int main(int argc, char **argv) { GEnumClass *xenum = g_type_class_ref(MESON_TYPE_THE_XENUM); diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build index dbb8793a7..f0989cf16 100644 --- a/test cases/frameworks/7 gnome/mkenums/meson.build +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -1,13 +1,118 @@ -myenums = gnome.mkenums('abc', +# Generate both header and source via template together. + +myenums = gnome.mkenums('abc1', sources : 'meson-sample.h', h_template : 'enums.h.in', c_template : 'enums.c.in', install_header : true, install_dir : get_option('includedir')) -enums_c = myenums[0] -enums_h = myenums[1] +enums_c1 = myenums[0] +enums_h1 = myenums[1] + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums.h') +main = configure_file( + input : 'main.c', + output : 'main1.c', + configuration : conf) + +enumexe1 = executable('enumprog1', main, enums_c1, enums_h1, +dependencies : gobj) +test('enum test 1', enumexe1) + +# Generate both header and source via template individually and overriding. + +enums_c2 = gnome.mkenums('abc2', + sources : 'meson-sample.h', + c_template : 'enums2.c.in', + ftail : '/* trailing source file info */', + install_header : true, + install_dir : get_option('includedir')) + +enums_h2 = gnome.mkenums('abc2', + sources : 'meson-sample.h', + h_template : 'enums2.h.in', + ftail : '/* trailing header file info */', + install_header : true, + install_dir : get_option('includedir')) + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums2.h') +main = configure_file( + input : 'main.c', + output : 'main2.c', + configuration : conf) + +enumexe2 = executable('enumprog2', main, enums_c2, enums_h2, +dependencies : gobj) +test('enum test 2', enumexe2) + +# Generate both header and source by options only. +# These are specified in a way that should produce the same result as above +# (modulo any filename changes.) + +enums_h3 = gnome.mkenums('enums3.h', + sources : 'meson-sample.h', + fhead : '''#ifndef MESON_ENUMS_H +#define MESON_ENUMS_H + +#include + +G_BEGIN_DECLS +''', + fprod : ''' +/* enumerations from "@basename@" */ +''', + vhead : '''GType @enum_name@_get_type(void) G_GNUC_CONST; +#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type()) +''', + ftail : ''' +G_END_DECLS + +#endif /* MESON_ENUMS_H */ +''', + install_header : true, + install_dir : get_option('includedir')) + +enums_c3 = gnome.mkenums('enums3.c', + sources : 'meson-sample.h', + depends : enums_h3, + fhead : '''#include "enums3.h" +''', + fprod : ''' + +/* enumerations from "@basename@" */ +#include "@basename@" +''', + vhead : ''' +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 [] = { +''', + vprod : ''' { @VALUENAME@, "@VALUENAME@", "@valuenick@" },''', + vtail : ''' { 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; +} +''') + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums3.h') +main = configure_file( + input : 'main.c', + output : 'main3.c', + configuration : conf) -enumexe = executable('enumprog', 'main.c', enums_c, enums_h, +enumexe3 = executable('enumprog3', main, enums_c3, enums_h3, dependencies : gobj) -test('enum test', enumexe) +test('enum test 3', enumexe3)