[pypy-svn] r54891 - in pypy/dist/pypy: config module/readline rpython/tool rpython/tool/test tool tool/test translator/tool
arigo at codespeak.net
arigo at codespeak.net
Sun May 18 17:11:37 CEST 2008
Author: arigo
Date: Sun May 18 17:11:35 2008
New Revision: 54891
Modified:
pypy/dist/pypy/config/pypyoption.py
pypy/dist/pypy/module/readline/c_readline.py
pypy/dist/pypy/rpython/tool/rffi_platform.py
pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
pypy/dist/pypy/tool/gcc_cache.py
pypy/dist/pypy/tool/test/test_gcc_cache.py
pypy/dist/pypy/translator/tool/cbuild.py
Log:
Whack whack whack until the logic for skipping modules from
--allworkingmodules if the C code snippets cannot be compiled.
In this attempt, we should see the whole C compiler output
when running translate.py.
Modified: pypy/dist/pypy/config/pypyoption.py
==============================================================================
--- pypy/dist/pypy/config/pypyoption.py (original)
+++ pypy/dist/pypy/config/pypyoption.py Sun May 18 17:11:35 2008
@@ -56,6 +56,7 @@
module_import_dependencies = {
# no _rawffi if importing pypy.rlib.libffi raises ImportError
+ # or CompilationError
"_rawffi": ["pypy.rlib.libffi"],
}
@@ -63,16 +64,17 @@
if modname in module_import_dependencies:
modlist = module_import_dependencies[modname]
def validator(config):
+ from pypy.rpython.tool.rffi_platform import CompilationError
try:
for name in modlist:
__import__(name)
- except ImportError, e:
- err = "%s: %s" % (e.__class__.__name__, e)
+ except (ImportError, CompilationError), e:
+ errcls = e.__class__.__name__
config.add_warning(
"The module %r is disabled\n" % (modname,) +
- "because importing %s raised\n" % (name,) +
- err)
- raise ConfigError("--withmod-%s: %s" % (modname, err))
+ "because importing %s raised %s\n" % (name, errcls) +
+ str(e))
+ raise ConfigError("--withmod-%s: %s" % (modname, errcls))
return validator
else:
return None
Modified: pypy/dist/pypy/module/readline/c_readline.py
==============================================================================
--- pypy/dist/pypy/module/readline/c_readline.py (original)
+++ pypy/dist/pypy/module/readline/c_readline.py Sun May 18 17:11:35 2008
@@ -8,15 +8,18 @@
# we also need to link with some variant of curses or libtermcap.
# We follow the logic of CPython below.
def try_with_lib(extralibs, **kwds):
+ global most_recent_error
# at least on Gentoo Linux, readline.h doesn't compile if stdio.h is not
# included before
eci = ExternalCompilationInfo(
includes = ["stdio.h", "readline/readline.h", "readline/history.h"],
libraries = extralibs + ['readline'],
)
- if platform.check_eci(eci):
+ try:
+ platform.verify_eci(eci)
return eci
- else:
+ except platform.CompilationError, e:
+ most_recent_error = e
return None
eci = (try_with_lib([]) or
@@ -25,7 +28,7 @@
try_with_lib(['curses']) or
try_with_lib(['termcap'], library_dirs=['/usr/lib/termcap']))
if eci is None:
- raise Exception("cannot find how to link to the readline library")
+ raise most_recent_error
# ____________________________________________________________
Modified: pypy/dist/pypy/rpython/tool/rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/rffi_platform.py (original)
+++ pypy/dist/pypy/rpython/tool/rffi_platform.py Sun May 18 17:11:35 2008
@@ -6,6 +6,7 @@
from pypy.rpython.lltypesystem import llmemory
from pypy.tool.gcc_cache import build_executable_cache, try_compile_cache
from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.translator.tool.cbuild import CompilationError
from pypy.tool.udir import udir
import distutils
@@ -48,12 +49,13 @@
HAS = Has(name)
return configure(CConfig)['HAS']
-def check_eci(eci):
- """Check if a given ExternalCompilationInfo compiles and links."""
+def verify_eci(eci):
+ """Check if a given ExternalCompilationInfo compiles and links.
+ If not, raises CompilationError."""
class CConfig:
_compilation_info_ = eci
WORKS = Works()
- return configure(CConfig)['WORKS']
+ configure(CConfig)
def sizeof(name, eci, **kwds):
class CConfig:
@@ -150,8 +152,8 @@
self.f.write(question + "\n")
self.close()
eci = self.config._compilation_info_
- return try_compile_cache([self.path], eci)
-
+ try_compile_cache([self.path], eci)
+
def configure(CConfig):
"""Examine the local system by running the C compiler.
The CConfig class contains CConfigEntry attribues that describe
@@ -445,11 +447,15 @@
self.name = name
def question(self, ask_gcc):
- return ask_gcc(self.name + ';')
+ try:
+ ask_gcc(self.name + ';')
+ return True
+ except CompilationError:
+ return False
class Works(CConfigSingleEntry):
def question(self, ask_gcc):
- return ask_gcc("")
+ ask_gcc("")
class SizeOf(CConfigEntry):
"""An entry in a CConfig class that stands for
Modified: pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py
==============================================================================
--- pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py (original)
+++ pypy/dist/pypy/rpython/tool/test/test_rffi_platform.py Sun May 18 17:11:35 2008
@@ -218,11 +218,12 @@
# has() should also not crash if it is given an invalid #include
assert not rffi_platform.has("x", "#include <some/path/which/cannot/exist>")
-def test_check_eci():
+def test_verify_eci():
eci = ExternalCompilationInfo()
- assert rffi_platform.check_eci(eci)
+ rffi_platform.verify_eci(eci)
eci = ExternalCompilationInfo(libraries=['some_name_that_doesnt_exist_'])
- assert not rffi_platform.check_eci(eci)
+ py.test.raises(rffi_platform.CompilationError,
+ rffi_platform.verify_eci, eci)
def test_sizeof():
assert rffi_platform.sizeof("char", ExternalCompilationInfo()) == 1
Modified: pypy/dist/pypy/tool/gcc_cache.py
==============================================================================
--- pypy/dist/pypy/tool/gcc_cache.py (original)
+++ pypy/dist/pypy/tool/gcc_cache.py Sun May 18 17:11:35 2008
@@ -1,6 +1,8 @@
from pypy.tool.autopath import pypydir
-from pypy.translator.tool.cbuild import build_executable, ExternalCompilationInfo
+from pypy.translator.tool.cbuild import build_executable
+from pypy.translator.tool.cbuild import ExternalCompilationInfo
+from pypy.translator.tool.cbuild import CompilationError
import md5
import py
import distutils
@@ -27,13 +29,19 @@
def try_compile_cache(c_files, eci):
path = cache_file_path(c_files, eci, 'try_compile_cache')
try:
- return eval(path.read())
+ data = path.read()
except py.error.Error:
+ data = ''
+ if not (data.startswith('True') or data.startswith('FAIL\n')):
try:
build_executable(c_files, eci)
- result = True
- except (distutils.errors.CompileError,
- distutils.errors.LinkError):
- result = False
- path.write(repr(result))
- return result
+ data = 'True'
+ except CompilationError, e:
+ data = 'FAIL\n%s\n' % (e,)
+ path.write(data)
+ if data.startswith('True'):
+ return True
+ else:
+ assert data.startswith('FAIL\n')
+ msg = data[len('FAIL\n'):]
+ raise CompilationError(msg.strip())
Modified: pypy/dist/pypy/tool/test/test_gcc_cache.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_gcc_cache.py (original)
+++ pypy/dist/pypy/tool/test/test_gcc_cache.py Sun May 18 17:11:35 2008
@@ -28,6 +28,11 @@
assert build_executable_cache([f], eci) == "3\n"
eci2 = ExternalCompilationInfo(include_dirs=[str(dir2)])
assert build_executable_cache([f], eci2) == "42\n"
+ f.write("#error BOOM\n")
+ err = py.test.raises(CompilationError, build_executable_cache, [f], eci2)
+ print '<<<'
+ print err
+ print '>>>'
def test_gcc_ask():
f = udir.join("y.c")
@@ -53,4 +58,7 @@
assert try_compile_cache([f], eci)
assert build_executable_cache([f], eci) == "hello\n"
eci2 = ExternalCompilationInfo(include_dirs=[str(dir2)])
- assert not try_compile_cache([f], eci2)
+ err = py.test.raises(CompilationError, try_compile_cache, [f], eci2)
+ print '<<<'
+ print err
+ print '>>>'
Modified: pypy/dist/pypy/translator/tool/cbuild.py
==============================================================================
--- pypy/dist/pypy/translator/tool/cbuild.py (original)
+++ pypy/dist/pypy/translator/tool/cbuild.py Sun May 18 17:11:35 2008
@@ -463,7 +463,10 @@
finally:
compiler.compile_extra.pop()
compiler.link_extra.pop()
-
+
+class CompilationError(Exception):
+ pass
+
class CCompiler:
def __init__(self, cfilenames, eci, outputfilename=None,
@@ -507,6 +510,7 @@
self.eci = eci
def build(self, noerr=False):
+ import distutils.errors
basename = self.outputfilename.new(ext='')
data = ''
try:
@@ -537,6 +541,13 @@
fdump = basename.new(ext='errors').open("w")
fdump.write(data)
fdump.close()
+ except (distutils.errors.CompileError,
+ distutils.errors.LinkError), e:
+ data = data.rstrip()
+ if data:
+ data += '\n'
+ data += str(e)
+ raise CompilationError(data)
except:
if not noerr:
print >>sys.stderr, data
@@ -577,7 +588,6 @@
return str(compiler.outputfilename)
def check_boehm_presence():
- import distutils.errors
from pypy.tool.udir import udir
try:
cfile = udir.join('check_boehm.c')
@@ -596,14 +606,12 @@
else:
eci = ExternalCompilationInfo(libraries=['gc'])
build_executable([cfname], eci, noerr=True)
- except (distutils.errors.CompileError,
- distutils.errors.LinkError):
+ except CompilationError:
return False
else:
return True
def check_under_under_thread():
- import distutils.errors
from pypy.tool.udir import udir
cfile = py.path.local(autopath.this_dir).join('__thread_test.c')
fsource = cfile.open('r')
@@ -617,8 +625,7 @@
exe = build_executable([str(cfile)], ExternalCompilationInfo(),
noerr=True)
py.process.cmdexec(exe)
- except (distutils.errors.CompileError,
- distutils.errors.LinkError,
+ except (CompilationError,
py.error.Error):
return False
else:
More information about the Pypy-commit
mailing list