Bug 572423 - Support --c-include argument for specifying C headers
authorColin Walters <walters@verbum.org>
Thu, 19 Feb 2009 22:52:22 +0000 (17:52 -0500)
committerColin Walters <walters@verbum.org>
Fri, 20 Feb 2009 14:10:46 +0000 (09:10 -0500)
This option is for specifying inside the .gir what C header files should
be included by C consumers (as opposed to parsed by the scanner).

gir/Makefile.am
giscanner/girwriter.py
tests/scanner/Makefile.am
tests/scanner/foo-1.0-expected.gir
tools/g-ir-scanner

index 9b1b7c6..f2dee10 100644 (file)
@@ -31,7 +31,8 @@ GLib-2.0.gir: $(SCANNER_BIN) $(SCANNER_LIBS) Makefile glib-2.0.c
            --noclosure \
            --output $@ \
            --strip-prefix=g \
-            --libtool="$(LIBTOOL)" \
+           --libtool="$(LIBTOOL)" \
+           --c-include="glib.h" \
            --library=$(GLIB_LIBRARY) \
            --pkg glib-2.0 \
            $(CPPFLAGS) \
@@ -63,13 +64,14 @@ GObject-2.0.gir: GLib-2.0.gir $(SCANNER_BIN) $(SCANNER_LIBS) Makefile
            --noclosure \
            --output $@ \
            --strip-prefix=g \
-            --libtool="$(LIBTOOL)" \
-            --include=GLib-2.0 \
+           --libtool="$(LIBTOOL)" \
+           --c-include="glib-object.h" \
+           --include=GLib-2.0 \
            --library=$(GOBJECT_LIBRARY) \
            -I$(GOBJECT_INCLUDEDIR) \
            -I$(GOBJECT_LIBDIR)/glib-2.0/include \
            -DGOBJECT_COMPILATION \
-            --pkg gobject-2.0 \
+           --pkg gobject-2.0 \
            $(GLIB_INCLUDEDIR)/gobject/*.h
        $(SCANNER) $(SCANNER_ARGS) \
            --xpath-assertions=$(srcdir)/GObject-2.0.xpath GObject-2.0.gir
@@ -92,12 +94,13 @@ GModule-2.0.gir: GLib-2.0.gir $(SCANNER_BIN) $(SCANNER_LIBS)
            --noclosure \
            --output $@ \
            --strip-prefix=g \
-            --libtool="$(LIBTOOL)" \
-            --include=GLib-2.0 \
+           --libtool="$(LIBTOOL)" \
+           --c-include="gmodule.h" \
+           --include=GLib-2.0 \
            --library=$(GMODULE_LIBRARY) \
            -I$(GMODULE_INCLUDEDIR) \
            -I$(GMODULE_LIBDIR)/glib-2.0/include \
-            --pkg gmodule-2.0 \
+           --pkg gmodule-2.0 \
            $(GLIB_INCLUDEDIR)/gmodule.h
 BUILT_GIRSOURCES += GModule-2.0.gir
 
@@ -124,8 +127,9 @@ Gio-2.0.gir: GObject-2.0.gir $(SCANNER_BIN) $(SCANNER_LIBS) Makefile $(srcdir)/g
            --noclosure \
            --output $@ \
            --strip-prefix=g \
-            --libtool="$(LIBTOOL)" \
-            --include=GObject-2.0 \
+               --libtool="$(LIBTOOL)" \
+               --c-include="gio/gio.h" \
+               --include=GObject-2.0 \
            --library=$(GIO_LIBRARY) \
            -I$(GIO_INCLUDEDIR) \
            -I$(GIO_LIBDIR)/glib-2.0/include \
@@ -148,12 +152,13 @@ GIRepository-2.0.gir: GObject-2.0.gir $(SCANNER_BIN) $(SCANNER_LIBS) $(GIREPOSIT
            --noclosure \
            --output $@ \
            --strip-prefix=g \
-            --libtool="$(LIBTOOL)" \
-            --include=GObject-2.0 \
+               --libtool="$(LIBTOOL)" \
+               --c-include="girepository.h" \
+               --include=GObject-2.0 \
            --library=girepository-1.0 \
            -I$(srcdir)/girepository \
-            --pkg glib-2.0 \
-            --pkg gobject-2.0 \
+               --pkg glib-2.0 \
+               --pkg gobject-2.0 \
            $(GIREPOSITORY_FILES)
 BUILT_GIRSOURCES += GIRepository-2.0.gir
 
index 116681a..4742840 100644 (file)
@@ -33,20 +33,22 @@ from .xmlwriter import XMLWriter
 
 class GIRWriter(XMLWriter):
 
-    def __init__(self, namespace, shlibs, includes, pkgs):
+    def __init__(self, namespace, shlibs, includes, pkgs, c_includes):
         super(GIRWriter, self).__init__()
         self.write_comment(
 '''This file was automatically generated from C sources - DO NOT EDIT!
 To affect the contents of this file, edit the original C definitions,
 and/or use gtk-doc annotations. ''')
-        self._write_repository(namespace, shlibs, includes, pkgs)
+        self._write_repository(namespace, shlibs, includes, pkgs, c_includes)
 
     def _write_repository(self, namespace, shlibs, includes=None,
-                          packages=None):
+                          packages=None, c_includes=None):
         if includes is None:
             includes = frozenset()
         if packages is None:
             packages = frozenset()
+        if c_includes is None:
+            c_includes = frozenset()
         attrs = [
             ('version', '1.0'),
             ('xmlns', 'http://www.gtk.org/introspection/core/1.0'),
@@ -58,6 +60,8 @@ and/or use gtk-doc annotations. ''')
                 self._write_include(include)
             for pkg in sorted(set(packages)):
                 self._write_pkgconfig_pkg(pkg)
+            for c_include in sorted(set(c_includes)):
+                self._write_c_include(c_include)
             self._write_namespace(namespace, shlibs)
 
     def _write_include(self, include):
@@ -68,6 +72,10 @@ and/or use gtk-doc annotations. ''')
         attrs = [('name', package)]
         self.write_tag('package', attrs)
 
+    def _write_c_include(self, c_include):
+        attrs = [('name', c_include)]
+        self.write_tag('c:include', attrs)
+
     def _write_namespace(self, namespace, shlibs):
         libraries = []
         for l in shlibs:
index ec7b2b5..e3c0393 100644 (file)
@@ -68,6 +68,7 @@ foo-1.0.gir: libfoo.la foo.c foo.h utility-1.0.gir $(SCANNER_BIN) $(SCANNER_LIBS
        $(CHECK_DEBUG) $(SCANNER) \
        --include=GObject-2.0 \
        --include=utility-1.0 \
+       --c-include="foo.h" \
         --libtool="$(LIBTOOL)" \
        --library=foo \
        --namespace=foo \
index c0fa2aa..6a1d8a4 100644 (file)
@@ -10,6 +10,7 @@ and/or use gtk-doc annotations.  -->
   <include name="GObject" version="2.0"/>
   <include name="utility" version="1.0"/>
   <package name="gobject-2.0"/>
+  <c:include name="foo.h"/>
   <namespace name="foo" version="1.0" shared-library="foo">
     <alias name="List" target="GLib.SList" c:type="FooList"/>
     <alias name="ObjectCookie" target="any" c:type="FooObjectCookie"/>
index f53f7fc..8205828 100755 (executable)
@@ -111,6 +111,9 @@ def _get_option_parser():
     parser.add_option("", "--xpath-assertions",
                       action="store", dest="xpath_assertions",
                       help="Use given file to create assertions on GIR content")
+    parser.add_option("", "--c-include",
+                      action="append", dest="c_includes", default=[],
+                      help="headers which should be included in C programs")
 
     group = optparse.OptionGroup(parser, "Preprocessor options")
     group.add_option("-I", help="Pre-processor include file",
@@ -345,7 +348,7 @@ def main(args):
 
     # Write out AST
     writer = Writer(namespace, libraries, transformer.get_includes(),
-                    options.packages)
+                    options.packages, options.c_includes)
     data = writer.get_xml()
     if options.output:
         fd = open(options.output, "w")