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 \
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 \
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 \
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 \
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,
};
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;
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++)
{
{
key = g_strdup (name);
}
-
g_hash_table_insert (ctx->aliases, key, value);
return TRUE;
parse_include (GMarkupParseContext *context,
ParseContext *ctx,
const char *name,
+ const char *version,
GError **error)
{
ParseContext sub_ctx = { 0 };
gsize length;
char *girpath;
- girpath = locate_gir (name, ctx->includes);
+ girpath = locate_gir (name, version, ctx->includes);
if (girpath == NULL)
{
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);
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):
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)
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'])
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):
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):
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():
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">
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 \
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 \
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 \
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 \
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"
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"
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"/>
<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>
char * foo_object_dup_name (FooObject *object);
+void foo_object_handle_glyph (FooObject *object, UtilityGlyph glyph);
+
struct _FooSubobject
{
FooObject parent_instance;
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"
GObjectClass parent_class;
};
+/* This one is similar to Pango.Glyph */
+typedef guint32 UtilityGlyph;
+
GType utility_object_get_type (void) G_GNUC_CONST;
typedef enum
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 \
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
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")
# 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