[Telepathy-commits] [telepathy-glib/master] Use xincludator.py (from telepathy-qt4) rather than abusing xsltproc to do XInclude.

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Jan 21 05:53:23 PST 2009


This helps with portability/cross-compilation. Our only remaining
use of XSLT is doc-generator.xsl which is used to compile docs for
the example extensions - I'd rather not disable this until we have
a Python script that will do sanity checking on spec extensions.
---
 examples/extensions/Makefile.am |   10 ++++------
 telepathy-glib/Makefile.am      |   13 ++++---------
 tools/Makefile.am               |    4 ++--
 tools/identity.xsl              |    7 -------
 tools/xincludator.py            |   39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 49 insertions(+), 24 deletions(-)
 delete mode 100644 tools/identity.xsl
 create mode 100644 tools/xincludator.py

diff --git a/examples/extensions/Makefile.am b/examples/extensions/Makefile.am
index c206640..52aa58f 100644
--- a/examples/extensions/Makefile.am
+++ b/examples/extensions/Makefile.am
@@ -64,10 +64,9 @@ XSLTPROCFLAGS = --nonet --novalid
 
 # Generated files which can be generated for all categories simultaneously
 
-_gen/all.xml: all.xml $(wildcard *.xml)
+_gen/all.xml: all.xml $(wildcard *.xml) $(tools_dir)/xincludator.py
 	$(mkdir_p) _gen
-	$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \
-		$< > $@
+	$(PYTHON) $(tools_dir)/xincludator.py $< > $@
 
 extensions.html: _gen/all.xml $(tools_dir)/doc-generator.xsl
 	$(XSLTPROC) $(XSLTPROCFLAGS) \
@@ -110,10 +109,9 @@ _gen/interfaces-body.h _gen/interfaces.h: _gen/all.xml \
 # subclass you want to use with --subclass will need to have its own category,
 # although you can subdivide further if you want.
 
-_gen/connection.xml: connection.xml $(wildcard *.xml)
+_gen/connection.xml: connection.xml $(wildcard *.xml) $(tools_dir)/xincludator.py
 	$(mkdir_p) _gen
-	$(XSLTPROC) $(XSLTPROCFLAGS) --xinclude $(tools_dir)/identity.xsl \
-		$< > $@
+	$(PYTHON) $(tools_dir)/xincludator.py $< > $@
 
 _gen/cli-connection-body.h _gen/cli-connection.h: _gen/connection.xml \
 	$(tools_dir)/glib-client-gen.py
diff --git a/telepathy-glib/Makefile.am b/telepathy-glib/Makefile.am
index 45f2252..2ae33da 100644
--- a/telepathy-glib/Makefile.am
+++ b/telepathy-glib/Makefile.am
@@ -273,7 +273,6 @@ ALL_LIBS = \
 # Generated stuff
 
 DROP_NAMESPACE = sed -e 's at xmlns:tp="http://telepathy\.freedesktop\.org/wiki/DbusSpec.extensions-v0"@@g'
-XSLTPROCFLAGS = --nonet --novalid
 tools_dir = $(top_srcdir)/tools
 
 # Bootstrapping
@@ -285,10 +284,8 @@ _gen/spec-stamp: $(wildcard $(top_srcdir)/spec/*.xml)
 _gen/stable-stamp: $(wildcard *.xml) _gen/spec-stamp
 	touch $@
 
-_gen/stable-spec.xml: stable-interfaces.xml _gen/stable-stamp
-	$(XSLTPROC) --xinclude $(XSLTPROCFLAGS) \
-		$(tools_dir)/identity.xsl \
-		$< > $@
+_gen/stable-spec.xml: stable-interfaces.xml _gen/stable-stamp $(tools_dir)/xincludator.py
+	$(PYTHON) $(tools_dir)/xincludator.py $< > $@
 
 # Things generated from the whole spec at once
 
@@ -340,10 +337,8 @@ _gen/signals-marshal.c: _gen/signals-marshal.list Makefile.am
 
 # Things generated per interface
 
-_gen/tp-spec-%.xml: %.xml $(tools_dir)/identity.xsl _gen/spec-stamp
-	$(XSLTPROC) --xinclude $(XSLTPROCFLAGS) \
-		$(tools_dir)/identity.xsl \
-		$< > $@
+_gen/tp-spec-%.xml: %.xml _gen/spec-stamp $(tools_dir)/xincludator.py
+	$(PYTHON) $(tools_dir)/xincludator.py $< > $@
 
 _gen/tp-svc-%.c _gen/tp-svc-%.h: _gen/tp-spec-%.xml \
 	$(tools_dir)/glib-ginterface-gen.py \
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 30b5c26..4af909a 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -23,14 +23,14 @@ EXTRA_DIST = \
     glib-interfaces-gen.py \
     glib-signals-marshal-gen.py \
     gobject-foo.py \
-    identity.xsl \
     lcov.am \
     libtpcodegen.py \
     libglibcodegen.py \
     make-version-script.py \
     telepathy.am \
     telepathy-glib-env.in \
-    with-session-bus.sh
+    with-session-bus.sh \
+    xincludator.py
 
 CLEANFILES = libtpcodegen.pyc libtpcodegen.pyo libglibcodegen.pyc libglibcodegen.pyo $(noinst_SCRIPTS)
 
diff --git a/tools/identity.xsl b/tools/identity.xsl
deleted file mode 100644
index 6630f84..0000000
--- a/tools/identity.xsl
+++ /dev/null
@@ -1,7 +0,0 @@
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-	<xsl:template match="@*|node()">
-		<xsl:copy>
-			<xsl:apply-templates select="@*|node()"/>
-		</xsl:copy>
-	</xsl:template>
-</xsl:stylesheet>
diff --git a/tools/xincludator.py b/tools/xincludator.py
new file mode 100644
index 0000000..63e106a
--- /dev/null
+++ b/tools/xincludator.py
@@ -0,0 +1,39 @@
+#!/usr/bin/python
+
+from sys import argv, stdout, stderr
+import codecs, locale
+import os
+import xml.dom.minidom
+
+stdout = codecs.getwriter('utf-8')(stdout)
+
+NS_XI = 'http://www.w3.org/2001/XInclude'
+
+def xincludate(dom, base, dropns = []):
+    remove_attrs = []
+    for i in xrange(dom.documentElement.attributes.length):
+        attr = dom.documentElement.attributes.item(i)
+        if attr.prefix == 'xmlns':
+            if attr.localName in dropns:
+                remove_attrs.append(attr)
+            else:
+                dropns.append(attr.localName)
+    for attr in remove_attrs:
+        dom.documentElement.removeAttributeNode(attr)
+    for include in dom.getElementsByTagNameNS(NS_XI, 'include'):
+        href = include.getAttribute('href')
+        # FIXME: assumes Unixy paths
+        filename = os.path.join(os.path.dirname(base), href)
+        subdom = xml.dom.minidom.parse(filename)
+        xincludate(subdom, filename, dropns)
+        if './' in href:
+            subdom.documentElement.setAttribute('xml:base', href)
+        include.parentNode.replaceChild(subdom.documentElement, include)
+
+if __name__ == '__main__':
+    argv = argv[1:]
+    dom = xml.dom.minidom.parse(argv[0])
+    xincludate(dom, argv[0])
+    xml = dom.toxml()
+    stdout.write(xml)
+    stdout.write('\n')
-- 
1.5.6.5



More information about the Telepathy-commits mailing list