diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-02-15 00:00:00 +0000 |
---|---|---|
committer | Christoph Reiter <reiter.christoph@gmail.com> | 2018-07-28 19:00:55 +0200 |
commit | b80fff2e5a8f327c3128378c12c290dd8e4f7c01 (patch) | |
tree | bdf8e8dd62436a99513e35645245e4641a93245f /giscanner/dumper.py | |
parent | 8bf05589bba98a13dacce1312075af9f04145b82 (diff) | |
download | gobject-introspection-b80fff2e5a8f327c3128378c12c290dd8e4f7c01.tar.gz |
Factor out pkg-config functionality to a separate module.
Functional changes:
* Consistently check that return code from pkg-config is zero.
* Use shell word splitting rules to process pkg-config output to match
behaviour obtained by running `cc program.cc $(pkg-config --cflags ...)`.
Fixes issue #171 .
* Use user preferred encoding to process output from pkg-config on
Python 3. Python 2 behaviour defaults to using ascii encoding as before.
edit creiter: still ignore pkg-config errors by default for now as we
depend on it when glib is a subproject.
Diffstat (limited to 'giscanner/dumper.py')
-rw-r--r-- | giscanner/dumper.py | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/giscanner/dumper.py b/giscanner/dumper.py index bb97bc81..494c7ff7 100644 --- a/giscanner/dumper.py +++ b/giscanner/dumper.py @@ -32,7 +32,7 @@ import tempfile from distutils.errors import LinkError from .gdumpparser import IntrospectionBinary -from . import utils +from . import pkgconfig, utils from .ccompiler import CCompiler # bugzilla.gnome.org/558436 @@ -94,9 +94,8 @@ class DumpCompiler(object): # Acquire the compiler (and linker) commands via the CCompiler class in ccompiler.py self._compiler = CCompiler() - self._pkgconfig_cmd = os.environ.get('PKG_CONFIG', 'pkg-config') self._uninst_srcdir = os.environ.get('UNINSTALLED_INTROSPECTION_SRCDIR') - self._packages = ['gio-2.0 gmodule-2.0'] + self._packages = ['gio-2.0', 'gmodule-2.0'] self._packages.extend(options.packages) if self._compiler.check_is_msvc(): self._linker_cmd = ['link.exe'] @@ -189,21 +188,9 @@ class DumpCompiler(object): self._options.namespace_version, suffix) 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._compiler.check_is_msvc(): - cmd = [self._pkgconfig_cmd, '--msvc-syntax', flag] - else: - cmd = [self._pkgconfig_cmd, flag] - proc = subprocess.Popen( - cmd + self._packages, - stdout=subprocess.PIPE) - out, err = proc.communicate() - return out.decode('ascii').split() - def _compile(self, *sources): - cflags = self._run_pkgconfig('--cflags') + cflags = pkgconfig.cflags(self._packages, + msvc_syntax=self._compiler.check_is_msvc()) cflags.extend(self._options.cflags) return self._compiler.compile(cflags, self._options.cpp_includes, @@ -255,7 +242,8 @@ class DumpCompiler(object): args.extend(sources) - pkg_config_libs = self._run_pkgconfig('--libs') + pkg_config_libs = pkgconfig.libs(self._packages, + msvc_syntax=self._compiler.check_is_msvc()) if not self._options.external_library: self._compiler.get_internal_link_flags(args, |