[glib] meson: Simplify the use of built tools



commit 3c03cc8f68b5d81c7b47423b1a3be3b8c9197d1c
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Mon Jul 17 10:54:28 2017 +0100

    meson: Simplify the use of built tools
    
    The Meson build has fallen a bit behind the Autotools one, when it comes
    to the internally built tools like glib-mkenums and glib-genmarshals.
    
    We don't need to generate gmarshal.strings any more, and since the
    glib-genmarshal tool is now written in Python it can also be used when
    cross-compiling, and without indirection, just like we use glib-mkenums.
    
    We can also coalesce various rules into a simple array iteration, with
    minimal changes to glib-mkenums, thus making the build a bit more
    resilient and without unnecessary duplication.

 gobject/glib-mkenums.in               |   21 +++++-------
 gobject/gmarshal-list-to-strings.py   |   21 ------------
 gobject/meson.build                   |   43 ++++++++++++-------------
 gobject/tests/gobject_test_marshal.py |   21 ------------
 gobject/tests/meson.build             |   55 +++++++++++++++++++-------------
 meson.build                           |    1 +
 tests/gobject/meson.build             |    2 +-
 7 files changed, 65 insertions(+), 99 deletions(-)
---
diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in
index 6242561..9ae036b 100755
--- a/gobject/glib-mkenums.in
+++ b/gobject/glib-mkenums.in
@@ -15,6 +15,13 @@ import re
 import sys
 import tempfile
 
+VERSION_STR = '''glib-mkenums version @VERSION@
+glib-genmarshal comes with ABSOLUTELY NO WARRANTY.
+You may redistribute copies of glib-genmarshal under the terms of
+the GNU General Public License which can be found in the
+GLib source package. Sources, examples and contact
+information are available at http://www.gtk.org'''
+
 output_stream = sys.stdout
 
 # pylint: disable=too-few-public-methods
@@ -64,8 +71,6 @@ def write_output(output):
     global output_stream
     print(output, file=output_stream)
 
-version = '@GLIB_VERSION@'
-
 # glib-mkenums.py
 # Information about the current enumeration
 flags = False               # Is enumeration a bitmask?
@@ -190,15 +195,6 @@ def parse_entries(file, file_name):
             sys.exit("Failed to parse %s." % file_name)
     return False
 
-def print_version():
-    print("glib-mkenums version glib-" + version)
-    print("glib-mkenums comes with ABSOLUTELY NO WARRANTY.")
-    print("You may redistribute copies of glib-mkenums under the terms of")
-    print("the GNU General Public License which can be found in the")
-    print("GLib source package. Sources, examples and contact")
-    print("information are available at http://www.gtk.org";)
-    sys.exit(0)
-
 help_epilog = '''Production text substitutions:
   \u0040EnumName\u0040            PrefixTheXEnum
   \u0040enum_name\u0040           prefix_the_xenum
@@ -306,7 +302,8 @@ parser.add_argument('args', nargs='*')
 options = parser.parse_args()
 
 if options.version:
-    print_version()
+    print(VERSION_STR)
+    sys.exit(0)
 
 def unescape_cmdline_args(arg):
     arg = arg.replace('\\n', '\n')
diff --git a/gobject/meson.build b/gobject/meson.build
index 0e5cc43..0d39f2b 100644
--- a/gobject/meson.build
+++ b/gobject/meson.build
@@ -66,35 +66,34 @@ libgobject = shared_library('gobject-2.0',
 libgobject_dep = declare_dependency(link_with : libgobject,
   include_directories : gobjectinc)
 
-glib_mkenums_conf = configuration_data()
-glib_mkenums_conf.set('GLIB_VERSION', glib_version)
-glib_mkenums_conf.set('PYTHON', python.path())
+python_tools = [
+  'glib-genmarshal',
+  'glib-mkenums',
+]
 
-# FIXME: Set permissions
-glib_mkenums = configure_file(input : 'glib-mkenums.in',
-  output : 'glib-mkenums',
-  install : true,
-  install_dir : 'bin', configuration : glib_mkenums_conf)
+python_tools_conf = configuration_data()
+python_tools_conf.set('VERSION', glib_version)
+python_tools_conf.set('PYTHON', python.path())
+
+foreach tool: python_tools
+  # FIXME: Ensure we set the appropriate permissions
+  tool_bin = configure_file(
+    input : tool + '.in',
+    output : tool,
+    configuration : python_tools_conf,
+    install : true,
+    install_dir : glib_bindir,
+  )
+
+  # Set variables for later use
+  set_variable(tool.underscorify(), tool_bin)
+endforeach
 
 executable('gobject-query', 'gobject-query.c',
   install : true,
   c_args : ['-DHAVE_CONFIG_H=1'],
   dependencies : [libglib_dep, libgobject_dep])
 
-gmarshal_strings = custom_target('gmarshal.strings',
-    input : ['gmarshal-list-to-strings.py', 'gmarshal.list'],
-    output : ['gmarshal.strings'],
-    command : [python, '@INPUT0@', '@INPUT1@', '@OUTPUT@'])
-
-glib_genmarshal_conf = configuration_data()
-glib_genmarshal_conf.set('VERSION', glib_version)
-glib_genmarshal_conf.set('PYTHON', python.path())
-
-glib_genmarshal = configure_file(input : 'glib-genmarshal.in',
-  output : 'glib-genmarshal',
-  install : true,
-  install_dir : 'bin', configuration : glib_genmarshal_conf)
-
 install_data('gobject_gdb.py', install_dir : join_paths(glib_pkgdatadir, 'gdb'))
 gdb_conf = configuration_data()
 gdb_conf.set('datadir', glib_datadir)
diff --git a/gobject/tests/meson.build b/gobject/tests/meson.build
index 38002f2..3d99ef3 100644
--- a/gobject/tests/meson.build
+++ b/gobject/tests/meson.build
@@ -44,26 +44,37 @@ foreach test_name : gobject_tests
   test(test_name, exe, env : test_env)
 endforeach
 
-# The marshalers test requires running a binary, so we cannot build it when
-# cross-compiling
-if not meson.has_exe_wrapper()
-  genmarshal = find_program('gobject_test_marshal.py')
+marshalers_h = custom_target('marshalers_h',
+  output : 'marshalers.h',
+  input : 'marshalers.list',
+  command : [
+    python, glib_genmarshal,
+    '--prefix=test',
+    '--valist-marshallers',
+    '--output=@OUTPUT@',
+    '--quiet',
+    '--header',
+    '@INPUT@',
+  ],
+)
+marshalers_c = custom_target('marshalers_c',
+  output : 'marshalers.c',
+  input : 'marshalers.list',
+  command : [
+    python, glib_genmarshal,
+    '--prefix=test',
+    '--valist-marshallers',
+    '--include-header=marshalers.h',
+    '--output=@OUTPUT@',
+    '--quiet',
+    '--body',
+    '@INPUT@',
+  ],
+)
 
-  marshalers_h = custom_target('marshalers_h',
-    output : 'marshalers.h',
-    input : 'marshalers.list',
-    command : [genmarshal, glib_genmarshal, '@INPUT@', '@OUTPUT@'],
-  )
-  marshalers_c = custom_target('marshalers_c',
-    output : 'marshalers.c',
-    input : 'marshalers.list',
-    command : [genmarshal, glib_genmarshal, '@INPUT@', '@OUTPUT@'],
-  )
-
-  exe = executable('signals',
-      'signals.c', marshalers_h, marshalers_c,
-      c_args : ['-DHAVE_CONFIG_H=1', '-DG_LOG_DOMAIN="GLib-GObject"'],
-      dependencies : deps,
-  )
-  test('signals', exe, env : test_env)
-endif
+exe = executable('signals',
+    'signals.c', marshalers_h, marshalers_c,
+    c_args : ['-DHAVE_CONFIG_H=1', '-DG_LOG_DOMAIN="GLib-GObject"'],
+    dependencies : deps,
+)
+test('signals', exe, env : test_env)
diff --git a/meson.build b/meson.build
index bbb8138..8c82fb8 100644
--- a/meson.build
+++ b/meson.build
@@ -49,6 +49,7 @@ gmoduleinc = include_directories('gmodule')
 gioinc = include_directories('gio')
 
 glib_prefix = get_option('prefix')
+glib_bindir = join_paths(glib_prefix, get_option('bindir'))
 glib_libdir = join_paths(glib_prefix, get_option('libdir'))
 glib_datadir = join_paths(glib_prefix, get_option('datadir'))
 glib_pkgdatadir = join_paths(glib_datadir, 'glib-2.0')
diff --git a/tests/gobject/meson.build b/tests/gobject/meson.build
index e10a345..f406011 100644
--- a/tests/gobject/meson.build
+++ b/tests/gobject/meson.build
@@ -31,7 +31,7 @@ foreach t : gobject_tests
   test_timeout = t.get(3, 30)
 
   # FIXME? $(GLIB_DEBUG_FLAGS)
-  exe = executable(test_name, test_src,
+  exe = executable(test_name + '-gobject', test_src,
     c_args : test_cargs + test_extra_cargs + ['-DGLIB_DISABLE_DEPRECATION_WARNINGS'],
     dependencies : [libm, thread_dep, libglib_dep, libgobject_dep],
     install : false,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]