From 6dd896d0014138c5eea194dc0f5bde658c286074 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Thu, 17 May 2018 00:49:08 +0200 Subject: [PATCH 1/2] gnome/mkenums: allow passing generated files as templates --- mesonbuild/modules/gnome.py | 8 ++++++-- .../frameworks/7 gnome/mkenums/meson.build | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py index da72a1fff..ea8ff3f83 100644 --- a/mesonbuild/modules/gnome.py +++ b/mesonbuild/modules/gnome.py @@ -1014,12 +1014,16 @@ This will become a hard error in the future.''') raise AssertionError("sources should've already been handled") elif arg == 'c_template': c_template = value + if isinstance(c_template, mesonlib.File): + c_template = c_template.absolute_path(state.environment.source_dir, state.environment.build_dir) if 'template' in kwargs: raise MesonException('Mkenums does not accept both ' 'c_template and template keyword ' 'arguments at the same time.') elif arg == 'h_template': h_template = value + if isinstance(h_template, mesonlib.File): + h_template = h_template.absolute_path(state.environment.source_dir, state.environment.build_dir) if 'template' in kwargs: raise MesonException('Mkenums does not accept both ' 'h_template and template keyword ' @@ -1040,7 +1044,7 @@ This will become a hard error in the future.''') targets = [] if h_template is not None: - h_output = os.path.splitext(h_template)[0] + h_output = os.path.basename(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@'] @@ -1055,7 +1059,7 @@ This will become a hard error in the future.''') targets.append(h_target) if c_template is not None: - c_output = os.path.splitext(c_template)[0] + c_output = os.path.basename(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@'] diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build index ff3161991..3db4d63da 100644 --- a/test cases/frameworks/7 gnome/mkenums/meson.build +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -127,3 +127,19 @@ enums5 = gnome.mkenums_simple('enums5', sources : 'meson-sample.h', decorator : 'MESON_EXPORT', header_prefix : '#include "meson-decls.h"') enumexe5 = executable('enumprog5', main, enums5, dependencies : gobj) + +# Generate template then use as input to mkenums + +# Simple trick to copy the file without substitutions, can be +# removed when https://github.com/mesonbuild/meson/pull/3383 is fixed +gen_h_template = configure_file(input: 'enums2.h.in', + output: 'enums2-tmp.h.in', + configuration: configuration_data(), + format: 'cmake') + +enums_h3 = gnome.mkenums('abc3', + sources : 'meson-sample.h', + h_template : gen_h_template, + ftail : '/* trailing header file info */', + install_header : true, + install_dir : get_option('includedir')) From 9a0e380525cfa3bf509888a1694aaf60218705e6 Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 23 May 2018 23:22:42 +0200 Subject: [PATCH 2/2] gnome.mkenums: test header built from generated template --- .../frameworks/7 gnome/mkenums/meson.build | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/test cases/frameworks/7 gnome/mkenums/meson.build b/test cases/frameworks/7 gnome/mkenums/meson.build index 3db4d63da..af4a9017e 100644 --- a/test cases/frameworks/7 gnome/mkenums/meson.build +++ b/test cases/frameworks/7 gnome/mkenums/meson.build @@ -132,14 +132,25 @@ enumexe5 = executable('enumprog5', main, enums5, dependencies : gobj) # Simple trick to copy the file without substitutions, can be # removed when https://github.com/mesonbuild/meson/pull/3383 is fixed -gen_h_template = configure_file(input: 'enums2.h.in', - output: 'enums2-tmp.h.in', +gen_h_template = configure_file(input: 'enums.h.in', + output: 'enums6.h.in', configuration: configuration_data(), format: 'cmake') -enums_h3 = gnome.mkenums('abc3', +enums_h6 = gnome.mkenums('enums6', sources : 'meson-sample.h', h_template : gen_h_template, ftail : '/* trailing header file info */', install_header : true, install_dir : get_option('includedir')) + +conf = configuration_data() +conf.set('ENUM_FILE', 'enums6.h') +main = configure_file( + input : 'main.c', + output : 'main6.c', + configuration : conf) + +enumexe6 = executable('enumprog6', main, enums_c2, enums_h6, +dependencies : gobj) +test('enum test 4', enumexe6)