telepathy-qt: Tools: Update c-constants-gen from telepathy-glib

Alexandr Akulich kaffeine at kemper.freedesktop.org
Mon Sep 2 18:00:11 UTC 2019


Module: telepathy-qt
Branch: master
Commit: 7cee0637436ec8d5287fccadc88dad3fdb4680ca
URL:    http://cgit.freedesktop.org/telepathy/telepathy-qt/commit/?id=7cee0637436ec8d5287fccadc88dad3fdb4680ca

Author: Alexander Akulich <akulichalexander at gmail.com>
Date:   Fri Aug 30 01:16:17 2019 +0300

Tools: Update c-constants-gen from telepathy-glib

(output gtk-doc separately)

See commit 93c4e78ac4dbb31b2106da2835c47eeb3896d0a3 in telepathy-glib

---

 tests/lib/glib/future/extensions/CMakeLists.txt |  2 +-
 tools/c-constants-gen.py                        | 84 ++++++++++++++++---------
 2 files changed, 57 insertions(+), 29 deletions(-)

diff --git a/tests/lib/glib/future/extensions/CMakeLists.txt b/tests/lib/glib/future/extensions/CMakeLists.txt
index c415eeac..e92b6fbc 100644
--- a/tests/lib/glib/future/extensions/CMakeLists.txt
+++ b/tests/lib/glib/future/extensions/CMakeLists.txt
@@ -29,7 +29,7 @@ if(ENABLE_TP_GLIB_TESTS)
         COMMAND ${PYTHON_EXECUTABLE}
         ARGS ${CMAKE_SOURCE_DIR}/tools/c-constants-gen.py
              Future ${CMAKE_CURRENT_BINARY_DIR}/_gen/all.xml
-             > _gen/enums.h
+             > _gen/enums.h _gen/enums
         DEPENDS ${gen_all_xml}
                 ${CMAKE_SOURCE_DIR}/tools/c-constants-gen.py)
 
diff --git a/tools/c-constants-gen.py b/tools/c-constants-gen.py
index 8969ffdc..9467e436 100644
--- a/tools/c-constants-gen.py
+++ b/tools/c-constants-gen.py
@@ -1,23 +1,34 @@
-#!/usr/bin/python
+#!/usr/bin/env python2
 
 from sys import argv, stdout, stderr
 import xml.dom.minidom
 
+from libtpcodegen import file_set_contents, u
 from libglibcodegen import NS_TP, get_docstring, \
         get_descendant_text, get_by_path
 
 class Generator(object):
-    def __init__(self, prefix, dom):
+    def __init__(self, prefix, dom, output_base):
         self.prefix = prefix + '_'
         self.spec = get_by_path(dom, "spec")[0]
 
+        self.output_base = output_base
+        self.__header = []
+        self.__docs = []
+
     def __call__(self):
         self.do_header()
         self.do_body()
         self.do_footer()
 
+        file_set_contents(self.output_base + '.h', u('').join(self.__header).encode('utf-8'))
+        file_set_contents(self.output_base + '-gtk-doc.h', u('').join(self.__docs).encode('utf-8'))
+
     def write(self, code):
-        stdout.write(code.encode('utf-8'))
+        self.__header.append(code)
+
+    def d(self, code):
+        self.__docs.append(code)
 
     # Header
     def do_header(self):
@@ -54,25 +65,26 @@ extern "C" {
         value_prefix = flags.getAttribute('singular') or \
                        flags.getAttribute('value-prefix') or \
                        flags.getAttribute('name')
-        self.write("""\
+        self.d("""\
 /**
- *
-%s:
+ * %s:
 """ % (self.prefix + name).replace('_', ''))
         for flag in get_by_path(flags, 'flag'):
             self.do_gtkdoc(flag, value_prefix)
-        self.write(' *\n')
+        self.d(' *\n')
         docstrings = get_by_path(flags, 'docstring')
         if docstrings:
-            self.write("""\
+            self.d("""\
  * <![CDATA[%s]]>
  *
 """ % get_descendant_text(docstrings).replace('\n', ' '))
-        self.write("""\
+        self.d("""\
  * Bitfield/set of flags generated from the Telepathy specification.
  */
-typedef enum {
 """)
+
+        self.write("typedef enum /*< flags >*/ {\n")
+
         for flag in get_by_path(flags, 'flag'):
             self.do_val(flag, value_prefix)
         self.write("""\
@@ -87,40 +99,56 @@ typedef enum {
                        enum.getAttribute('name')
         name_plural = enum.getAttribute('plural') or \
                       enum.getAttribute('name') + 's'
-        self.write("""\
+        self.d("""\
 /**
- *
-%s:
+ * %s:
 """ % (self.prefix + name).replace('_', ''))
         vals = get_by_path(enum, 'enumvalue')
         for val in vals:
             self.do_gtkdoc(val, value_prefix)
-        self.write(' *\n')
+        self.d(' *\n')
         docstrings = get_by_path(enum, 'docstring')
         if docstrings:
-            self.write("""\
+            self.d("""\
  * <![CDATA[%s]]>
  *
 """ % get_descendant_text(docstrings).replace('\n', ' '))
-        self.write("""\
+        self.d("""\
  * Bitfield/set of flags generated from the Telepathy specification.
  */
-typedef enum {
 """)
+
+        self.write("typedef enum {\n")
+
         for val in vals:
             self.do_val(val, value_prefix)
-        self.write("""\
-} %(mixed-name)s;
+        self.write("} %s;\n" % (self.prefix + name).replace('_', ''))
 
+        self.d("""\
 /**
- * NUM_%(upper-plural)s:
+ * %(upper-prefix)sNUM_%(upper-plural)s:
  *
  * 1 higher than the highest valid value of #%(mixed-name)s.
  */
-#define NUM_%(upper-plural)s (%(last-val)s+1)
+
+/**
+ * NUM_%(upper-prefix)s%(upper-plural)s: (skip)
+ *
+ * 1 higher than the highest valid value of #%(mixed-name)s.
+ * In new code, use %(upper-prefix)sNUM_%(upper-plural)s instead.
+ */
+""" % {'mixed-name' : (self.prefix + name).replace('_', ''),
+       'upper-prefix' : self.prefix.upper(),
+       'upper-plural' : name_plural.upper(),
+       'last-val' : vals[-1].getAttribute('value')})
+
+        self.write("""\
+#define %(upper-prefix)sNUM_%(upper-plural)s (%(last-val)s+1)
+#define NUM_%(upper-prefix)s%(upper-plural)s %(upper-prefix)sNUM_%(upper-plural)s
 
 """ % {'mixed-name' : (self.prefix + name).replace('_', ''),
-       'upper-plural' : (self.prefix + name_plural).upper(),
+       'upper-prefix' : self.prefix.upper(),
+       'upper-plural' : name_plural.upper(),
        'last-val' : vals[-1].getAttribute('value')})
 
     def do_val(self, val, value_prefix):
@@ -133,13 +161,13 @@ typedef enum {
         self.write('    %s = %s,\n' % (use_name, val.getAttribute('value')))
 
     def do_gtkdoc(self, node, value_prefix):
-        self.write(' * @')
-        self.write((self.prefix + value_prefix + '_' +
+        self.d(' * @')
+        self.d((self.prefix + value_prefix + '_' +
             node.getAttribute('suffix')).upper())
-        self.write(': <![CDATA[')
+        self.d(': <![CDATA[')
         docstring = get_by_path(node, 'docstring')
-        self.write(get_descendant_text(docstring).replace('\n', ' '))
-        self.write(']]>\n')
+        self.d(get_descendant_text(docstring).replace('\n', ' '))
+        self.d(']]>\n')
 
     # Footer
     def do_footer(self):
@@ -151,4 +179,4 @@ typedef enum {
 
 if __name__ == '__main__':
     argv = argv[1:]
-    Generator(argv[0], xml.dom.minidom.parse(argv[1]))()
+    Generator(argv[0], xml.dom.minidom.parse(argv[1]), argv[2])()



More information about the telepathy-commits mailing list