Ronny Pfannschmidt avatar Ronny Pfannschmidt committed 95707b7

move config cache recreation code to pypy/tool/lib_pypy

Comments (0)

Files changed (3)

lib_pypy/ctypes_config_cache/dumpcache.py

-import os
-from ctypes_configure import dumpcache
-from pypy.jit.backend import detect_cpu
-
-def dumpcache2(basename, config):
-    model = detect_cpu.autodetect_main_model_and_size()
-    filename = '_%s_%s_.py' % (basename, model)
-    dumpcache.dumpcache(__file__, filename, config)
-    #
-    filename = os.path.join(os.path.dirname(__file__),
-                            '_%s_cache.py' % (basename,))
-    g = open(filename, 'w')
-    print >> g, '''\
-try:
-    from __pypy__ import cpumodel
-except ImportError:
-    from pypy.jit.backend import detect_cpu
-    cpumodel = detect_cpu.autodetect_main_model_and_size()
-# XXX relative import, should be removed together with
-# XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib
-mod = __import__("_%s_%%s_" %% (cpumodel,),
-                 globals(), locals(), ["*"])
-globals().update(mod.__dict__)\
-''' % (basename,)
-    g.close()

lib_pypy/ctypes_config_cache/rebuild.py

 autopath_py = os.path.abspath(autopath_py)
 execfile(autopath_py, dict(__name__='autopath', __file__=autopath_py))
 
-import os, sys
-import py
-
-_dirpath = os.path.dirname(__file__) or os.curdir
-
-from pypy.tool.ansi_print import ansi_log
-log = py.log.Producer("ctypes_config_cache")
-py.log.setconsumer("ctypes_config_cache", ansi_log)
-
-
-def rebuild_one(name):
-    filename = os.path.join(_dirpath, name)
-    d = {'__file__': filename}
-    path = sys.path[:]
-    try:
-        sys.path.insert(0, _dirpath)
-        execfile(filename, d)
-    finally:
-        sys.path[:] = path
-
-def try_rebuild():
-    from pypy.jit.backend import detect_cpu
-    model = detect_cpu.autodetect_main_model_and_size()
-    # remove the files '_*_model_.py'
-    left = {}
-    for p in os.listdir(_dirpath):
-        if p.startswith('_') and (p.endswith('_%s_.py' % model) or
-                                  p.endswith('_%s_.pyc' % model)):
-            os.unlink(os.path.join(_dirpath, p))
-        elif p.startswith('_') and (p.endswith('_.py') or
-                                    p.endswith('_.pyc')):
-            for i in range(2, len(p)-4):
-                left[p[:i]] = True
-    # remove the files '_*_cache.py' if there is no '_*_*_.py' left around
-    for p in os.listdir(_dirpath):
-        if p.startswith('_') and (p.endswith('_cache.py') or
-                                  p.endswith('_cache.pyc')):
-            if p[:-9] not in left:
-                os.unlink(os.path.join(_dirpath, p))
-    #
-    for p in os.listdir(_dirpath):
-        if p.endswith('.ctc.py'):
-            try:
-                rebuild_one(p)
-            except Exception, e:
-                log.ERROR("Running %s:\n  %s: %s" % (
-                    os.path.join(_dirpath, p),
-                    e.__class__.__name__, e))
-
+from pypy.tool.lib_pypy import try_rebuild
 
 if __name__ == '__main__':
     try_rebuild()

pypy/tool/lib_pypy.py

+import os
+import sys
+
 import py
 import pypy
 import pypy.module
 from pypy.module.sys.version import CPYTHON_VERSION
 
+from ctypes_configure import dumpcache
+from pypy.jit.backend import detect_cpu
+
+
+from pypy.tool.ansi_print import ansi_log
+log = py.log.Producer("ctypes_config_cache")
+py.log.setconsumer("ctypes_config_cache", ansi_log)
+
+
 LIB_ROOT = py.path.local(pypy.__path__[0]).dirpath()
 LIB_PYPY =  LIB_ROOT.join('lib_pypy')
 LIB_PYTHON = LIB_ROOT.join('lib-python', '%d.%d' % CPYTHON_VERSION[:2])
+
+
+ctypes_cachedir = LIB_PYPY.join('ctypes_config_cache')
+
+
+def dumpcache2(basename, config, sourcefile):
+    model = detect_cpu.autodetect_main_model_and_size()
+    filename = '_%s_%s_.py' % (basename, model)
+    dumpcache.dumpcache(sourcefile, filename, config)
+    #
+    filename = ctypes_cachedir.join('_%s_cache.py' % (basename))
+    filename.write('''\
+try:
+    from __pypy__ import cpumodel
+except ImportError:
+    from pypy.jit.backend import detect_cpu
+    cpumodel = detect_cpu.autodetect_main_model_and_size()
+# XXX relative import, should be removed together with
+# XXX the relative imports done e.g. by lib_pypy/pypy_test/test_hashlib
+mod = __import__("_BASENAME_%s_" % (cpumodel,),
+                 globals(), locals(), ["*"])
+globals().update(mod.__dict__)\\
+'''.replace("BASENAME", basename))
+
+
+
+
+
+def rebuild_one(path):
+    filename = str(path)
+    d = {'__file__': filename}
+    #XXX: hack
+    class DumpCache:
+        @staticmethod
+        def dumpcache2(basename, config):
+            dumpcache2(basename, config, filename)
+
+    sys.modules['dumpcache'] = DumpCache()
+    try:
+        execfile(filename, d)
+    finally:
+        del sys.modules['dumpcache']
+
+def try_rebuild():
+    from pypy.jit.backend import detect_cpu
+    model = detect_cpu.autodetect_main_model_and_size()
+
+    # kill pyc files:
+    for p in ctypes_cachedir.listdir('*.pyc'):
+        p.remove()
+        
+    # remove the files '_*_model_.py'
+    left = {}
+    for p in ctypes_cachedir.listdir('_*_%s_.py' % (model,)):
+        p.remove()
+    # remove the files '_*_cache.py' if there is no '_*_*_.py' left around
+    for p in ctypes_cachedir.listdir('_*_cache.py'):
+        fnmatch = p.basename.replace('cache', '*')
+        if not ctypes_cachedir.listdir(fnmatch):
+            p.remove()
+    #
+    for p in ctypes_cachedir.listdir('*.ctc.py'):
+        try:
+            rebuild_one(p)
+        except Exception, e:
+            log.ERROR("Running %s:\n  %s: %s" % (
+                LIB_PYPY.bestrelpath(p),
+                e.__class__.__name__, e))
+            import traceback
+            traceback.print_exc()
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.