summaryrefslogtreecommitdiff
path: root/giscanner/dumper.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/dumper.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/dumper.py')
-rw-r--r--giscanner/dumper.py105
1 files changed, 39 insertions, 66 deletions
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index 793177b0..7f77bd24 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -99,10 +99,10 @@ class DumpCompiler(object):
self._uninst_srcdir = os.environ.get('UNINSTALLED_INTROSPECTION_SRCDIR')
self._packages = ['gio-2.0 gmodule-2.0']
self._packages.extend(options.packages)
- if hasattr(self._compiler.compiler, 'linker_exe'):
- self._linker_cmd = self._compiler.compiler.linker_exe
+ if self._compiler.check_is_msvc():
+ self._linker_cmd = ['link.exe']
else:
- self._linker_cmd = []
+ self._linker_cmd = shlex.split(os.environ.get('CC', 'cc'))
# Public API
@@ -212,21 +212,25 @@ class DumpCompiler(object):
libtool = utils.get_libtool_command(self._options)
if libtool:
# Note: MSVC Builds do not use libtool!
- # In the libtool case, put together the linker command, as we did before.
- # We aren't using distutils to link in this case.
args.extend(libtool)
args.append('--mode=link')
args.append('--tag=CC')
if self._options.quiet:
args.append('--silent')
- args.extend(self._linker_cmd)
+ args.extend(self._linker_cmd)
+ # We can use -o for the Microsoft compiler/linker,
+ # but it is considered deprecated usage
+ if self._compiler.check_is_msvc():
+ args.extend(['-out:' + output])
+ else:
args.extend(['-o', output])
- if os.name == 'nt':
- args.append('-Wl,--export-all-symbols')
- else:
- args.append('-export-dynamic')
+ if libtool:
+ if os.name == 'nt':
+ args.append('-Wl,--export-all-symbols')
+ else:
+ args.append('-export-dynamic')
if not self._compiler.check_is_msvc():
# These envvars are not used for MSVC Builds!
@@ -246,8 +250,7 @@ class DumpCompiler(object):
raise CompilerError(
"Could not find object file: %s" % (source, ))
- if libtool:
- args.extend(sources)
+ args.extend(sources)
pkg_config_libs = self._run_pkgconfig('--libs')
@@ -261,66 +264,36 @@ class DumpCompiler(object):
else:
args.extend(pkg_config_libs)
- self._compiler.get_external_link_flags(args,
- libtool,
- self._options.libraries)
+ self._compiler.get_external_link_flags(args, self._options.libraries)
if not self._compiler.check_is_msvc():
for ldflag in shlex.split(os.environ.get('LDFLAGS', '')):
args.append(ldflag)
- if not libtool:
- # non-libtool: prepare distutils for linking the introspection
- # dumper program...
- try:
- self._compiler.link(output,
- sources,
- args)
-
- # Ignore failing to embed the manifest files, when the manifest
- # file does not exist, especially for MSVC 2010 and later builds.
- # If we are on Visual C++ 2005/2008, where
- # this embedding is required, the build will fail anyway, as
- # the dumper program will likely fail to run, and this means
- # something went wrong with the build.
- except LinkError as e:
- if self._compiler.check_is_msvc():
- msg = str(e)
-
- if msg[msg.rfind('mt.exe'):] == 'mt.exe\' failed with exit status 31':
- if sys.version_info < (3, 0):
- sys.exc_clear()
- pass
- else:
- raise LinkError(e)
- else:
- raise LinkError(e)
- else:
- # libtool: Run the assembled link command, we don't use distutils
- # for linking here.
- if not self._options.quiet:
- print("g-ir-scanner: link: %s" % (
- subprocess.list2cmdline(args), ))
- sys.stdout.flush()
- msys = os.environ.get('MSYSTEM', None)
+ if not self._options.quiet:
+ print("g-ir-scanner: link: %s" % (
+ subprocess.list2cmdline(args), ))
+ sys.stdout.flush()
+
+ msys = os.environ.get('MSYSTEM', None)
+ if msys:
+ shell = os.environ.get('SHELL', 'sh.exe')
+ # Create a temporary script file that
+ # runs the command we want
+ tf, tf_name = tempfile.mkstemp()
+ with os.fdopen(tf, 'wb') as f:
+ shellcontents = ' '.join([x.replace('\\', '/') for x in args])
+ fcontents = '#!/bin/sh\nunset PWD\n{}\n'.format(shellcontents)
+ f.write(fcontents)
+ shell = utils.which(shell)
+ args = [shell, tf_name.replace('\\', '/')]
+ try:
+ subprocess.check_call(args)
+ except subprocess.CalledProcessError as e:
+ raise LinkerError(e)
+ finally:
if msys:
- shell = os.environ.get('SHELL', 'sh.exe')
- # Create a temporary script file that
- # runs the command we want
- tf, tf_name = tempfile.mkstemp()
- with os.fdopen(tf, 'wb') as f:
- shellcontents = ' '.join([x.replace('\\', '/') for x in args])
- fcontents = '#!/bin/sh\nunset PWD\n{}\n'.format(shellcontents)
- f.write(fcontents)
- shell = utils.which(shell)
- args = [shell, tf_name.replace('\\', '/')]
- try:
- subprocess.check_call(args)
- except subprocess.CalledProcessError as e:
- raise LinkerError(e)
- finally:
- if msys:
- os.remove(tf_name)
+ os.remove(tf_name)
def compile_introspection_binary(options, get_type_functions,