[gobject-introspection] Add an --add-init-section argument
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Add an --add-init-section argument
- Date: Tue, 5 Jan 2010 18:53:45 +0000 (UTC)
commit d3b2976ae77a363d48246afe889860783e6c41d0
Author: Damien Lespiau <damien lespiau intel com>
Date: Thu Dec 24 00:15:21 2009 +0100
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
giscanner/dumper.py | 17 ++++++++++++-----
giscanner/scannermain.py | 3 +++
2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index b11768c..430f81e 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:
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index dfe1743..cc70fde 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -75,6 +75,9 @@ def _get_option_parser():
parser.add_option("", "--strip-prefix",
action="store", dest="strip_prefix", default=None,
help="remove this prefix from objects and functions")
+ parser.add_option("", "--add-init-section",
+ action="append", dest="init_sections", default=[],
+ help="add extra initialization code in the introspection program")
parser.add_option("-o", "--output",
action="store", dest="output",
help="output to writeout, defaults to stdout")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]