[caribou/geometry] libcaribou: Added a tool to ammend valac's gir.
- From: Eitan Isaacson <eitani src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [caribou/geometry] libcaribou: Added a tool to ammend valac's gir.
- Date: Sat, 30 Apr 2011 07:38:57 +0000 (UTC)
commit fd7fbe0155c2f3232d969aaed997ebe950869f19
Author: Eitan Isaacson <eitan monotonous org>
Date: Fri Apr 29 01:59:17 2011 -0700
libcaribou: Added a tool to ammend valac's gir.
I filed a bug for this: https://bugzilla.gnome.org/show_bug.cgi?id=648957
.gitignore | 4 +-
libcaribou/Makefile.am | 6 ++++-
tools/fix_gir.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+), 3 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index cb3be79..a0ba962 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,8 +33,8 @@ libtool
ltmain.sh
m4
libcaribou/.libs/
-libcaribou/Caribou-1.0.gir
-libcaribou/Caribou-1.0.typelib
+libcaribou/*.gir
+libcaribou/*.typelib
*.lo
*.o
libcaribou/libcaribou.la
diff --git a/libcaribou/Makefile.am b/libcaribou/Makefile.am
index 90cc34b..9e157e9 100644
--- a/libcaribou/Makefile.am
+++ b/libcaribou/Makefile.am
@@ -12,7 +12,7 @@ libcaribou_la_VALAFLAGS = \
--pkg x11 --pkg json-glib-1.0 --pkg gdk-3.0 --pkg gio-2.0 \
--pkg libxklavier --pkg external-libs --pkg gdk-x11-3.0 \
--internal-vapi caribou-internals-1.0.vapi \
- --library caribou-1.0 --gir Caribou-1.0.gir \
+ --library caribou-1.0 --gir _Caribou-1.0.gir \
$(VALAFLAGS)
libcaribou_la_CPPFLAGS = \
@@ -55,6 +55,9 @@ gir_DATA = Caribou-1.0.gir
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = Caribou-1.0.typelib
+Caribou-1.0.gir: _Caribou-1.0.gir
+ $(top_srcdir)/tools/fix_gir.py $< > $@
+
Caribou-1.0.typelib: Caribou-1.0.gir
@INTROSPECTION_COMPILER@ --shared-library=libcaribou -o $@ $^
endif
@@ -66,4 +69,5 @@ CLEANFILES = \
caribou-internals-1.0.vapi \
Caribou-1.0.typelib \
Caribou-1.0.gir \
+ _Caribou-1.0.gir \
*.[ch]
\ No newline at end of file
diff --git a/tools/fix_gir.py b/tools/fix_gir.py
new file mode 100755
index 0000000..31190e3
--- /dev/null
+++ b/tools/fix_gir.py
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+from xml.dom import minidom
+
+def purge_white_space_and_fix_namespace(node, indent=0):
+ if getattr(node, "tagName", None) == "namespace":
+ name = node.getAttribute("name")
+ node.setAttribute("name", name.lstrip('_'))
+ for child in [c for c in node.childNodes]:
+ if child.nodeType == node.TEXT_NODE or \
+ getattr(child, "tagName", None) == "annotation":
+ node.removeChild(child)
+ continue
+ purge_white_space_and_fix_namespace(child, indent+1)
+
+def find_ancestor(node, name):
+ if getattr(node, "tagName") == name:
+ return node
+ parent = getattr(node, "parentNode", None)
+ if not parent:
+ return None
+ return find_ancestor(parent, name)
+
+def fix_vfuncs(dom):
+ for f in dom.getElementsByTagName("callback"):
+ record = find_ancestor(f, "record")
+ if not record:
+ continue
+
+ name = record.getAttribute("name")
+ cname = record.getAttribute("c:type")
+
+ assert(name.endswith("Class"))
+ assert(cname.endswith("Class"))
+
+ params = (f.getElementsByTagName("parameters") or [None])[0]
+
+ if not params:
+ params = dom.createElement("parameters")
+ f.insertBefore(params, f.firstChild)
+
+ param = dom.createElement("parameter")
+ param.setAttribute("name", "self")
+ param.setAttribute("transfer-ownership", "none")
+ ptype = dom.createElement("type")
+ ptype.setAttribute("name", name[:-5])
+ ptype.setAttribute("c:type", cname[:-5])
+ param.appendChild(ptype)
+ params.insertBefore(param, params.firstChild)
+
+if __name__ == "__main__":
+ import sys
+
+ if len(sys.argv) != 2:
+ print "supply a gir file"
+ sys.exit(1)
+
+ dom = minidom.parse(sys.argv[-1])
+
+ purge_white_space_and_fix_namespace(dom)
+ fix_vfuncs(dom)
+
+ print dom.toprettyxml(indent=" ", newl="\n")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]