meson: use gnome.mkenums() with template files for enum file gen
authorTim-Philipp Müller <tim@centricular.com>
Sat, 17 Dec 2016 14:35:19 +0000 (14:35 +0000)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 22 Dec 2016 11:35:04 +0000 (11:35 +0000)
Saves us a custom script. Template files are nicer than passing
multiline templating stuff through to glib-mkenums. And we can
get rid of our custom python script.

gst/build_mkenum.py [deleted file]
gst/gstenumtypes.c.template [new file with mode: 0644]
gst/gstenumtypes.h.template [new file with mode: 0644]
gst/meson.build

diff --git a/gst/build_mkenum.py b/gst/build_mkenum.py
deleted file mode 100755 (executable)
index 42940cb..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/usr/bin/env python3
-
-# This is in its own file rather than inside meson.build
-# because a) mixing the two is ugly and b) trying to
-# make special characters such as \n go through all
-# backends is a fool's errand.
-
-import sys, os, shutil, subprocess
-
-h_array = ['--fhead',
-           "#ifndef __GST_ENUM_TYPES_H__\n#define __GST_ENUM_TYPES_H__\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n",
-           '--fprod',
-           "\n/* enumerations from \"@filename@\" */\n",
-           '--vhead',
-           "GType @enum_name@_get_type (void);\n#define GST_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n",
-           '--ftail',
-           "G_END_DECLS\n\n#endif /* __GST_ENUM_TYPES_H__ */"]
-
-c_array = [
-    '--fhead',
-    "#include \"gst_private.h\"\n#include <gst/gst.h>\n#define C_ENUM(v) ((gint) v)\n#define C_FLAGS(v) ((guint) v)\n ",
-    '--fprod',
-    "\n/* enumerations from \"@filename@\" */",
-    '--vhead',
-    "GType\n@enum_name@_get_type (void)\n{\n  static gsize id = 0;\n  static const G@Type@Value values[] = {",
-    '--vprod',
-    "    { C_@TYPE@(@VALUENAME@), \"@VALUENAME@\", \"@valuenick@\" },",
-    '--vtail',
-    "    { 0, NULL, NULL }\n  };\n\n  if (g_once_init_enter (&id)) {\n    GType tmp = g_@type@_register_static (\"@EnumName@\", values);\n    g_once_init_leave (&id, tmp);\n  }\n\n  return (GType) id;\n}"
-    ]
-
-cmd = []
-argn = 1
-# Find the full command needed to run glib-mkenums
-# On UNIX-like, this is just the full path to glib-mkenums
-# On Windows, this is the full path to interpreter + full path to glib-mkenums
-for arg in sys.argv[1:]:
-    cmd.append(arg)
-    argn += 1
-    if arg.endswith('glib-mkenums'):
-        break
-ofilename = sys.argv[argn]
-headers = sys.argv[argn + 1:]
-
-if ofilename.endswith('.h'):
-    arg_array = h_array
-else:
-    arg_array = c_array
-
-pc = subprocess.Popen(cmd + arg_array + headers, stdout=subprocess.PIPE)
-(stdo, _) = pc.communicate()
-if pc.returncode != 0:
-    sys.exit(pc.returncode)
-open(ofilename, 'wb').write(stdo)
diff --git a/gst/gstenumtypes.c.template b/gst/gstenumtypes.c.template
new file mode 100644 (file)
index 0000000..1bb7506
--- /dev/null
@@ -0,0 +1,41 @@
+/*** BEGIN file-header ***/
+#include "gst/gst_private.h"
+#include <gst/gst.h>
+#define C_ENUM(v) ((gint) v)
+#define C_FLAGS(v) ((guint) v)
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@basename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+@enum_name@_get_type (void)
+{
+  static gsize id = 0;
+  static const G@Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+    { C_@TYPE@(@VALUENAME@), "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+    { 0, NULL, NULL }
+  };
+
+  if (g_once_init_enter (&id)) {
+    GType tmp = g_@type@_register_static ("@EnumName@", values);
+    g_once_init_leave (&id, tmp);
+  }
+
+  return (GType) id;
+}
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+
+/*** END file-tail ***/
diff --git a/gst/gstenumtypes.h.template b/gst/gstenumtypes.h.template
new file mode 100644 (file)
index 0000000..aa4c797
--- /dev/null
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+#ifndef __GST_ENUM_TYPES_H__
+#define __GST_ENUM_TYPES_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);
+#define @ENUMPREFIX@_TYPE_@ENUMSHORT@ (@enum_name@_get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __GST_ENUM_TYPES_H__ */
+/*** END file-tail ***/
index 42d6368..f2af393 100644 (file)
@@ -163,21 +163,16 @@ configure_file(input : 'gstversion.h.in',
   install_dir : 'include/gstreamer-1.0/gst',
   configuration : cdata)
 
-mkenums = find_program('build_mkenum.py')
-glib_mkenums = find_program('glib-mkenums')
+gst_enums = gnome.mkenums('gstenumtypes',
+  sources : gst_headers,
+  h_template : 'gstenumtypes.h.template',
+  c_template : 'gstenumtypes.c.template',
+  install_header : true,
+  install_dir : join_paths(get_option('includedir'), 'gstreamer-1.0/gst'))
 
-gstenum_h = custom_target('gstenum_h',
-  output : 'gstenumtypes.h',
-  input : gst_headers,
-  install : true,
-  install_dir : 'include/gstreamer-1.0/gst',
-  command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
+gstenum_h = gst_enums[0]
+gstenum_c = gst_enums[1]
 
-gstenum_c = custom_target('gstenum_c',
-  output : 'gstenumtypes.c',
-  input : gst_headers,
-  depends : [gstenum_h],
-  command : [mkenums, glib_mkenums, '@OUTPUT@', '@INPUT@'])
 
 subdir('parse')
 subdir('printf')