summaryrefslogtreecommitdiff
path: root/giscanner/dumper.py
diff options
context:
space:
mode:
authorDamien Lespiau <damien.lespiau@intel.com>2009-12-24 00:15:21 +0100
committerColin Walters <walters@verbum.org>2010-01-05 13:50:55 -0500
commitd3b2976ae77a363d48246afe889860783e6c41d0 (patch)
tree3ce485c7aa0320009daf29505625df1951236fb4 /giscanner/dumper.py
parentab1af50d167da42f5b927c9cf7373c7bc7f87a89 (diff)
downloadgobject-introspection-d3b2976ae77a363d48246afe889860783e6c41d0.tar.gz
Add an --add-init-section argument
One might need to call some init functions before being able to call get_type() to create the types of a library. --add-init-section let the user insert some initialization code in the introspection program. https://bugzilla.gnome.org/show_bug.cgi?id=605778
Diffstat (limited to 'giscanner/dumper.py')
-rw-r--r--giscanner/dumper.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index b11768c4..430f81ee 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -30,7 +30,7 @@ from .utils import get_libtool_command
# Compile a binary program which is then linked to a library
# we want to introspect, in order to call its get_type functions.
-_PROGRAM_TEMPLATE = '''/* This file is generated, do not edit */
+_PROGRAM_TEMPLATE = """/* This file is generated, do not edit */
#include <glib.h>
#include <girepository.h>
#include <string.h>
@@ -49,19 +49,21 @@ main(int argc, char **argv)
if (!g_thread_supported ()) g_thread_init (NULL);
g_type_init ();
+ %(init_sections)s
+
context = g_option_context_new ("");
g_option_context_add_main_entries (context, entries, "girepository-1.0");
g_option_context_add_group (context, g_irepository_get_option_group ());
if (!g_option_context_parse (context, &argc, &argv, &error))
{
- g_printerr ("introspect failed (%d,%d): %s\\n",
+ g_printerr ("introspect failed (%%d,%%d): %%s\\n",
error->domain, error->code,
error->message);
return 1;
}
return 0;
}
-'''
+"""
class CompilerError(Exception):
@@ -94,9 +96,12 @@ class DumpCompiler(object):
# Public API
def run(self):
+ tpl_args = {}
+ tpl_args['init_sections'] = "\n".join(self._options.init_sections)
+
c_path = self._generate_tempfile('.c')
f = open(c_path, 'w')
- f.write(_PROGRAM_TEMPLATE)
+ f.write(_PROGRAM_TEMPLATE % tpl_args)
# We need to reference our get_type functions to make sure they are
# pulled in at the linking stage if the library is a static library
@@ -148,7 +153,9 @@ class DumpCompiler(object):
def _compile(self, output, *sources):
# Not strictly speaking correct, but easier than parsing shell
args = self._compiler_cmd.split()
- if self._compiler_cmd == 'gcc':
+ # Do not add -Wall when using init code as we do not include any
+ # header of the library being introspected
+ if self._compiler_cmd == 'gcc' and not self._options.init_sections:
args.append('-Wall')
pkgconfig_flags = self._run_pkgconfig('--cflags')
if self._uninst_srcdir: