Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r64662:c80297370acf Date: 2013-05-29 11:57 +0200 http://bitbucket.org/pypy/pypy/changeset/c80297370acf/
Log: More of the same: try "pkg-config ncurses" before trying "ncurses5-config", and both can give bogus results, so check the results and continue with hard-coded paths afterwards. diff --git a/pypy/module/_minimal_curses/fficurses.py b/pypy/module/_minimal_curses/fficurses.py --- a/pypy/module/_minimal_curses/fficurses.py +++ b/pypy/module/_minimal_curses/fficurses.py @@ -27,12 +27,18 @@ yield ExternalCompilationInfo(libraries=['curses']) yield ExternalCompilationInfo(libraries=['curses', 'tinfo']) -def try_eci(): +def try_tools(): try: - eci = ExternalCompilationInfo.from_config_tool("ncurses5-configx") + yield ExternalCompilationInfo.from_pkg_config("ncurses") except Exception: pass - else: + try: + yield ExternalCompilationInfo.from_config_tool("ncurses5-config") + except Exception: + pass + +def try_eci(): + for eci in try_tools(): yield eci.merge(ExternalCompilationInfo(includes=['curses.h', 'term.h'])) for eci1 in try_cflags(): diff --git a/rpython/translator/tool/cbuild.py b/rpython/translator/tool/cbuild.py --- a/rpython/translator/tool/cbuild.py +++ b/rpython/translator/tool/cbuild.py @@ -1,5 +1,5 @@ import py -import sys +import sys, subprocess from rpython.translator.platform import host from rpython.tool.udir import udir @@ -99,6 +99,7 @@ return platform return self._platform + @classmethod def from_compiler_flags(cls, flags): """Returns a new ExternalCompilationInfo instance by parsing the string 'flags', which is in the typical Unix compiler flags @@ -124,8 +125,8 @@ return cls(pre_include_bits=pre_include_bits, include_dirs=include_dirs, compile_extra=compile_extra) - from_compiler_flags = classmethod(from_compiler_flags) + @classmethod def from_linker_flags(cls, flags): """Returns a new ExternalCompilationInfo instance by parsing the string 'flags', which is in the typical Unix linker flags @@ -146,8 +147,8 @@ return cls(libraries=libraries, library_dirs=library_dirs, link_extra=link_extra) - from_linker_flags = classmethod(from_linker_flags) + @classmethod def from_config_tool(cls, execonfigtool): """Returns a new ExternalCompilationInfo instance by executing the 'execonfigtool' with --cflags and --libs arguments.""" @@ -156,12 +157,26 @@ raise ImportError("cannot find %r" % (execonfigtool,)) # we raise ImportError to be nice to the pypy.config.pypyoption # logic of skipping modules depending on non-installed libs - cflags = py.process.cmdexec('"%s" --cflags' % (str(path),)) + return cls._run_config_tool('"%s"' % (str(path),)) + + @classmethod + def from_pkg_config(cls, pkgname): + """Returns a new ExternalCompilationInfo instance by executing + 'pkg-config <pkgname>' with --cflags and --libs arguments.""" + assert isinstance(pkgname, str) + popen = subprocess.Popen(['pkg-config', pkgname, '--exists']) + result = popen.wait() + if result != 0: + raise ImportError("failed: 'pkg-config %s --exists'" % pkgname) + return cls._run_config_tool('pkg-config "%s"' % pkgname) + + @classmethod + def _run_config_tool(cls, command): + cflags = py.process.cmdexec('%s --cflags' % command) eci1 = cls.from_compiler_flags(cflags) - libs = py.process.cmdexec('"%s" --libs' % (str(path),)) + libs = py.process.cmdexec('%s --libs' % command) eci2 = cls.from_linker_flags(libs) return eci1.merge(eci2) - from_config_tool = classmethod(from_config_tool) def _value(self): return tuple([getattr(self, x) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit