diff options
author | Colin Walters <walters@src.gnome.org> | 2008-10-16 01:40:29 +0000 |
---|---|---|
committer | Colin Walters <walters@src.gnome.org> | 2008-10-16 01:40:29 +0000 |
commit | c3d732b2c2393a14ed9bda1e5a2e17745c94ca54 (patch) | |
tree | 3dd71bc56c4defb6d7f1a0ef7597922ab8dd17bb | |
parent | 1f1ca54b3a41713b9328f0824f59d18c3ef7ffd2 (diff) | |
download | gobject-introspection-c3d732b2c2393a14ed9bda1e5a2e17745c94ca54.tar.gz |
Merge branch 'bug556331-includecleanup'
svn path=/trunk/; revision=724
-rw-r--r-- | gir/Makefile.am | 10 | ||||
-rw-r--r-- | girepository/girepository.c | 2 | ||||
-rw-r--r-- | girepository/girparser.c | 22 | ||||
-rw-r--r-- | giscanner/ast.py | 26 | ||||
-rw-r--r-- | giscanner/girparser.py | 6 | ||||
-rw-r--r-- | giscanner/girwriter.py | 2 | ||||
-rw-r--r-- | giscanner/transformer.py | 29 | ||||
-rw-r--r-- | tests/object.gir | 2 | ||||
-rw-r--r-- | tests/scanner/Makefile.am | 18 | ||||
-rw-r--r-- | tests/scanner/annotation-1.0-expected.gir | 6 | ||||
-rw-r--r-- | tests/scanner/drawable-1.0-expected.gir | 6 | ||||
-rw-r--r-- | tests/scanner/foo-1.0-expected.gir | 16 | ||||
-rw-r--r-- | tests/scanner/foo.h | 2 | ||||
-rw-r--r-- | tests/scanner/utility-1.0-expected.gir | 5 | ||||
-rw-r--r-- | tests/scanner/utility.h | 3 | ||||
-rw-r--r-- | tests/types/Makefile.am | 3 | ||||
-rwxr-xr-x | tools/g-ir-scanner | 11 |
17 files changed, 114 insertions, 55 deletions
diff --git a/gir/Makefile.am b/gir/Makefile.am index a945f7f5..59caad75 100644 --- a/gir/Makefile.am +++ b/gir/Makefile.am @@ -17,6 +17,7 @@ endif GLib-2.0.gir: $(G_IR_SCANNER) $(G_IR_SCANNER_FILES) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(G_IR_SCANNER) \ -v --namespace GLib --nsversion=2.0 \ + --add-include-path=. \ --noclosure \ --output $@ \ --strip-prefix=g \ @@ -45,10 +46,11 @@ endif GObject-2.0.gir: GLib-2.0.gir $(G_IR_SCANNER) $(G_IR_SCANNER_FILES) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(G_IR_SCANNER) \ -v --namespace GObject --nsversion=2.0 \ + --add-include-path=. \ --noclosure \ --output $@ \ --strip-prefix=g \ - --include=$(top_builddir)/gir/GLib-2.0.gir \ + --include=GLib-2.0 \ --library=$(GOBJECT_LIBRARY) \ -I$(GOBJECT_INCLUDEDIR) \ -I$(GOBJECT_LIBDIR)/glib-2.0/include \ @@ -70,10 +72,11 @@ endif GModule-2.0.gir: GLib-2.0.gir $(G_IR_SCANNER) $(G_IR_SCANNER_FILES) PYTHONPATH=$(top_builddir):$$PYTHONPATH $(G_IR_SCANNER) \ -v --namespace GModule --nsversion=2.0 \ + --add-include-path=. \ --noclosure \ --output $@ \ --strip-prefix=g \ - --include=$(top_builddir)/gir/GLib-2.0.gir \ + --include=GLib-2.0 \ --library=$(GMODULE_LIBRARY) \ -I$(GMODULE_INCLUDEDIR) \ -I$(GMODULE_LIBDIR)/glib-2.0/include \ @@ -94,10 +97,11 @@ endif Gio-2.0.gir: GObject-2.0.gir $(G_IR_SCANNER) $(G_IR_SCANNER_FILES) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(G_IR_SCANNER) \ -v --namespace Gio --nsversion=2.0 \ + --add-include-path=. \ --noclosure \ --output $@ \ --strip-prefix=g \ - --include=$(top_builddir)/gir/GObject-2.0.gir \ + --include=GObject-2.0 \ --library=$(GIO_LIBRARY) \ -I$(GIO_INCLUDEDIR) \ -I$(GIO_LIBDIR)/glib-2.0/include \ diff --git a/girepository/girepository.c b/girepository/girepository.c index 6d401140..04c32c3b 100644 --- a/girepository/girepository.c +++ b/girepository/girepository.c @@ -1060,7 +1060,7 @@ g_irepository_require (GIRepository *repository, if (version != NULL) g_set_error (error, G_IREPOSITORY_ERROR, G_IREPOSITORY_ERROR_TYPELIB_NOT_FOUND, - "Typelib file %s for namespace '%s', version '%s' not found", + "Typelib file for namespace '%s', version '%s' not found", namespace, version); else g_set_error (error, G_IREPOSITORY_ERROR, diff --git a/girepository/girparser.c b/girepository/girparser.c index 35f882be..0b9e6199 100644 --- a/girepository/girparser.c +++ b/girepository/girparser.c @@ -130,7 +130,7 @@ static GMarkupParser firstpass_parser = }; static char * -locate_gir (const char *name, const char * const* extra_paths) +locate_gir (const char *name, const char *version, const char * const* extra_paths) { const gchar *const *datadirs; const gchar *const *dir; @@ -141,7 +141,7 @@ locate_gir (const char *name, const char * const* extra_paths) datadirs = g_get_system_data_dirs (); - girname = g_strdup_printf ("%s.gir", name); + girname = g_strdup_printf ("%s-%s.gir", name, version); for (dir = datadirs; *dir; dir++) { @@ -981,7 +981,6 @@ start_alias (GMarkupParseContext *context, { key = g_strdup (name); } - g_hash_table_insert (ctx->aliases, key, value); return TRUE; @@ -2048,6 +2047,7 @@ static gboolean parse_include (GMarkupParseContext *context, ParseContext *ctx, const char *name, + const char *version, GError **error) { ParseContext sub_ctx = { 0 }; @@ -2056,7 +2056,7 @@ parse_include (GMarkupParseContext *context, gsize length; char *girpath; - girpath = locate_gir (name, ctx->includes); + girpath = locate_gir (name, version, ctx->includes); if (girpath == NULL) { @@ -2231,19 +2231,27 @@ start_element_handler (GMarkupParseContext *context, ctx->state == STATE_REPOSITORY) { const gchar *name; - + const gchar *version; + name = find_attribute ("name", attribute_names, attribute_values); + version = find_attribute ("version", attribute_names, attribute_values); if (name == NULL) { MISSING_ATTRIBUTE (context, error, element_name, "name"); break; } + if (version == NULL) + { + MISSING_ATTRIBUTE (context, error, element_name, "version"); + break; + } - if (!parse_include (context, ctx, name, error)) + if (!parse_include (context, ctx, name, version, error)) break; - ctx->dependencies = g_list_prepend (ctx->dependencies, g_strdup (name)); + ctx->dependencies = g_list_prepend (ctx->dependencies, + g_strdup_printf ("%s-%s", name, version)); state_switch (ctx, STATE_INCLUDE); diff --git a/giscanner/ast.py b/giscanner/ast.py index 8ee6f7a8..f4bc05c7 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -155,6 +155,32 @@ class Namespace(Node): self.version, self.nodes) +class Include(Node): + + def __init__(self, name, version): + Node.__init__(self, 'include') + self.name = name + self.version = version + + @classmethod + def from_string(self, string): + return Include(*string.split('-', 1)) + + def __cmp__(self, other): + if not isinstance(other, Include): + return cmp(self, other) + namecmp = cmp(self.name, other.name) + if namecmp != 0: + return namecmp + return cmp(self.version, other.version) + + def __hash__(self): + return hash((self.name, self.version)) + + def __str__(self): + return '%s-%s' % (self.name, self.version) + + class Function(Node): def __init__(self, name, retval, parameters, symbol): diff --git a/giscanner/girparser.py b/giscanner/girparser.py index 7fca083c..5649e036 100644 --- a/giscanner/girparser.py +++ b/giscanner/girparser.py @@ -22,7 +22,7 @@ from xml.etree.cElementTree import parse from .ast import (Alias, Array, Callback, Constant, Enum, Function, Field, Namespace, Parameter, Property, Return, Union, Struct, Type, - Varargs) + Varargs, Include) from .glibast import (GLibEnum, GLibEnumMember, GLibFlags, GLibInterface, GLibObject, GLibBoxedStruct, GLibBoxedUnion, GLibBoxedOther) @@ -85,7 +85,9 @@ class GIRParser(object): assert root.tag == _corens('repository') for node in root.getchildren(): if node.tag == _corens('include'): - self._includes.add((node.attrib['name'])) + include = Include(node.attrib['name'], + node.attrib['version']) + self._includes.add(include) ns = root.find(_corens('namespace')) assert ns is not None self._namespace = Namespace(ns.attrib['name'], ns.attrib['version']) diff --git a/giscanner/girwriter.py b/giscanner/girwriter.py index 1ccbbefb..f6df49df 100644 --- a/giscanner/girwriter.py +++ b/giscanner/girwriter.py @@ -48,7 +48,7 @@ class GIRWriter(XMLWriter): self._write_namespace(namespace, shlibs) def _write_include(self, include): - attrs = [('name', include)] + attrs = [('name', include.name), ('version', include.version)] self.write_tag('include', attrs) def _write_namespace(self, namespace, shlibs): diff --git a/giscanner/transformer.py b/giscanner/transformer.py index c1609aa4..29111db7 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -96,24 +96,15 @@ class Transformer(object): self._add_node(node) return self._namespace - def register_include(self, filename): - (dirname, basename) = os.path.split(filename) - if dirname: - path = filename - (name, suffix) = os.path.splitext(basename) - else: - path = None - name = filename - if name.endswith('.gir'): - (name, suffix) = os.path.splitext(name) - if name in self._includes: - return - source = filename + def set_include_paths(self, paths): + self._includepaths = list(paths) + + def register_include(self, include, path=None): if path is None: - girname = name + '.gir' - searchdirs = [os.path.join(d, 'gir') for d \ - in _xdg_data_dirs] - searchdirs.extend(self._includepaths) + girname = '%s-%s.gir' % (include.name, include.version) + searchdirs = list(self._includepaths) + searchdirs.extend([os.path.join(d, 'gir') + for d in _xdg_data_dirs]) for d in searchdirs: path = os.path.join(d, girname) if os.path.exists(path): @@ -123,9 +114,7 @@ class Transformer(object): raise ValueError("Couldn't find include %r (search path: %r)"\ % (girname, searchdirs)) d = os.path.dirname(path) - if d not in self._includepaths: - self._includepaths.append(d) - self._includes.add(name) + self._includes.add(include) from .girparser import GIRParser parser = GIRParser(path) for include in parser.get_includes(): diff --git a/tests/object.gir b/tests/object.gir index 7751fe91..b7701c1a 100644 --- a/tests/object.gir +++ b/tests/object.gir @@ -3,7 +3,7 @@ xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0"> - <include name="GObject-2.0"/> + <include name="GObject" version="2.0"/> <namespace name="Foo" version="1.0"> <interface name="IFace1" glib:type-name="IFace1" glib:get-type="iface1_get_type"/> <class name="Object1" parent="Object2" glib:type-name="Object1" glib:get-type="object1_get_type"> diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am index 2bf78d13..b375d08d 100644 --- a/tests/scanner/Makefile.am +++ b/tests/scanner/Makefile.am @@ -36,8 +36,9 @@ EXTRA_DIST = $(EXPECTEDGIRS) annotation-1.0.gir: libannotation.la annotation.c annotation.h utility-1.0.gir $(SCANNER) $(SCANNER_LIBS) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \ - --include=$(top_srcdir)/gir/GObject-2.0.gir \ - --include=$(top_builddir)/tests/scanner/utility-1.0.gir \ + --add-include-path=$(top_builddir)/gir --add-include-path=. \ + --include=GObject-2.0 \ + --include=utility-1.0 \ --library=annotation \ --namespace=annotation \ --nsversion=1.0 \ @@ -48,8 +49,9 @@ GIRS += annotation-1.0.gir drawable-1.0.gir: libdrawable.la drawable.c drawable.h utility-1.0.gir $(SCANNER) $(SCANNER_LIBS) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \ - --include=$(top_srcdir)/gir/GObject-2.0.gir \ - --include=$(top_builddir)/tests/scanner/utility-1.0.gir \ + --add-include-path=$(top_builddir)/gir --add-include-path=. \ + --include=GObject-2.0 \ + --include=utility-1.0 \ --library=drawable \ --namespace=drawable \ --nsversion=1.0 \ @@ -60,8 +62,9 @@ GIRS += drawable-1.0.gir foo-1.0.gir: libfoo.la foo.c foo.h utility-1.0.gir $(SCANNER) $(SCANNER_LIBS) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \ - --include=$(top_srcdir)/gir/GObject-2.0.gir \ - --include=$(top_builddir)/tests/scanner/utility-1.0.gir \ + --add-include-path=$(top_builddir)/gir --add-include-path=. \ + --include=GObject-2.0 \ + --include=utility-1.0 \ --library=foo \ --namespace=foo \ --nsversion=1.0 \ @@ -72,7 +75,8 @@ GIRS += foo-1.0.gir utility-1.0.gir: libutility.la utility.h $(SCANNER) $(SCANNER_LIBS) Makefile PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \ - --include=$(top_srcdir)/gir/GObject-2.0.gir \ + --add-include-path=$(top_builddir)/gir --add-include-path=. \ + --include=GObject-2.0 \ --library=utility \ --namespace=utility \ --nsversion=1.0 \ diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir index fb16ff0c..c4169cc7 100644 --- a/tests/scanner/annotation-1.0-expected.gir +++ b/tests/scanner/annotation-1.0-expected.gir @@ -3,9 +3,9 @@ xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0"> - <include name="GLib-2.0"/> - <include name="GObject-2.0"/> - <include name="utility-1.0"/> + <include name="GLib" version="2.0"/> + <include name="GObject" version="2.0"/> + <include name="utility" version="1.0"/> <namespace name="annotation" version="1.0" shared-library="annotation"> <class name="Object" c:type="AnnotationObject" diff --git a/tests/scanner/drawable-1.0-expected.gir b/tests/scanner/drawable-1.0-expected.gir index 54ba700d..c24f46b4 100644 --- a/tests/scanner/drawable-1.0-expected.gir +++ b/tests/scanner/drawable-1.0-expected.gir @@ -3,9 +3,9 @@ xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0"> - <include name="GLib-2.0"/> - <include name="GObject-2.0"/> - <include name="utility-1.0"/> + <include name="GLib" version="2.0"/> + <include name="GObject" version="2.0"/> + <include name="utility" version="1.0"/> <namespace name="drawable" version="1.0" shared-library="drawable"> <class name="TestDrawable" c:type="TestDrawable" diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir index 23035fe1..34de38c2 100644 --- a/tests/scanner/foo-1.0-expected.gir +++ b/tests/scanner/foo-1.0-expected.gir @@ -3,9 +3,9 @@ xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0"> - <include name="GLib-2.0"/> - <include name="GObject-2.0"/> - <include name="utility-1.0"/> + <include name="GLib" version="2.0"/> + <include name="GObject" version="2.0"/> + <include name="utility" version="1.0"/> <namespace name="foo" version="1.0" shared-library="foo"> <alias name="List" target="GLib.SList" c:type="FooList"/> <alias name="XEvent" target="none" c:type="FooXEvent"/> @@ -123,6 +123,16 @@ <type name="utf8" c:type="char*"/> </return-value> </method> + <method name="handle_glyph" c:identifier="foo_object_handle_glyph"> + <return-value> + <type name="none" c:type="void"/> + </return-value> + <parameters> + <parameter name="glyph"> + <type name="utility.Glyph" c:type="UtilityGlyph"/> + </parameter> + </parameters> + </method> <property name="string" writable="1"> <type name="utf8" c:type="gchararray"/> </property> diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h index e5ed4f18..4639f7b5 100644 --- a/tests/scanner/foo.h +++ b/tests/scanner/foo.h @@ -70,6 +70,8 @@ const char * foo_object_get_name (FooObject *object); char * foo_object_dup_name (FooObject *object); +void foo_object_handle_glyph (FooObject *object, UtilityGlyph glyph); + struct _FooSubobject { FooObject parent_instance; diff --git a/tests/scanner/utility-1.0-expected.gir b/tests/scanner/utility-1.0-expected.gir index a3618caf..ce83ee3d 100644 --- a/tests/scanner/utility-1.0-expected.gir +++ b/tests/scanner/utility-1.0-expected.gir @@ -3,9 +3,10 @@ xmlns="http://www.gtk.org/introspection/core/1.0" xmlns:c="http://www.gtk.org/introspection/c/1.0" xmlns:glib="http://www.gtk.org/introspection/glib/1.0"> - <include name="GLib-2.0"/> - <include name="GObject-2.0"/> + <include name="GLib" version="2.0"/> + <include name="GObject" version="2.0"/> <namespace name="utility" version="1.0" shared-library="utility"> + <alias name="Glyph" target="uint32" c:type="UtilityGlyph"/> <class name="Object" c:type="UtilityObject" parent="GObject.Object" diff --git a/tests/scanner/utility.h b/tests/scanner/utility.h index df03a5cd..d1f581a0 100644 --- a/tests/scanner/utility.h +++ b/tests/scanner/utility.h @@ -20,6 +20,9 @@ struct _UtilityObjectClass GObjectClass parent_class; }; +/* This one is similar to Pango.Glyph */ +typedef guint32 UtilityGlyph; + GType utility_object_get_type (void) G_GNUC_CONST; typedef enum diff --git a/tests/types/Makefile.am b/tests/types/Makefile.am index 68d0572a..c74dbe86 100644 --- a/tests/types/Makefile.am +++ b/tests/types/Makefile.am @@ -30,7 +30,8 @@ BUILT_SOURCES = $(TYPELIBS) $(TXMLS) $(GIRS) gitesttypes-1.0.gir: libgitesttypes.la gitesttypes.c gitesttypes.h $(SCANNER) $(SCANNER_LIBS) PYTHONPATH=$(top_builddir):$$PYTHONPATH $(CHECK_DEBUG) $(SCANNER) -v \ - --include=$(top_srcdir)/gir/GObject-2.0.gir \ + --add-include-path=$(top_builddir)/gir \ + --include=GObject-2.0 \ --library=gitesttypes \ --namespace=gitesttypes --nsversion=1.0 \ --pkg gobject-2.0 \ diff --git a/tools/g-ir-scanner b/tools/g-ir-scanner index 7d3f02d9..8c284f94 100755 --- a/tools/g-ir-scanner +++ b/tools/g-ir-scanner @@ -38,6 +38,7 @@ sys.path.insert(0, path) from giscanner.glibtransformer import GLibTransformer from giscanner.sourcescanner import SourceScanner from giscanner.transformer import Transformer +from giscanner.ast import Include from giscanner.minixpath import myxpath, xpath_assert @@ -50,6 +51,9 @@ def _get_option_parser(): parser.add_option("-i", "--include", action="append", dest="includes", default=[], help="include types for other gidls") + parser.add_option("--add-include-path", + action="append", dest="include_paths", default=[], + help="include paths for other GIR files") parser.add_option("-l", "--library", action="append", dest="libraries", default=[], help="libraries of this unit") @@ -249,8 +253,13 @@ def main(args): # Transform the C symbols into AST nodes transformer = Transformer(ss, options.namespace_name, options.namespace_version) transformer.set_strip_prefix(options.strip_prefix) + transformer.set_include_paths(options.include_paths) + shown_include_warning = False for include in options.includes: - transformer.register_include(include) + if os.sep in include: + raise ValueError("Invalid include path %r" % (include, )) + include_obj = Include.from_string(include) + transformer.register_include(include_obj) # Transform the C AST nodes into higher level # GLib/GObject nodes |