From 5dfa997724551ed163fefc11782b7163db3be378 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 12 Feb 2009 22:40:08 +0000 Subject: Bug 564016 - Add c:prefix to .gir 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. --- diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index e30bc6b..ddd562c 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -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 diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index f7ac884..e280159 100644 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -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") diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 2746b6e..c084606 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -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 diff --git a/tests/scanner/BarApp-1.0-expected.gir b/tests/scanner/BarApp-1.0-expected.gir index da8c825..e8095e5 100644 --- a/tests/scanner/BarApp-1.0-expected.gir +++ b/tests/scanner/BarApp-1.0-expected.gir @@ -9,7 +9,7 @@ and/or use gtk-doc annotations. --> - + - + diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir index c37d2d4..91fe561 100644 --- a/tests/scanner/annotation-1.0-expected.gir +++ b/tests/scanner/annotation-1.0-expected.gir @@ -10,7 +10,10 @@ and/or use gtk-doc annotations. --> - + diff --git a/tests/scanner/drawable-1.0-expected.gir b/tests/scanner/drawable-1.0-expected.gir index 052e788..6f82e3a 100644 --- a/tests/scanner/drawable-1.0-expected.gir +++ b/tests/scanner/drawable-1.0-expected.gir @@ -10,7 +10,10 @@ and/or use gtk-doc annotations. --> - + - + diff --git a/tests/scanner/utility-1.0-expected.gir b/tests/scanner/utility-1.0-expected.gir index 331979c..02e2913 100644 --- a/tests/scanner/utility-1.0-expected.gir +++ b/tests/scanner/utility-1.0-expected.gir @@ -9,7 +9,10 @@ and/or use gtk-doc annotations. --> - + -- cgit v0.9.1