diff options
author | Eitan Isaacson <eitan@monotonous.org> | 2011-04-29 01:59:17 -0700 |
---|---|---|
committer | Eitan Isaacson <eitan@monotonous.org> | 2011-05-02 10:18:49 -0700 |
commit | f195b7aafa878568e7aae8ccc27e3716ae7c21cc (patch) | |
tree | 41a9868f025dedf323ad6b87bfcaf8a263d00601 | |
parent | 6294dab42aec83a4e9edd314544903a67152b7fb (diff) | |
download | caribou-f195b7aafa878568e7aae8ccc27e3716ae7c21cc.tar.gz |
libcaribou: Added a tool to ammend valac's gir.
I filed a bug for this: https://bugzilla.gnome.org/show_bug.cgi?id=648957
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | libcaribou/Makefile.am | 6 | ||||
-rwxr-xr-x | tools/fix_gir.py | 63 |
3 files changed, 70 insertions, 3 deletions
@@ -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") |