[pypy-svn] r50472 - in pypy/dist/pypy/tool: . test
arigo at codespeak.net
arigo at codespeak.net
Wed Jan 9 22:53:37 CET 2008
Author: arigo
Date: Wed Jan 9 22:53:37 2008
New Revision: 50472
Modified:
pypy/dist/pypy/tool/gcc_cache.py
pypy/dist/pypy/tool/test/test_gcc_cache.py
Log:
(oesser, arigo)
Make gcc_cache robust to detect changing ExternalCompilationInfo's.
Also, test and fix for calling both try_compile_cache() and
build_executable_cache() with the same arguments.
Modified: pypy/dist/pypy/tool/gcc_cache.py
==============================================================================
--- pypy/dist/pypy/tool/gcc_cache.py (original)
+++ pypy/dist/pypy/tool/gcc_cache.py Wed Jan 9 22:53:37 2008
@@ -6,31 +6,34 @@
import distutils
import distutils.errors
-py.path.local(pypydir).join('_cache').ensure(dir=1)
-cache_dir = py.path.local(pypydir).join('_cache', 'gcc')
-cache_dir.ensure(dir=1)
+cache_dir_root = py.path.local(pypydir).join('_cache').ensure(dir=1)
-def build_executable_cache(c_files, *args, **kwds):
- s = "\n\n".join([c_file.read() for c_file in c_files])
- hash = md5.md5(s).hexdigest()
+def cache_file_path(c_files, eci, cachename):
+ cache_dir = cache_dir_root.join(cachename).ensure(dir=1)
+ filecontents = [c_file.read() for c_file in c_files]
+ key = repr((filecontents, eci))
+ hash = md5.md5(key).hexdigest()
+ return cache_dir.join(hash)
+
+def build_executable_cache(c_files, eci):
+ path = cache_file_path(c_files, eci, 'build_executable_cache')
try:
- return cache_dir.join(hash).read()
+ return path.read()
except py.error.Error:
- result = py.process.cmdexec(build_executable(c_files, *args, **kwds))
- cache_dir.join(hash).write(result)
+ result = py.process.cmdexec(build_executable(c_files, eci))
+ path.write(result)
return result
-def try_compile_cache(c_files, *args, **kwds):
- s = "\n\n".join([c_file.read() for c_file in c_files])
- hash = md5.md5(s).hexdigest()
+def try_compile_cache(c_files, eci):
+ path = cache_file_path(c_files, eci, 'try_compile_cache')
try:
- return eval(cache_dir.join(hash).read())
+ return eval(path.read())
except py.error.Error:
try:
- build_executable(c_files, *args, **kwds)
+ build_executable(c_files, eci)
result = True
except (distutils.errors.CompileError,
distutils.errors.LinkError):
result = False
- cache_dir.join(hash).write(repr(result))
- return bool(result)
+ path.write(repr(result))
+ return result
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 Wed Jan 9 22:53:37 2008
@@ -8,31 +8,49 @@
f = udir.join("x.c")
f.write("""
#include <stdio.h>
+ #include <test_gcc_exec.h>
int main()
{
- printf("3\\n");
+ printf("%d\\n", ANSWER);
return 0;
}
""")
+ dir1 = udir.join('test_gcc_exec_dir1').ensure(dir=1)
+ dir2 = udir.join('test_gcc_exec_dir2').ensure(dir=1)
+ dir1.join('test_gcc_exec.h').write('#define ANSWER 3\n')
+ dir2.join('test_gcc_exec.h').write('#define ANSWER 42\n')
+ eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
# remove cache
- try:
- cache_dir.join(md5.md5(f.read()).hexdigest()).remove()
- except:
- pass
- assert build_executable_cache([f], ExternalCompilationInfo()) == "3\n"
- assert build_executable_cache([f], ExternalCompilationInfo(), compiler_exe="xxx") == "3\n"
+ path = cache_file_path([f], eci, 'build_executable_cache')
+ if path.check():
+ path.remove()
+ assert build_executable_cache([f], eci) == "3\n"
+ assert build_executable_cache([f], eci) == "3\n"
+ eci2 = ExternalCompilationInfo(include_dirs=[str(dir2)])
+ assert build_executable_cache([f], eci2) == "42\n"
def test_gcc_ask():
f = udir.join("y.c")
f.write("""
+ #include <stdio.h>
+ #include <test_gcc_ask.h>
int main()
{
- return 0;
+ printf("hello\\n");
+ return 0;
}
""")
- try:
- cache_dir.join(md5.md5(f.read()).hexdigest()).remove()
- except:
- pass
- assert try_compile_cache([f], ExternalCompilationInfo())
- assert try_compile_cache([f], ExternalCompilationInfo(), compiler_exe="xxx")
+ dir1 = udir.join('test_gcc_ask_dir1').ensure(dir=1)
+ dir2 = udir.join('test_gcc_ask_dir2').ensure(dir=1)
+ dir1.join('test_gcc_ask.h').write('/* hello world */\n')
+ dir2.join('test_gcc_ask.h').write('#error boom\n')
+ eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
+ # remove cache
+ path = cache_file_path([f], eci, 'try_compile_cache')
+ if path.check():
+ path.remove()
+ assert try_compile_cache([f], eci)
+ 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)
More information about the pypy-svn
mailing list