[pypy-svn] r54928 - in pypy/branch/win32port/pypy/translator/c: . test

afa at codespeak.net afa at codespeak.net
Mon May 19 14:28:28 CEST 2008


Author: afa
Date: Mon May 19 14:28:27 2008
New Revision: 54928

Modified:
   pypy/branch/win32port/pypy/translator/c/genc.py
   pypy/branch/win32port/pypy/translator/c/test/test_standalone.py
Log:
Allow compilation of files residing outside the target directory.
These files are copied into our working space, and compiled there.

Used by libffi on win32.


Modified: pypy/branch/win32port/pypy/translator/c/genc.py
==============================================================================
--- pypy/branch/win32port/pypy/translator/c/genc.py	(original)
+++ pypy/branch/win32port/pypy/translator/c/genc.py	Mon May 19 14:28:27 2008
@@ -304,8 +304,18 @@
             if profopt is not None and not self.config.translation.noprofopt:
                 profbased = (ProfOpt, profopt)
 
+        # Copy extrafiles to target directory, if needed
+        extrafiles = []
+        for fn in self.extrafiles:
+            fn = py.path.local(fn)
+            if not fn.relto(udir):
+                newname = self.targetdir.join(fn.basename)
+                fn.copy(newname)
+                fn = newname
+            extrafiles.append(fn)
+
         return CCompiler(
-            [self.c_source_filename] + self.extrafiles,
+            [self.c_source_filename] + extrafiles,
             self.eci, compiler_exe = cc, profbased = profbased)
 
     def compile(self):
@@ -366,6 +376,8 @@
             else:
                 assert fn.dirpath().dirpath() == udir
                 name = '../' + fn.relto(udir)
+                
+            name = name.replace("\\", "/")
             cfiles.append(name)
             if self.config.translation.gcrootfinder == "asmgcc":
                 ofiles.append(name[:-2] + '.s')

Modified: pypy/branch/win32port/pypy/translator/c/test/test_standalone.py
==============================================================================
--- pypy/branch/win32port/pypy/translator/c/test/test_standalone.py	(original)
+++ pypy/branch/win32port/pypy/translator/c/test/test_standalone.py	Mon May 19 14:28:27 2008
@@ -4,9 +4,10 @@
 from pypy.rlib.rarithmetic import r_longlong
 from pypy.translator.translator import TranslationContext
 from pypy.translator.backendopt import all
-from pypy.translator.c.genc import CStandaloneBuilder
+from pypy.translator.c.genc import CStandaloneBuilder, ExternalCompilationInfo
 from pypy.annotation.listdef import s_list_of_strings
 from pypy.tool.udir import udir
+from pypy.tool.autopath import pypydir
 
 
 def test_hello_world():
@@ -190,3 +191,42 @@
     cbuilder.compile()
     data = cbuilder.cmdexec('hi there')
     assert data.strip() == "OK"
+
+def test_separate_files():
+    # One file in translator/c/src
+    fname = py.path.local(pypydir).join(
+        'translator', 'c', 'src', 'll_strtod.h')
+    
+    # One file in (another) subdir of the temp directory
+    dirname = udir.join("test_dir").ensure(dir=1)
+    fname2 = dirname.join("test_genc.c")
+    fname2.write("""
+    void f() {
+        LL_strtod_formatd("%5f", 12.3);
+    }""")
+
+    files = [fname, fname2]
+
+    def entry_point(argv):
+        return 0
+
+    t = TranslationContext()
+    t.buildannotator().build_types(entry_point, [s_list_of_strings])
+    t.buildrtyper().specialize()
+
+    cbuilder = CStandaloneBuilder(t, entry_point, t.config)
+    cbuilder.eci = cbuilder.eci.merge(
+        ExternalCompilationInfo(separate_module_files=files))
+    cbuilder.generate_source()
+
+    makefile = udir.join(cbuilder.modulename, 'Makefile').read()
+
+    # generated files are compiled in the same directory
+    assert "  ../test_dir/test_genc.c" in makefile
+    assert "  ../test_dir/test_genc.o" in makefile
+
+    # but files from pypy source dir must be copied
+    assert "translator/c/src" not in makefile
+    assert "  ll_strtod.h" in makefile
+    assert "  ll_strtod.o" in makefile
+



More information about the Pypy-commit mailing list