[pypy-svn] r7566 - pypy/trunk/src/pypy/translator/tool

arigo at codespeak.net arigo at codespeak.net
Mon Nov 22 15:14:27 CET 2004


Author: arigo
Date: Mon Nov 22 15:14:26 2004
New Revision: 7566

Modified:
   pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py
Log:
For faster running compilation tests, we can now use TCC
(http://fabrice.bellard.free.fr/tcc/).  It can compile and link the .so files
with CPython at least on my machine.

To use it (or any another compiler of your choice), set the PYPY_CC
environment variable to a line where %s will be replaced by the base file name
(without extension).  For example:

    tcc -shared -o %s.so %s.c -I/usr/local/include/python2.3



Modified: pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/buildpyxmodule.py	Mon Nov 22 15:14:26 2004
@@ -25,20 +25,22 @@
     #print "made module", module
     return module
 
+def compiler_command():
+    return os.getenv('PYPY_CC')
+
 def enable_fast_compilation():
+    if compiler_command():
+        return   # don't bother importing distutils
     from distutils import sysconfig
     gcv = sysconfig.get_config_vars()
     opt = gcv.get('OPT') # not always existent
     if opt:
-        opt = re.sub('-O.', '-O0', opt)
+        opt = re.sub('-O\d+', '-O0', opt)
     else:
         opt = '-O0'
     gcv['OPT'] = opt
 
 def make_module_from_c(cfile, include_dirs=None):
-    from distutils.core import setup
-    from distutils.extension import Extension
-
     #try:
     #    from distutils.log import set_threshold
     #    set_threshold(10000)
@@ -57,16 +59,25 @@
         c = stdoutcapture.Capture(mixed_out_err = True)
         try:
             try:
-                setup(
-                  name = "testmodules",
-                  ext_modules=[
-                        Extension(modname, [str(cfile)],
-                            include_dirs=include_dirs)
-                  ],
-                  script_name = 'setup.py',
-                  script_args = ['-q', 'build_ext', '--inplace']
-                  #script_args = ['build_ext', '--inplace']
-                )
+                if compiler_command():
+                    # GCC-ish options only
+                    cmd = compiler_command().replace('%s', modname)
+                    for dir in include_dirs:
+                        cmd += ' -I%s' % dir
+                    cmdexec(cmd)
+                else:
+                    from distutils.core import setup
+                    from distutils.extension import Extension
+                    setup(
+                      name = "testmodules",
+                      ext_modules=[
+                            Extension(modname, [str(cfile)],
+                                include_dirs=include_dirs)
+                      ],
+                      script_name = 'setup.py',
+                      script_args = ['-q', 'build_ext', '--inplace']
+                      #script_args = ['build_ext', '--inplace']
+                    )
             finally:
                 foutput, foutput = c.done()
         except:



More information about the Pypy-commit mailing list