In addition to the current --library=<foo>, support --library=lib<foo>.la.
This makes it unambiguous that we are referencing an uninstalled
library and allows accurate extraction of the shared library name
for the uninstalled library.
* tests/scanner/Makefile.am tests/offsets/Makefile.am: Use the
new form of --library=. Also some LD_LIBRARY_PATH frobbing as needed.
*-expected.gir *-expected.tgir: We now pick out the shared library
accurately, so fix shared-library="" in our reference girs. (The
comparison may need some pre-sanitization now to work on non-ELF)
http://bugzilla.gnome.org/show_bug.cgi?id=591669
if (uninst_builddir and
self._options.libraries[0] == 'girepository-1.0'):
continue
- args.append('-l' + library)
+ if library.endswith(".la"): # explicitly specified libtool library
+ args.append(library)
+ else:
+ args.append('-l' + library)
# hack for building gobject-introspection itself
if uninst_builddir:
import re
import subprocess
-from .utils import get_libtool_command
+from .utils import get_libtool_command, extract_libtool_shlib
+
+# For .la files, the situation is easy.
+def _resolve_libtool(options, binary, libraries):
+ shlibs = []
+ for library in libraries:
+ shlib = extract_libtool_shlib(library)
+ if shlib:
+ shlibs.append(shlib)
+
+ return shlibs
# Assume ldd output is something vaguely like
#
# The negative lookbehind at the start is to avoid problems if someone
# is crazy enough to name a library liblib<foo> when lib<foo> exists.
#
-def _library_pattern(library_name):
+def _ldd_library_pattern(library_name):
return re.compile("(?<![A-Za-z0-9_-])(lib*%s[^A-Za-z0-9_-][^\s\(\)]*)"
% re.escape(library_name))
-# We want to resolve a set of library names (the <foo> of -l<foo>)
-# against a library to find the shared library name. The shared
-# library name is suppose to be what you pass to dlopen() (or
-# equivalent). And we want to do this using the libraries that 'binary'
-# is linking against. The implementation below assumes that we are on an
+# This is a what we do for non-la files. We assume that we are on an
# ELF-like system where ldd exists and the soname extracted with ldd is
-# a filename that can be opened with dlopen(). Alternate implementations
-# could be added here.
+# a filename that can be opened with dlopen().
#
-def resolve_shlibs(options, binary, libraries):
+# On OS X this will need a straightforward alternate implementation
+# in terms of otool.
+#
+# Windows is more difficult, since there isn't always a straightforward
+# translation between library name (.lib) and the name of the .dll, so
+# extracting the dll names from the compiled app may not be sufficient.
+# We might need to hunt down the .lib in the compile-time path and
+# use that to figure out the name of the DLL.
+#
+def _resolve_non_libtool(options, binary, libraries):
+ if not libraries:
+ return []
+
args = []
libtool = get_libtool_command(options)
if libtool:
proc = subprocess.Popen(args, stdout=subprocess.PIPE)
patterns = {}
for library in libraries:
- patterns[library] = _library_pattern(library)
+ patterns[library] = _ldd_library_pattern(library)
shlibs = []
for line in proc.stdout:
", ".join(patterns.keys()))
return shlibs
+
+# We want to resolve a set of library names (the <foo> of -l<foo>)
+# against a library to find the shared library name. The shared
+# library name is suppose to be what you pass to dlopen() (or
+# equivalent). And we want to do this using the libraries that 'binary'
+# is linking against.
+#
+def resolve_shlibs(options, binary, libraries):
+ libtool = filter(lambda x: x.endswith(".la"), libraries)
+ non_libtool = filter(lambda x: not x.endswith(".la"), libraries)
+
+ return (_resolve_libtool(options, binary, libtool) +
+ _resolve_non_libtool(options, binary, non_libtool))
import re
import os
+import subprocess
# Copied from h2defs.py
_upperstr_pat1 = re.compile(r'([^A-Z])([A-Z])')
_libtool_pat = re.compile("dlname='([A-z0-9\.\-\+]+)'\n")
+def _extract_dlname_field(la_file):
+ f = open(la_file)
+ data = f.read()
+ f.close()
+ m = _libtool_pat.search(data)
+ if m:
+ return m.groups()[0]
+ else:
+ return None
+
+# Returns the name that we would pass to dlopen() the library
+# corresponding to this .la file
+def extract_libtool_shlib(la_file):
+ dlname = _extract_dlname_field(la_file)
+ if dlname is None:
+ return None
+
+ # From the comments in extract_libtool(), older libtools had
+ # a path rather than the raw dlname
+ return os.path.basename(dlname)
-def extract_libtool(libname):
- data = open(libname).read()
- filename = _libtool_pat.search(data).groups()[0]
- libname = os.path.join(os.path.dirname(libname),
- '.libs', filename)
+def extract_libtool(la_file):
+ dlname = _extract_dlname_field(la_file)
+ if dlname is None:
+ raise ValueError("%s has no dlname. Not a shared library?" % la_file)
+ libname = os.path.join(os.path.dirname(la_file),
+ '.libs', dlname)
# FIXME: This hackish, but I'm not sure how to do this
# in a way which is compatible with both libtool 2.2
# and pre-2.2. Johan 2008-10-21
$(CHECK_DEBUG) $(SCANNER) \
--include=GObject-2.0 \
--libtool="$(SHAVE_SAVED_LIBTOOL)" \
- --library=offsets \
+ --library=liboffsets.la \
--namespace=offsets \
--nsversion=1.0 \
--pkg gobject-2.0 \
--output $@
%.typelib: %.gir $(top_builddir)/tools/g-ir-compiler$(EXEEXT) Makefile
- $(top_builddir)/tools/g-ir-compiler --includedir=. --includedir=$(top_builddir)/gir $< -o $@
+ LD_LIBRARY_PATH=$(top_builddir)/girepository/.libs:$(builddir)/.libs$${LD_LIBRARY_PATH:+:$$LD_LIBRARY_PATH} \
+ $(top_builddir)/tools/g-ir-compiler --includedir=. --includedir=$(top_builddir)/gir $< -o $@
CLEANFILES += offsets-1.0.gir offsets-1.0.typelib
############################################################
check-local: offsets-1.0.typelib
- LD_LIBRARY_PATH=$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:} GI_TYPELIB_PATH=:$(top_builddir)/gir \
- gitestoffsets$(EXEEXT) offsets.compiled offsets.introspected
+ LD_LIBRARY_PATH=$(top_builddir)/girepository/.libs:$(builddir)/.libs$${LD_LIBRARY_PATH:+:$$LD_LIBRARY_PATH} \
+ GI_TYPELIB_PATH=:$(top_builddir)/gir gitestoffsets$(EXEEXT) offsets.compiled offsets.introspected
diff -u offsets.compiled offsets.introspected
CLEANFILES += offsets.compiled offsets.introspected
<package name="gobject-2.0"/>
<namespace name="GtkFrob"
version="1.0"
- shared-library="gtkfrob"
+ shared-library="libgtkfrob.so"
c:prefix="Gtk">
<function name="language_manager_get_default"
c:identifier="gtk_frob_language_manager_get_default">
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
- <namespace name="GtkFrob" version="1.0" shared-library="gtkfrob" c:prefix="Gtk">
+ <namespace name="GtkFrob" version="1.0" shared-library="libgtkfrob.so" c:prefix="Gtk">
<function name="language_manager_get_default" c:identifier="gtk_frob_language_manager_get_default">
<return-value transfer-ownership="none">
<type name="none"/>
--include=GObject-2.0 \
--include=utility-1.0 \
--libtool="$(LIBTOOL)" \
- --library=annotation \
+ --library=libannotation.la \
--namespace=annotation \
--nsversion=1.0 \
--pkg gobject-2.0 \
--include=GObject-2.0 \
--include=utility-1.0 \
--libtool="$(LIBTOOL)" \
- --library=drawable \
+ --library=libdrawable.la \
--namespace=drawable \
--nsversion=1.0 \
--pkg gobject-2.0 \
--include=utility-1.0 \
--c-include="foo.h" \
--libtool="$(LIBTOOL)" \
- --library=foo \
+ --library=libfoo.la \
--namespace=foo \
--nsversion=1.0 \
--pkg gobject-2.0 \
$(CHECK_DEBUG) $(SCANNER) \
--include=GObject-2.0 \
--libtool="$(LIBTOOL)" \
- --library=utility \
+ --library=libutility.la \
--namespace=utility \
--nsversion=1.0 \
--pkg gobject-2.0 \
$(CHECK_DEBUG) $(SCANNER) \
--include=GObject-2.0 \
--libtool="$(LIBTOOL)" \
- --library=gtkfrob \
+ --library=libgtkfrob.la \
--namespace=GtkFrob \
--strip-prefix=Gtk \
--nsversion=1.0 \
<package name="gobject-2.0"/>
<namespace name="annotation"
version="1.0"
- shared-library="annotation"
+ shared-library="libannotation.so"
c:prefix="annotation">
<callback name="Callback"
c:type="AnnotationCallback"
<include name="utility" version="1.0"/>
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
- <namespace name="annotation" version="1.0" shared-library="annotation" c:prefix="annotation">
+ <namespace name="annotation" version="1.0" shared-library="libannotation.so" c:prefix="annotation">
<callback name="Callback">
<return-value transfer-ownership="none">
<type name="int"/>
<package name="gobject-2.0"/>
<namespace name="drawable"
version="1.0"
- shared-library="drawable"
+ shared-library="libdrawable.so"
c:prefix="drawable">
<class name="TestDrawable"
c:type="TestDrawable"
<include name="utility" version="1.0"/>
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
- <namespace name="drawable" version="1.0" shared-library="drawable" c:prefix="drawable">
+ <namespace name="drawable" version="1.0" shared-library="libdrawable.so" c:prefix="drawable">
<class name="TestDrawable" parent="GObject.Object" glib:type-struct="TestDrawableClass" abstract="1" glib:type-name="TestDrawable" glib:get-type="test_drawable_get_type">
<field name="parent_instance">
<type name="GObject.Object"/>
<include name="utility" version="1.0"/>
<package name="gobject-2.0"/>
<c:include name="foo.h"/>
- <namespace name="foo" version="1.0" shared-library="foo" c:prefix="foo">
+ <namespace name="foo"
+ version="1.0"
+ shared-library="libfoo.so"
+ c:prefix="foo">
<alias name="List" target="GLib.SList" c:type="FooList"/>
<alias name="ObjectCookie" target="any" c:type="FooObjectCookie"/>
<alias name="XEvent" target="none" c:type="FooXEvent"/>
<include name="utility" version="1.0"/>
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
- <namespace name="foo" version="1.0" shared-library="foo" c:prefix="foo">
+ <namespace name="foo" version="1.0" shared-library="libfoo.so" c:prefix="foo">
<enumeration name="ASingle">
<member name="some_single_enum" value="0"/>
</enumeration>
<package name="gobject-2.0"/>
<namespace name="utility"
version="1.0"
- shared-library="utility"
+ shared-library="libutility.so"
c:prefix="utility">
<alias name="Glyph" target="uint32" c:type="UtilityGlyph"/>
<record name="Buffer" c:type="UtilityBuffer">
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GObject" version="2.0"/>
<include name="GLib" version="2.0"/>
- <namespace name="utility" version="1.0" shared-library="utility" c:prefix="utility">
+ <namespace name="utility" version="1.0" shared-library="libutility.so" c:prefix="utility">
<record name="Buffer">
<field name="data" writable="1">
<type name="any"/>