diff options
author | Colin Walters <walters@verbum.org> | 2009-02-05 17:36:35 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2009-02-11 15:03:16 -0500 |
commit | 44ea75378eb33fa6386e66e9e5a55f3122363fb8 (patch) | |
tree | 27385b5c523f7390193dba950df134540aabd838 /giscanner | |
parent | 1b5e689fe2fc105725fe71051c184e0f1c461223 (diff) | |
download | gobject-introspection-44ea75378eb33fa6386e66e9e5a55f3122363fb8.tar.gz |
Bug 567906 - Put pkg-config dependencies in .gir files
When generating a .gir file, we now first parse all of our .gir includes
to pick up their <package> headers. Then, we merge that with the set of
--pkg arguments passed to us, run pkg-config to gather the arguments,
and finally save the merged pkg-config list to our new .gir file.
This is useful for software which needs to map from .gir to pkg-config
in a programmatic way.
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/girparser.py | 10 | ||||
-rw-r--r-- | giscanner/girwriter.py | 19 | ||||
-rw-r--r-- | giscanner/transformer.py | 19 |
3 files changed, 38 insertions, 10 deletions
diff --git a/giscanner/girparser.py b/giscanner/girparser.py index 3e2432ed..62db3e98 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -50,6 +50,7 @@ class GIRParser(object): self._include_parsing = False self._shared_libraries = [] self._includes = set() + self._pkgconfig_packages = set() self._namespace = None # Public API @@ -62,6 +63,7 @@ class GIRParser(object): self._includes.clear() self._namespace = None self._shared_libraries = [] + self._pkgconfig_packages = set() self._parse_api(tree.getroot()) def get_namespace(self): @@ -73,6 +75,9 @@ class GIRParser(object): def get_includes(self): return self._includes + def get_pkgconfig_packages(self): + return self._pkgconfig_packages + def get_doc(self): return parse(self._filename) @@ -89,6 +94,8 @@ class GIRParser(object): for node in root.getchildren(): if node.tag == _corens('include'): self._parse_include(node) + elif node.tag == _corens('package'): + self._parse_pkgconfig_package(node) ns = root.find(_corens('namespace')) assert ns is not None @@ -122,6 +129,9 @@ class GIRParser(object): node.attrib['version']) self._includes.add(include) + def _parse_pkgconfig_package(self, node): + self._pkgconfig_packages.add(node.attrib['name']) + def _parse_alias(self, node): alias = Alias(node.attrib['name'], node.attrib['target'], diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index 657063e6..35c9b35e 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -33,15 +33,20 @@ from .xmlwriter import XMLWriter class GIRWriter(XMLWriter): - def __init__(self, namespace, shlibs, includes): + def __init__(self, namespace, shlibs, includes, pkgs): 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) - - def _write_repository(self, namespace, shlibs, includes=set()): + self._write_repository(namespace, shlibs, includes, pkgs) + + def _write_repository(self, namespace, shlibs, includes=None, + packages=None): + if includes is None: + includes = frozenset() + if packages is None: + packages = frozenset() attrs = [ ('version', '1.0'), ('xmlns', 'http://www.gtk.org/introspection/core/1.0'), @@ -51,12 +56,18 @@ and/or use gtk-doc annotations. ''') with self.tagcontext('repository', attrs): for include in sorted(includes): self._write_include(include) + for pkg in sorted(set(packages)): + self._write_pkgconfig_pkg(pkg) self._write_namespace(namespace, shlibs) def _write_include(self, include): attrs = [('name', include.name), ('version', include.version)] self.write_tag('include', attrs) + def _write_pkgconfig_pkg(self, package): + attrs = [('name', package)] + self.write_tag('package', attrs) + def _write_namespace(self, namespace, shlibs): libraries = [] for l in shlibs: diff --git a/giscanner/transformer.py b/giscanner/transformer.py index f6e89ce1..6f9207a1 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -63,12 +63,12 @@ class Names(object): class Transformer(object): - def __init__(self, cachestore, generator, - namespace_name, namespace_version): + def __init__(self, cachestore, namespace_name, namespace_version): self._cachestore = cachestore - self.generator = generator + self.generator = None self._namespace = Namespace(namespace_name, namespace_version) self._names = Names() + self._pkg_config_packages = set() self._typedefs_ns = {} self._strip_prefix = '' self._includes = set() @@ -83,6 +83,12 @@ class Transformer(object): def set_strip_prefix(self, strip_prefix): self._strip_prefix = strip_prefix + def get_pkgconfig_packages(self): + return self._pkg_config_packages + + def set_source_ast(self, src_ast): + self.generator = src_ast + def parse(self): nodes = [] for symbol in self.generator.get_symbols(): @@ -115,9 +121,8 @@ class Transformer(object): path = os.path.join(d, girname) if os.path.exists(path): return path - else: - raise ValueError("Couldn't find include %r (search path: %r)"\ - % (girname, searchdirs)) + raise ValueError("Couldn't find include %r (search path: %r)"\ + % (girname, searchdirs)) def _parse_include(self, filename): parser = self._cachestore.load(filename) @@ -130,6 +135,8 @@ class Transformer(object): for include in parser.get_includes(): self.register_include(include) + for pkg in parser.get_pkgconfig_packages(): + self._pkg_config_packages.add(pkg) namespace = parser.get_namespace() nsname = namespace.name for node in namespace.nodes: |