summaryrefslogtreecommitdiff
path: root/giscanner/dumper.py
diff options
context:
space:
mode:
Diffstat (limited to 'giscanner/dumper.py')
-rw-r--r--giscanner/dumper.py127
1 files changed, 99 insertions, 28 deletions
diff --git a/giscanner/dumper.py b/giscanner/dumper.py
index f78d2ae8..b415dd13 100644
--- a/giscanner/dumper.py
+++ b/giscanner/dumper.py
@@ -45,7 +45,9 @@ main(int argc, char **argv)
GError *error = NULL;
const char *introspect_dump_prefix = "--introspect-dump=";
+#if !GLIB_CHECK_VERSION(2,35,0)
g_type_init ();
+#endif
%(init_sections)s
@@ -80,10 +82,16 @@ class DumpCompiler(object):
self._get_type_functions = get_type_functions
self._error_quark_functions = error_quark_functions
- self._compiler_cmd = os.environ.get('CC', 'gcc')
+ self._compiler_cmd = os.environ.get('CC', 'cc')
self._linker_cmd = os.environ.get('CC', self._compiler_cmd)
self._pkgconfig_cmd = os.environ.get('PKG_CONFIG', 'pkg-config')
-
+ self._pkgconfig_msvc_flags = ''
+ # Enable the --msvc-syntax pkg-config flag when
+ # the Microsoft compiler is used
+ # (This is the other way to check whether Visual C++ is used subsequently)
+ args = self._compiler_cmd.split()
+ if 'cl.exe' in args or 'cl' in args:
+ self._pkgconfig_msvc_flags = '--msvc-syntax'
self._uninst_srcdir = os.environ.get(
'UNINSTALLED_INTROSPECTION_SRCDIR')
self._packages = ['gio-2.0 gmodule-2.0']
@@ -143,7 +151,12 @@ class DumpCompiler(object):
f.write("\n};\n")
f.close()
- o_path = self._generate_tempfile(tmpdir, '.o')
+ # Microsoft compilers generate intermediate .obj files
+ # during compilation, unlike .o files like GCC and others
+ if self._pkgconfig_msvc_flags:
+ o_path = self._generate_tempfile(tmpdir, '.obj')
+ else:
+ o_path = self._generate_tempfile(tmpdir, '.o')
if os.name == 'nt':
ext = 'exe'
@@ -154,14 +167,14 @@ class DumpCompiler(object):
try:
self._compile(o_path, c_path)
- except CompilerError, e:
+ except CompilerError as e:
if not utils.have_debug_flag('save-temps'):
shutil.rmtree(tmpdir)
raise SystemExit('compilation of temporary binary failed:' + str(e))
try:
self._link(bin_path, o_path)
- except LinkerError, e:
+ except LinkerError as e:
if not utils.have_debug_flag('save-temps'):
shutil.rmtree(tmpdir)
raise SystemExit('linking of temporary binary failed: ' + str(e))
@@ -176,8 +189,14 @@ class DumpCompiler(object):
return os.path.join(tmpdir, tmpl)
def _run_pkgconfig(self, flag):
+ # Enable the --msvc-syntax pkg-config flag when
+ # the Microsoft compiler is used
+ if self._pkgconfig_msvc_flags:
+ cmd = [self._pkgconfig_cmd, self._pkgconfig_msvc_flags, flag]
+ else:
+ cmd = [self._pkgconfig_cmd, flag]
proc = subprocess.Popen(
- [self._pkgconfig_cmd, flag] + self._packages,
+ cmd + self._packages,
stdout=subprocess.PIPE)
return proc.communicate()[0].split()
@@ -188,14 +207,28 @@ class DumpCompiler(object):
# header of the library being introspected
if self._compiler_cmd == 'gcc' and not self._options.init_sections:
args.append('-Wall')
+ # The Microsoft compiler uses different option flags for
+ # silencing warnings on deprecated function usage
+ if self._pkgconfig_msvc_flags:
+ args.append("-wd4996")
+ else:
+ args.append("-Wno-deprecated-declarations")
pkgconfig_flags = self._run_pkgconfig('--cflags')
- args.extend(pkgconfig_flags)
+ args.extend([utils.cflag_real_include_path(f) for f in pkgconfig_flags])
+ cppflags = os.environ.get('CPPFLAGS', '')
+ for cppflag in cppflags.split():
+ args.append(cppflag)
cflags = os.environ.get('CFLAGS', '')
for cflag in cflags.split():
args.append(cflag)
for include in self._options.cpp_includes:
args.append('-I' + include)
- args.extend(['-c', '-o', output])
+ # The Microsoft compiler uses different option flags for
+ # compilation result output
+ if self._pkgconfig_msvc_flags:
+ args.extend(['-c', '-Fe' + output, '-Fo' + output])
+ else:
+ args.extend(['-c', '-o', output])
for source in sources:
if not os.path.exists(source):
raise CompilerError(
@@ -207,7 +240,7 @@ class DumpCompiler(object):
sys.stdout.flush()
try:
subprocess.check_call(args)
- except subprocess.CalledProcessError, e:
+ except subprocess.CalledProcessError as e:
raise CompilerError(e)
def _link(self, output, *sources):
@@ -221,13 +254,21 @@ class DumpCompiler(object):
args.append('--silent')
args.extend(self._linker_cmd.split())
- args.extend(['-o', output])
+ # We can use -o for the Microsoft compiler/linker,
+ # but it is considered deprecated usage with that
+ if self._pkgconfig_msvc_flags:
+ args.extend(['-Fe' + output])
+ else:
+ args.extend(['-o', output])
if libtool:
if os.name == 'nt':
args.append('-export-all-symbols')
else:
args.append('-export-dynamic')
+ cppflags = os.environ.get('CPPFLAGS', '')
+ for cppflag in cppflags.split():
+ args.append(cppflag)
cflags = os.environ.get('CFLAGS', '')
for cflag in cflags.split():
args.append(cflag)
@@ -256,7 +297,7 @@ class DumpCompiler(object):
sys.stdout.flush()
try:
subprocess.check_call(args)
- except subprocess.CalledProcessError, e:
+ except subprocess.CalledProcessError as e:
raise LinkerError(e)
def _add_link_internal_args(self, args, libtool):
@@ -264,26 +305,52 @@ class DumpCompiler(object):
# is being built in the current directory.
# Search the current directory first
- args.append('-L.')
+ # (This flag is not supported nor needed for Visual C++)
+ if self._pkgconfig_msvc_flags == '':
+ args.append('-L.')
# https://bugzilla.gnome.org/show_bug.cgi?id=625195
if not libtool:
- args.append('-Wl,-rpath=.')
+ # We don't have -Wl,-rpath for Visual C++, and that's
+ # going to cause a problem. Instead, link to internal
+ # libraries by deducing the .lib file name using
+ # the namespace name and version
+ if self._pkgconfig_msvc_flags:
+ if self._options.namespace_version:
+ args.append(str.lower(self._options.namespace_name) +
+ '-' +
+ self._options.namespace_version + '.lib')
+ else:
+ args.append(str.lower(self._options.namespace_name) + '.lib')
+ else:
+ args.append('-Wl,-rpath=.')
+
+ # Ensure libraries are always linked as we are going to use ldd to work
+ # out their names later
+ if not libtool and self._pkgconfig_msvc_flags == '':
+ args.append('-Wl,--no-as-needed')
for library in self._options.libraries:
- if library.endswith(".la"): # explicitly specified libtool library
- args.append(library)
- else:
- args.append('-l' + library)
+ # Visual C++: We have the needed .lib files now, and we need to link
+ # to .lib files, not the .dll as the --library option specifies the
+ # .dll(s) the .gir file refers to
+ if self._pkgconfig_msvc_flags == '':
+ if library.endswith(".la"): # explicitly specified libtool library
+ args.append(library)
+ else:
+ args.append('-l' + library)
for library_path in self._options.library_paths:
- args.append('-L' + library_path)
- if os.path.isabs(library_path):
- if libtool:
- args.append('-rpath')
- args.append(library_path)
- else:
- args.append('-Wl,-rpath=' + library_path)
+ # Not used/needed on Visual C++, and -Wl,-rpath options
+ # will cause grief
+ if self._pkgconfig_msvc_flags == '':
+ args.append('-L' + library_path)
+ if os.path.isabs(library_path):
+ if libtool:
+ args.append('-rpath')
+ args.append(library_path)
+ else:
+ args.append('-Wl,-rpath=' + library_path)
args.extend(self._run_pkgconfig('--libs'))
@@ -294,10 +361,14 @@ class DumpCompiler(object):
args.extend(self._run_pkgconfig('--libs'))
for library in self._options.libraries:
- if library.endswith(".la"): # explicitly specified libtool library
- args.append(library)
- else:
- args.append('-l' + library)
+ # The --library option on Windows pass in the .dll file(s) the
+ # .gir files refer to, so don't link to them on Visual C++
+ if self._pkgconfig_msvc_flags == '':
+ if library.endswith(".la"): # explicitly specified libtool library
+ args.append(library)
+ else:
+ args.append('-l' + library)
+
def compile_introspection_binary(options, get_type_functions,
error_quark_functions):