Tests for common include dir.
authorRobert Bradshaw <robertwb@gmail.com>
Fri, 9 Aug 2013 07:00:49 +0000 (00:00 -0700)
committerRobert Bradshaw <robertwb@gmail.com>
Fri, 9 Aug 2013 21:03:42 +0000 (14:03 -0700)
Cython/Build/Dependencies.py
Cython/Compiler/Code.py
tests/build/common_include_dir.srctree [new file with mode: 0644]

index 2032318..b7c521c 100644 (file)
@@ -652,6 +652,9 @@ def cythonize(module_list, exclude=[], nthreads=0, aliases=None, quiet=False, fo
     """
     if 'include_path' not in options:
         options['include_path'] = ['.']
+    if 'common_utility_include_dir' in options:
+        if not os.path.exists(options['common_utility_include_dir']):
+            os.makedirs(options['common_utility_include_dir'])
     c_options = CompilationOptions(**options)
     cpp_options = CompilationOptions(**options); cpp_options.cplus = True
     ctx = c_options.create_context()
@@ -811,6 +814,9 @@ def cythonize_one(pyx_file, c_file, fingerprint, quiet, options=None, raise_on_f
     except (EnvironmentError, PyrexError), e:
         sys.stderr.write('%s\n' % e)
         any_failures = 1
+        # XXX
+        import traceback
+        traceback.print_exc()
     except Exception:
         if raise_on_failure:
             raise
index b608104..2a0213c 100644 (file)
@@ -1540,7 +1540,7 @@ class CCodeWriter(object):
 
     def put_or_include(self, code, name):
         include_dir = self.globalstate.common_utility_include_dir
-        if include_dir and len(code) > 1042:
+        if include_dir and len(code) > 1024:
             include_file = "%s_%s.h" % (
                 name, hashlib.md5(code).hexdigest())
             path = os.path.join(include_dir, include_file)
diff --git a/tests/build/common_include_dir.srctree b/tests/build/common_include_dir.srctree
new file mode 100644 (file)
index 0000000..94626d1
--- /dev/null
@@ -0,0 +1,49 @@
+PYTHON setup.py build_ext --inplace
+PYTHON -c "import runner"
+
+# Verify some files were created.
+ls common/AddTraceback_impl*.h common/RaiseException_impl_*.h
+
+# Verify that they're used.
+grep -c '#include "common/AddTraceback_impl_.*h"' a.c
+grep -c '#include "common/AddTraceback_impl_.*h"' b.c
+grep -c '#include "common/AddTraceback_impl_.*h"' c.c
+
+
+######## setup.py ########
+
+from Cython.Build.Dependencies import cythonize
+
+from distutils.core import setup
+
+setup(
+  ext_modules = cythonize("*.pyx", common_utility_include_dir='common', nthreads=2),
+)
+
+######## a.pyx ########
+
+def generator(n):
+    for k in range(n):
+        yield k
+
+assert list(generator(10)) == list(range(10))
+
+######## b.pyx ########
+
+def generator(n):
+    for k in range(n):
+        yield k
+
+assert list(generator(10)) == list(range(10))
+
+if __name__ == "__main__":
+    print "here", "b"
+
+######## c.pyx ########
+
+if __name__ == "__main__":
+    print "here", "c"
+
+######## runner.py ########
+
+import a, b, c