summaryrefslogtreecommitdiff
path: root/giscanner/ccompiler.py
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2017-04-20 18:47:03 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2017-05-03 16:30:59 +0800
commit5d4cd25292b8ed2c7a821ebe19fc5ab5d447db1a (patch)
treed3da013a6c572c9ec4e63583050b440204aed428 /giscanner/ccompiler.py
parent6b703b3211ce45389a777a439ccdf8fd64ed2b30 (diff)
downloadgobject-introspection-5d4cd25292b8ed2c7a821ebe19fc5ab5d447db1a.tar.gz
giscanner: Do not use distutils for linking
...the dumper program for all cases. It turned out that using distutils for linking is more troublesome than useful as we need to ensure that the paths specified by -L need to come before the standard library search paths, and distutil's ccompiler.add_library_path() and ccompiler.add_runtime_library_path() does not work for all of its supported compilers (Visual Studio is an example). Instead, we go back to constructing our linker command line manually as we did before (and as we now do in the libtool case), but with some enhancements: -Use '-libpath:' on Visual Studio builds, which corresponds to the -L flag on GCC/CLang. -Extend LIB/PATH (Windows/Visual Studio) or LD_LIBRARY_PATH (other compilers/envs), which is necessary as we resolve the libraries that are passed into g-ir-scanner, at least on Windows. -Don't attempt to link to or resolve m.lib on Visual Studio builds, as the math functions are in the standard CRT .lib/.dll, and there is no such thing as m.lib https://bugzilla.gnome.org/show_bug.cgi?id=781525
Diffstat (limited to 'giscanner/ccompiler.py')
-rw-r--r--giscanner/ccompiler.py96
1 files changed, 47 insertions, 49 deletions
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index 155b61d4..9951cc7a 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -113,22 +113,18 @@ class CCompiler(object):
# An "internal" link is where the library to be introspected
# is being built in the current directory.
- if not libtool:
- # non-libtool case: prepare distutils use
- if self.check_is_msvc():
- for library in libraries + extra_libraries:
- # MSVC Builds don't use libtool, so no .la libraries,
- # so just add the library directly.
- self.compiler.add_library(library)
- for libpath in libpaths:
- self.compiler.add_library_dir(libpath)
- else:
- # Search the current directory first
- # (This flag is not supported nor needed for Visual C++)
- self.compiler.add_library_dir('.')
- if os.name != 'nt':
- self.compiler.add_runtime_library_dir('.')
+ runtime_path_envvar = []
+ runtime_paths = []
+
+ if self.check_is_msvc():
+ runtime_path_envvar = ['LIB', 'PATH']
+ else:
+ runtime_path_envvar = ['LD_LIBRARY_PATH']
+ # Search the current directory first
+ # (This flag is not supported nor needed for Visual C++)
+ args.append('-L.')
+ if not libtool:
# https://bugzilla.gnome.org/show_bug.cgi?id=625195
args.append('-Wl,-rpath,.')
@@ -137,37 +133,51 @@ class CCompiler(object):
if sys.platform != 'darwin':
args.append('-Wl,--no-as-needed')
- for library in libraries + extra_libraries:
- self.compiler.add_library(library)
- if not self.check_is_msvc():
- for library_path in libpaths:
- args.append('-L' + library_path)
- if os.path.isabs(library_path):
- args.append('-Wl,-rpath,' + library_path)
-
- else:
- # libtool case: assemble linker command arguments, like we did before
- args.append('-L.')
- for library in libraries:
+ for library in libraries + extra_libraries:
+ if self.check_is_msvc():
+ # Note that Visual Studio builds do not use libtool!
+ if library != 'm':
+ args.append(library + '.lib')
+ else:
if library.endswith(".la"): # explicitly specified libtool library
args.append(library)
else:
args.append('-l' + library)
- for library_path in libpaths:
+ for library_path in libpaths:
+ # The dumper program needs to look for dynamic libraries
+ # in the library paths first
+ if self.check_is_msvc():
+ library_path = library_path.replace('/', '\\')
+ args.append('-libpath:' + library_path)
+ else:
args.append('-L' + library_path)
if os.path.isabs(library_path):
- args.append('-rpath')
- args.append(library_path)
+ if libtool:
+ args.append('-rpath')
+ args.append(library_path)
+ else:
+ args.append('-Wl,-rpath=' + library_path)
+
+ runtime_paths.append(library_path)
+
+ for envvar in runtime_path_envvar:
+ if envvar in os.environ:
+ os.environ[envvar] = \
+ os.pathsep.join(runtime_paths + [os.environ[envvar]])
+ else:
+ os.environ[envvar] = os.pathsep.join(runtime_paths)
- def get_external_link_flags(self, args, libtool, libraries):
+ def get_external_link_flags(self, args, libraries):
# An "external" link is where the library to be introspected
# is installed on the system; this case is used for the scanning
# of GLib in gobject-introspection itself.
for library in libraries:
- if not libtool:
- self.compiler.add_library(library)
+ if self.check_is_msvc():
+ # Visual Studio: don't attempt to link to m.lib
+ if library != 'm':
+ args.append(library + ".lib")
else:
if library.endswith(".la"): # explicitly specified libtool library
args.append(library)
@@ -240,22 +250,6 @@ class CCompiler(object):
extra_postargs=extra_postargs,
output_dir=os.path.abspath(os.sep))
- def link(self, output, objects, lib_args):
- # Note: This is used for non-libtool builds only!
- extra_preargs = []
- extra_postargs = []
- library_dirs = []
- libraries = []
-
- for arg in lib_args:
- extra_postargs.append(arg)
-
- self.compiler.link(target_desc=self.compiler.EXECUTABLE,
- objects=objects,
- output_filename=output,
- extra_preargs=extra_preargs,
- extra_postargs=extra_postargs)
-
def resolve_windows_libs(self, libraries, options):
args = []
libsearch = []
@@ -278,6 +272,10 @@ class CCompiler(object):
args.append('dumpbin.exe')
args.append('-symbols')
+ # Work around the attempt to resolve m.lib on Python 2.x
+ if sys.version_info.major < 3:
+ libraries[:] = [lib for lib in libraries if lib != 'm']
+
# When we are not using Visual C++ (i.e. we are using GCC)...
else:
libtool = utils.get_libtool_command(options)