Bug 564016 - Add c:prefix to .gir
authorColin Walters <walters@verbum.org>
Thu, 12 Feb 2009 22:40:08 +0000 (17:40 -0500)
committerColin Walters <walters@verbum.org>
Tue, 17 Mar 2009 20:28:30 +0000 (16:28 -0400)
This has a few use cases; the main one in mind right now is that
when we place this in the .typelib as well, we can use it to optimize
lookups based on GType names, by skipping entirely typelibs whose
c:prefix is not a prefix of the target type lookup.

giscanner/girwriter.py
giscanner/scannermain.py
giscanner/transformer.py
tests/scanner/BarApp-1.0-expected.gir
tests/scanner/GtkFrob-1.0-expected.gir
tests/scanner/annotation-1.0-expected.gir
tests/scanner/drawable-1.0-expected.gir
tests/scanner/foo-1.0-expected.gir
tests/scanner/utility-1.0-expected.gir

index e30bc6b9ef754212be476c4192bfc7a7beabf453..ddd562cd155898cb11053ed2f982db0a1bc6c32a 100644 (file)
@@ -35,16 +35,17 @@ from .xmlwriter import XMLWriter
 
 class GIRWriter(XMLWriter):
 
-    def __init__(self, namespace, shlibs, includes, pkgs, c_includes):
+    def __init__(self, namespace, shlibs, includes, pkgs, c_includes, cprefix):
         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, c_includes)
+        self._write_repository(namespace, shlibs, includes, pkgs,
+                               c_includes, cprefix)
 
     def _write_repository(self, namespace, shlibs, includes=None,
-                          packages=None, c_includes=None):
+                          packages=None, c_includes=None, cprefix=None):
         if includes is None:
             includes = frozenset()
         if packages is None:
@@ -64,7 +65,7 @@ and/or use gtk-doc annotations. ''')
                 self._write_pkgconfig_pkg(pkg)
             for c_include in sorted(set(c_includes)):
                 self._write_c_include(c_include)
-            self._write_namespace(namespace, shlibs)
+            self._write_namespace(namespace, shlibs, cprefix)
 
     def _write_include(self, include):
         attrs = [('name', include.name), ('version', include.version)]
@@ -78,7 +79,7 @@ and/or use gtk-doc annotations. ''')
         attrs = [('name', c_include)]
         self.write_tag('c:include', attrs)
 
-    def _write_namespace(self, namespace, shlibs):
+    def _write_namespace(self, namespace, shlibs, cprefix):
         libraries = []
         for l in shlibs:
             found_libname = find_library(l)
@@ -88,7 +89,8 @@ and/or use gtk-doc annotations. ''')
 
         attrs = [('name', namespace.name),
                  ('version', namespace.version),
-                 ('shared-library', ','.join(libraries))]
+                 ('shared-library', ','.join(libraries)),
+                 ('c:prefix', cprefix)]
         with self.tagcontext('namespace', attrs):
             # We define a custom sorting function here because
             # we want aliases to be first.  They're a bit
index f7ac884a15e3a4199b08754a66599e6859459347..e2801593f02bac173c3c1c9f0119df60ae54ecb5 100644 (file)
@@ -331,7 +331,8 @@ def scanner_main(args):
 
     # Write out AST
     writer = Writer(namespace, libraries, transformer.get_includes(),
-                    options.packages, options.c_includes)
+                    options.packages, options.c_includes,
+                    transformer.get_strip_prefix())
     data = writer.get_xml()
     if options.output:
         fd = open(options.output, "w")
index 2746b6e8f924207fd9f44a0e35f643338edbdb73..c0846065401c031bb905285abb3047a2464587b9 100644 (file)
@@ -83,6 +83,9 @@ class Transformer(object):
     def set_strip_prefix(self, strip_prefix):
         self._strip_prefix = strip_prefix
 
+    def get_strip_prefix(self):
+        return self._strip_prefix
+
     def get_pkgconfig_packages(self):
         return self._pkg_config_packages
 
index da8c825ed09da6512ba4b2929921e2631931745e..e8095e5dfd16a31dc67cee5d3237ab022aceaabb 100644 (file)
@@ -9,7 +9,7 @@ and/or use gtk-doc annotations.  -->
   <include name="GLib" version="2.0"/>
   <include name="GObject" version="2.0"/>
   <package name="gobject-2.0"/>
-  <namespace name="BarApp" version="1.0" shared-library="">
+  <namespace name="BarApp" version="1.0" shared-library="" c:prefix="Bar">
     <class name="Baz"
            c:type="BarBaz"
            parent="GObject.Object"
index fa4b3ed22b31640dc75886f02351b151c8a675b7..423c0539a7df68fe2aee29d9f057e6b60e7e142f 100644 (file)
@@ -9,7 +9,10 @@ and/or use gtk-doc annotations.  -->
   <include name="GLib" version="2.0"/>
   <include name="GObject" version="2.0"/>
   <package name="gobject-2.0"/>
-  <namespace name="GtkFrob" version="1.0" shared-library="gtkfrob">
+  <namespace name="GtkFrob"
+             version="1.0"
+             shared-library="gtkfrob"
+             c:prefix="Gtk">
     <function name="language_manager_get_default"
               c:identifier="gtk_frob_language_manager_get_default">
       <return-value transfer-ownership="none">
index c37d2d48d2a687f6917f81ce61e338cd810b4f52..91fe56119226ed6c90c0431e7f1d1d6bd90c293e 100644 (file)
@@ -10,7 +10,10 @@ and/or use gtk-doc annotations.  -->
   <include name="GObject" version="2.0"/>
   <include name="utility" version="1.0"/>
   <package name="gobject-2.0"/>
-  <namespace name="annotation" version="1.0" shared-library="annotation">
+  <namespace name="annotation"
+             version="1.0"
+             shared-library="annotation"
+             c:prefix="annotation">
     <callback name="Callback"
               c:type="AnnotationCallback"
               doc="This is a callback.">
index 052e788af22c1da6e5eb0aedab8e573d9c7e5e4b..6f82e3ab93cfb4c596d35fd87fd222570b43cdfd 100644 (file)
@@ -10,7 +10,10 @@ and/or use gtk-doc annotations.  -->
   <include name="GObject" version="2.0"/>
   <include name="utility" version="1.0"/>
   <package name="gobject-2.0"/>
-  <namespace name="drawable" version="1.0" shared-library="drawable">
+  <namespace name="drawable"
+             version="1.0"
+             shared-library="drawable"
+             c:prefix="drawable">
     <class name="TestDrawable"
            c:type="TestDrawable"
            parent="GObject.Object"
index b28d8611518aa7085b2051463ba1789bf2c7378f..839a8dc1c5333b9ebe6bd1bed370a8ab45edd600 100644 (file)
@@ -11,7 +11,7 @@ and/or use gtk-doc annotations.  -->
   <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">
+  <namespace name="foo" version="1.0" shared-library="foo" c:prefix="foo">
     <alias name="List" target="GLib.SList" c:type="FooList"/>
     <alias name="ObjectCookie" target="any" c:type="FooObjectCookie"/>
     <alias name="XEvent" target="none" c:type="FooXEvent"/>
index 331979c904749c88c492e3aed2fc64be9d7d32ef..02e29136cc7cf64c0105b4239af7bb41da66c77a 100644 (file)
@@ -9,7 +9,10 @@ and/or use gtk-doc annotations.  -->
   <include name="GLib" version="2.0"/>
   <include name="GObject" version="2.0"/>
   <package name="gobject-2.0"/>
-  <namespace name="utility" version="1.0" shared-library="utility">
+  <namespace name="utility"
+             version="1.0"
+             shared-library="utility"
+             c:prefix="utility">
     <alias name="Glyph" target="uint32" c:type="UtilityGlyph"/>
     <union name="Byte" c:type="UtilityByte">
       <field name="value" writable="1">