Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r68342:6bce07544ff7
Date: 2013-11-30 13:52 +0000
http://bitbucket.org/pypy/pypy/changeset/6bce07544ff7/
Log: Move evil conftest import from module- to function-level
diff --git a/rpython/tool/gcc_cache.py b/rpython/tool/gcc_cache.py
--- a/rpython/tool/gcc_cache.py
+++ b/rpython/tool/gcc_cache.py
@@ -1,15 +1,11 @@
-from rpython.translator.platform import CompilationError
-from rpython.conftest import cache_dir
from hashlib import md5
import py, os
-cache_dir_root = py.path.local(cache_dir).ensure(dir=1)
-
-def cache_file_path(c_files, eci, cachename):
+def cache_file_path(c_files, eci, cache_root, cachename):
"Builds a filename to cache compilation data"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
- cache_dir = cache_dir_root.join(cachename).ensure(dir=1)
+ cache_dir = cache_root.join(cachename).ensure(dir=1)
filecontents = [c_file.read() for c_file in c_files]
key = repr((filecontents, eci, platform.key()))
hash = md5(key).hexdigest()
@@ -19,7 +15,9 @@
"Builds and run a program; caches the result"
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
- path = cache_file_path(c_files, eci, 'build_executable_cache')
+ from rpython.conftest import cache_dir
+ cache_root = py.path.local(cache_dir).ensure(dir=1)
+ path = cache_file_path(c_files, eci, cache_root, 'build_executable_cache')
try:
return path.read()
except py.error.Error:
@@ -56,7 +54,9 @@
"Try to compile a program. If it works, caches this fact."
# Import 'platform' every time, the compiler may have been changed
from rpython.translator.platform import platform
- path = cache_file_path(c_files, eci, 'try_compile_cache')
+ from rpython.conftest import cache_dir
+ cache_root = py.path.local(cache_dir).ensure(dir=1)
+ path = cache_file_path(c_files, eci, cache_root, 'try_compile_cache')
try:
data = path.read()
if data == 'True':
diff --git a/rpython/tool/test/test_gcc_cache.py
b/rpython/tool/test/test_gcc_cache.py
--- a/rpython/tool/test/test_gcc_cache.py
+++ b/rpython/tool/test/test_gcc_cache.py
@@ -1,11 +1,17 @@
import sys
-from rpython.tool.gcc_cache import *
+import cStringIO
+import py
from rpython.tool.udir import udir
-import md5, cStringIO
from rpython.translator.tool.cbuild import ExternalCompilationInfo
+from rpython.translator.platform import CompilationError
+from rpython.tool.gcc_cache import (
+ cache_file_path, build_executable_cache, try_compile_cache)
localudir = udir.join('test_gcc_cache').ensure(dir=1)
+from rpython.conftest import cache_dir
+cache_root = py.path.local(cache_dir).ensure(dir=1)
+
def test_gcc_exec():
f = localudir.join("x.c")
f.write("""
@@ -23,7 +29,7 @@
dir2.join('test_gcc_exec.h').write('#define ANSWER 42\n')
eci = ExternalCompilationInfo(include_dirs=[str(dir1)])
# remove cache
- path = cache_file_path([f], eci, 'build_executable_cache')
+ path = cache_file_path([f], eci, cache_root, 'build_executable_cache')
if path.check():
path.remove()
res = build_executable_cache([f], eci)
@@ -54,7 +60,7 @@
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')
+ path = cache_file_path([f], eci, cache_root, 'try_compile_cache')
if path.check():
path.remove()
assert try_compile_cache([f], eci)
@@ -90,4 +96,3 @@
finally:
sys.stderr = oldstderr
assert 'ERROR' not in capture.getvalue().upper()
-
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit